Export business data from UI5 to Excel

前端 未结 1 1428
闹比i
闹比i 2021-01-15 17:54

I have a table with product details like ID, description, price etc.. I am trying to export these data to an Excel.

Issue

If I jus

相关标签:
1条回答
  • 2021-01-15 18:46

    According to the API reference of sap/ui/export/Spreadsheet, the dataSource setting object awaits one of the following arguments:

    • Map of data source properties, // See API reference for available options
    • URL to an OData service
    • JSON array

    But in your code, the aProduct, which is assigned to the dataSource, is a reference to the "A" model which is invalid.

    The dataSource should be set, depending on the model type, accordingly:

    With ODataModel

    const odataListBinding = this.byId("myResponsiveTable").getBinding("items");
    const serviceEntryPath = "/sap.app/dataSources/<sourceName>/uri"; // See manifest.json for <sourceName>
    const serviceUrl = this.getOwnerComponent().getManifestEntry(serviceEntryPath);
    
    { // Constructor settings of sap/ui/export/Spreadsheet
      dataSource: {
        type: "OData",
        useBatch: true,
        serviceUrl: serviceUrl,
        headers: odataListBinding.getModel().getHeaders(),
        dataUrl: odataListBinding.getDownloadUrl(), // serviceUrl + "/Orders" + added queries ($expand, $select, ...)
        count: odataListBinding.getLength(),
        sizeLimit: /*e.g.*/1000,
      },
      worker: true, // false if working with mock server or if CSP is enabled.
      fileName: "myExportedDataFromODataV2.xlsx"
    }
    

    Note: Please make sure that the corresponding $expand parameter is included in the dataUrl. Otherwise, nested properties won't be exported.

    Samples

    • My sample with nested properties ($expand)
    • Sample from the Demo Kit

    With client-side models (e.g. JSONModel)

    { // Constructor settings of sap/ui/export/Spreadsheet
      dataSource: myJSONModel.getProperty("/SomeCollection"), // returns an array
      fileName: "myExportedDataFromPlainJSON.xlsx"
    }
    

    Samples

    • My sample with nested properties
    • Sample from the Demo Kit
    0 讨论(0)
提交回复
热议问题