У меня есть таблица с деталями продукта, такими как Я БЫ, описание, цена и т. д. Я пытаюсь экспортировать эти данные в Excel.
Если я просто сделаю getModel("A"), а затем привяжу несколько свойств «A», которые вложены в нет, Excel загрузится нормально. Но если есть какая-либо другая структура, к которой я пытаюсь получить доступ, например, getModel("A").getProperty("/Person/PersonFullName"), она оставит эту пустая колонка.
{ // Controller
onExport: function() {
var aCols, aProducts, oSettings;
aCols = this.createColumnConfig();
aProducts = this.getView().getModel("A"); // A has nested/deep entities
oSettings = {
workbook: { columns: aCols },
dataSource: aProducts
};
var oSpreadsheet = new Spreadsheet(oSettings); // required "sap/ui/export/Spreadsheet"
oSpreadsheet.build();
},
createColumnConfig: function() {
return [
{
label: 'Product ID',
property: 'name'
},
{
label: 'Category',
property: 'BillTo/BillToName', //Not able to get this property
}
];
},
}





Согласно Ссылка API sap/ui/export/Spreadsheet, объект настройки dataSource ожидает один из следующих аргументов:
- Map of data source properties, // See API reference for available options
- URL to an OData service
- JSON array
Но в вашем коде aProduct, который назначен для dataSource, является ссылкой на модель "A", которая называется недействителен.
На dataSource надо ставить, в зависимости от типа модели, соответственно:
ODataModelconst 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"
}
Примечание: Убедитесь, что соответствующий параметр $expand включен в dataUrl. В противном случае вложенные свойства не будут экспортированы.
JSONModel){ // Constructor settings of sap/ui/export/Spreadsheet
dataSource: myJSONModel.getProperty("/SomeCollection"), // returns an array
fileName: "myExportedDataFromPlainJSON.xlsx"
}