使用SAPUI5将表数据导出为PDF

时间:2016-05-20 11:47:02

标签: sapui5

在PDF中导出数据之后,我有数据表,这些数据以单列显示所有表格数据。以下是PDF的屏幕截图:pdf image - All table data coming in single column

  

注意:要以pdf格式导出,我使用了 pdfmake.min.js & vfs_fonts.js

现在我想要,所有数据应该分为四栏和一栏。带有表头的两行,这是我的代码

xml代码

<Table id="placeTbl">
  <columns>
    <Column>
      <Text text="First Name"/>
    </Column>
    <Column>
      <Text text="Last Name"/>
    </Column>
    <Column>
      <Text text="age"/>
    </Column>
    <Column>
      <Text text="Contact"/>
    </Column>
  </columns>
</Table>

<Button text ="Export To PDF" press="downloadpdf"/>

JS代码

downloadpdf : function() {

  var oTable = this.getView().byId("placeTbl");
  var odata = oTable.getItems();

  var docDefinition = {
    pageSize : 'A4',
    pageOrientation : 'portrait',
    content : [ {
      table : {
        // widths: ['*', '*'],
        headerRows : 1,
        widths : [ '*', '*', '*' ],
        body : []
        // ['First Name', 'Last Name', 'age', 'contact']
      }
    } ],
    styles : {
      tableExample : {
        margin : [ 0, 10, 0, 15 ]
      },
    }
  };

  for (var i = 0; i < odata.length; i++) {
    docDefinition.content[0].table.body
    .push([ odata[i].mAggregations.cells[0].mProperties.text ]);
    docDefinition.content[0].table.body
    .push([ odata[i].mAggregations.cells[1].mProperties.text ]);
    docDefinition.content[0].table.body
    .push([ odata[i].mAggregations.cells[2].mProperties.text ]);
    docDefinition.content[0].table.body
    .push([ odata[i].mAggregations.cells[3].mProperties.text ]);

  }
  pdfMake.createPdf(docDefinition).download();
}

导出为pdf后,我希望在PDF格式中使用表格结构

Example for after exporting pdf should look like this

0 个答案:

没有答案
相关问题