下载 table 到电子表格
Download table to spreadsheet
我创建了一个 sap.m.Table。我需要将它下载到 excel。
为此,我关注了 this sample。然而,该文件虽然已导出,但它只包含每一列的标题,文件似乎知道行,但单元格是空的(检查下图)。
在我的控制器中,我有以下内容:
onExport : function () {
var oTable = this.getView().byId("lineItemsList"),
oRowBinding, aCols, oSettings, oSheet;
oRowBinding = oTable.getBinding("items");
aCols = this.createColumnConfig();
oSettings = {
workbook: {
columns: aCols
//hierarchyLevel: 'Level'
},
dataSource: oRowBinding,
fileName: "WBS Elements.xlsx"
//worker: false // We need to disable worker because we are using a MockServer as OData Service
};
oSheet = new Spreadsheet(oSettings);
oSheet.build().finally(function() {
oSheet.destroy();
});
},
然后控制器中的Column Config:
createColumnConfig: function() {
var aCols = [];
aCols.push({
//label: 'Nivel',
property: "Level",
type: EdmType.String,
});
aCols.push({
label: "WBS Element",
property: "WBS Element",
type: EdmType.String,
});
aCols.push({
property: "Description",
type: EdmType.String
});
aCols.push({
property: "Basic Start",
type: EdmType.Date
});
aCols.push({
property: "Basic Finish",
type: EdmType.Date
});
aCols.push({
property: "Actual Start",
type: EdmType.Date,
});
aCols.push({
property: "Actual Finish",
type: EdmType.Date
});
aCols.push({
property: "Plan PoC%",
type: EdmType.Number
});
aCols.push({
property: "Act PoC%",
type: EdmType.Number
});
aCols.push({
property: "Plan Cost",
type: EdmType.Number
});
aCols.push({
property: "Actual Cost",
type: EdmType.Number
});
aCols.push({
property: "Budget",
type: EdmType.Number
});
aCols.push({
property: "Curr. Year Budget",
type: EdmType.Number
});
aCols.push({
property: "Status",
type: EdmType.String
});
aCols.push({
property: "Currency",
type: EdmType.String
});
return aCols;
}
最后,table 视图中的 XML 定义(删除了工具栏定义和其他内容,以便专注于相关内容):
<semantic:content>
<Table
id="lineItemsList"
width="auto"
items="{
path: '/ItProjWbsSet',
sorter: {
path: 'Pspid',
descending: false
}
}"
mode="MultiSelect"
updateFinished=".onUpdateFinished"
selectionChange="onSelectionChange"
noDataText="{i18n>detailLineItemTableNoDataText}"
busyIndicatorDelay="{detailView>/delay}">
<columns>
<Column demandPopin="false" minScreenWidth="Phone">
<Text text="Level"/>
</Column>
<Column demandPopin="false" width="12em" minScreenWidth="Phone">
<Text text="WBS Element"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Basic Start"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Basic Finish"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Actual Start"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Actual Finish"/>
</Column>
<Column demandPopin="false" minScreenWidth="Phone" visible="{= !${device>/system/phone}}">
<Text text="Plan PoC%"/>
</Column>
<Column demandPopin="false" minScreenWidth="Phone" visible="{= !${device>/system/phone}}">
<Text text="Actual PoC%"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Plan Cost"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Act.Cost"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Budget"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Curr.Year Budget"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Status"/>
</Column>
</columns>
<items>
<ColumnListItem id="listLayout">
<cells>
<Text text="{Stufe}"/>
<ObjectIdentifier
title="{Pspid}"
text="{Post1}"/>
<Text text="{path : 'Pstrt',
type : 'sap.ui.model.type.Date',
formatOptions: { style : 'short'}}"/>
<Text text="{path : 'Pende',
type : 'sap.ui.model.type.Date',
formatOptions: { style : 'short'}}"/>
<Text text="{path : 'Istrt',
type : 'sap.ui.model.type.Date',
formatOptions: { style : 'short'}}"/>
<Text text="{path : 'Iende',
type : 'sap.ui.model.type.Date',
formatOptions: { style : 'short'}}"/>
<ObjectNumber
number="{
parts:[{path:'PlanCost'},{path:'CurrKey'}],
type: 'sap.ui.model.type.Currency',
formatOptions: {showMeasure: false}
}"
unit="{CurrKey}" />
<ObjectNumber
number="{
parts:[{path:'ActualCost'},{path:'CurrKey'}],
type: 'sap.ui.model.type.Currency',
formatOptions: {showMeasure: false}
}"
unit="{CurrKey}" />
<ObjectNumber
number="{
parts:[{path:'Budget'},{path:'CurrKey'}],
type: 'sap.ui.model.type.Currency',
formatOptions: {showMeasure: false}
}"
unit="{CurrKey}" />
<ObjectNumber
number="{
parts:[{path:'CurrYrBud'},{path:'CurrKey'}],
type: 'sap.ui.model.type.Currency',
formatOptions: {showMeasure: false}
}"
unit="{CurrKey}" />
<Text text="{Status}"/>
</cells>
</ColumnListItem>
</items>
</Table>
</semantic:content>
您需要使用与 viewModel/oData 服务中调用的完全相同的字符串作为 属性 名称。
aCols.push({
label: "Actual Cost"
property: "ActualCost", // Needs to be property name
type: EdmType.Number
});
对于它已经匹配的预算,因此 excel 中显示了“0”。
我创建了一个 sap.m.Table。我需要将它下载到 excel。 为此,我关注了 this sample。然而,该文件虽然已导出,但它只包含每一列的标题,文件似乎知道行,但单元格是空的(检查下图)。
在我的控制器中,我有以下内容:
onExport : function () {
var oTable = this.getView().byId("lineItemsList"),
oRowBinding, aCols, oSettings, oSheet;
oRowBinding = oTable.getBinding("items");
aCols = this.createColumnConfig();
oSettings = {
workbook: {
columns: aCols
//hierarchyLevel: 'Level'
},
dataSource: oRowBinding,
fileName: "WBS Elements.xlsx"
//worker: false // We need to disable worker because we are using a MockServer as OData Service
};
oSheet = new Spreadsheet(oSettings);
oSheet.build().finally(function() {
oSheet.destroy();
});
},
然后控制器中的Column Config:
createColumnConfig: function() {
var aCols = [];
aCols.push({
//label: 'Nivel',
property: "Level",
type: EdmType.String,
});
aCols.push({
label: "WBS Element",
property: "WBS Element",
type: EdmType.String,
});
aCols.push({
property: "Description",
type: EdmType.String
});
aCols.push({
property: "Basic Start",
type: EdmType.Date
});
aCols.push({
property: "Basic Finish",
type: EdmType.Date
});
aCols.push({
property: "Actual Start",
type: EdmType.Date,
});
aCols.push({
property: "Actual Finish",
type: EdmType.Date
});
aCols.push({
property: "Plan PoC%",
type: EdmType.Number
});
aCols.push({
property: "Act PoC%",
type: EdmType.Number
});
aCols.push({
property: "Plan Cost",
type: EdmType.Number
});
aCols.push({
property: "Actual Cost",
type: EdmType.Number
});
aCols.push({
property: "Budget",
type: EdmType.Number
});
aCols.push({
property: "Curr. Year Budget",
type: EdmType.Number
});
aCols.push({
property: "Status",
type: EdmType.String
});
aCols.push({
property: "Currency",
type: EdmType.String
});
return aCols;
}
最后,table 视图中的 XML 定义(删除了工具栏定义和其他内容,以便专注于相关内容):
<semantic:content>
<Table
id="lineItemsList"
width="auto"
items="{
path: '/ItProjWbsSet',
sorter: {
path: 'Pspid',
descending: false
}
}"
mode="MultiSelect"
updateFinished=".onUpdateFinished"
selectionChange="onSelectionChange"
noDataText="{i18n>detailLineItemTableNoDataText}"
busyIndicatorDelay="{detailView>/delay}">
<columns>
<Column demandPopin="false" minScreenWidth="Phone">
<Text text="Level"/>
</Column>
<Column demandPopin="false" width="12em" minScreenWidth="Phone">
<Text text="WBS Element"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Basic Start"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Basic Finish"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Actual Start"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Actual Finish"/>
</Column>
<Column demandPopin="false" minScreenWidth="Phone" visible="{= !${device>/system/phone}}">
<Text text="Plan PoC%"/>
</Column>
<Column demandPopin="false" minScreenWidth="Phone" visible="{= !${device>/system/phone}}">
<Text text="Actual PoC%"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Plan Cost"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Act.Cost"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Budget"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Curr.Year Budget"/>
</Column>
<Column demandPopin="false" minScreenWidth="Tablet" visible="{= !${device>/system/phone}}">
<Text text="Status"/>
</Column>
</columns>
<items>
<ColumnListItem id="listLayout">
<cells>
<Text text="{Stufe}"/>
<ObjectIdentifier
title="{Pspid}"
text="{Post1}"/>
<Text text="{path : 'Pstrt',
type : 'sap.ui.model.type.Date',
formatOptions: { style : 'short'}}"/>
<Text text="{path : 'Pende',
type : 'sap.ui.model.type.Date',
formatOptions: { style : 'short'}}"/>
<Text text="{path : 'Istrt',
type : 'sap.ui.model.type.Date',
formatOptions: { style : 'short'}}"/>
<Text text="{path : 'Iende',
type : 'sap.ui.model.type.Date',
formatOptions: { style : 'short'}}"/>
<ObjectNumber
number="{
parts:[{path:'PlanCost'},{path:'CurrKey'}],
type: 'sap.ui.model.type.Currency',
formatOptions: {showMeasure: false}
}"
unit="{CurrKey}" />
<ObjectNumber
number="{
parts:[{path:'ActualCost'},{path:'CurrKey'}],
type: 'sap.ui.model.type.Currency',
formatOptions: {showMeasure: false}
}"
unit="{CurrKey}" />
<ObjectNumber
number="{
parts:[{path:'Budget'},{path:'CurrKey'}],
type: 'sap.ui.model.type.Currency',
formatOptions: {showMeasure: false}
}"
unit="{CurrKey}" />
<ObjectNumber
number="{
parts:[{path:'CurrYrBud'},{path:'CurrKey'}],
type: 'sap.ui.model.type.Currency',
formatOptions: {showMeasure: false}
}"
unit="{CurrKey}" />
<Text text="{Status}"/>
</cells>
</ColumnListItem>
</items>
</Table>
</semantic:content>
您需要使用与 viewModel/oData 服务中调用的完全相同的字符串作为 属性 名称。
aCols.push({
label: "Actual Cost"
property: "ActualCost", // Needs to be property name
type: EdmType.Number
});
对于它已经匹配的预算,因此 excel 中显示了“0”。