<mvc:View xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:semantic="sap.m.semantic"
xmlns:core="sap.ui.core" xmlns:l="sap.ui.layout" controllerName="XXXX.UploadExcelData.controller.MainView" displayBlock="true">
<semantic:FullscreenPage busyIndicatorDelay="{appView>/delay}" enableScrolling="false" class="sapFioriListReportPageOverflow">
<semantic:content>
<VBox fitContainer="true">
<core:Fragment fragmentName="XXXX.UploadExcelData.fragment.UploadFile" type="XML"/>
<l:HorizontalLayout id="additionalParamaters"/>
<core:Fragment fragmentName="XXXX.UploadExcelData.fragment.UploadSmartTable" type="XML"/>
</VBox>
</semantic:content>
<semantic:customFooterContent>
<Button text="{i18n>btnSave}" press="handleSaveData" icon="sap-icon://save" type="Emphasized" enabled="{appView>/saveEnabled}"/>
</semantic:customFooterContent>
</semantic:FullscreenPage>
</mvc:View>
<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:l="sap.ui.layout" xmlns:u="sap.ui.unified">
<Panel>
<l:VerticalLayout width="100%" id="fileUploaderLayout">
<l:content>
<HBox alignItems="Center" justifyContent="Start">
<Label text="{i18n>uploadLabel}" id="fileUploaderLabel" class="sapMH5FontSize sapUiSmallMarginEnd" labelFor="fileUploader" required="true" width="15em"/>
<u:FileUploader sameFilenameAllowed="true" id="fileUploader" sendXHR="true" tooltip="{i18n>uploadTooltip}" change="onUpload"
fileType="xls,xlsx" useMultipart="false" width="400px" typeMissmatch="handleTypeMissmatch" placeholder="{i18n>uploadPlaceHolder}"/>
</HBox>
<HBox alignItems="Center" justifyContent="Start">
<Label text="{i18n>uploadType}" class="sapMH5FontSize sapUiSmallMarginEnd" labelFor="uploadType" required="true" width="15em"/>
<Select id="uploadType" items="{ path: '/UploadTypeSet', sorter: { path: 'TypeText' } }" enabled="{appView>/typeEnabled}" forceSelection="false" change="onTypeSelected">
<core:ListItem key="{Type}" text="{TypeText}"/>
</Select>
</HBox>
</l:content>
</l:VerticalLayout>
</Panel>
</core:FragmentDefinition>
<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core">
<ScrollContainer horizontal="true" vertical="true" height="85%">
<Table items="{path: 'localModel>/items', factory: '._populateItems'}" columns="{path: 'localModel>/columns', factory: '._populateColumns'}"
fixedLayout="false">
<headerToolbar>
<Toolbar>
<Title text="{i18n>tableTitle}"/>
</Toolbar>
</headerToolbar>
</Table>
</ScrollContainer>
</core:FragmentDefinition>
/**
* Initialize model for content
* @author Andy Goris
* @version 1.0.0
* @since 1.0.0
* @memberOf XXXX.UploadExcelData.controller.MainView
* @public
* @param {object} oEvent the event of the fileuploader
*/
onUpload: function(oEvent) {
let oExcelData = {};
const oFile = oEvent.getParameter("files") && oEvent.getParameter("files")[0];
if (oFile && window.FileReader) {
let oReader = new FileReader();
let aData = [];
let aColumns = [];
oReader.onload = function(oExcel) {
const sData = oExcel.target.result;
const oWorkbook = XLSX.read(sData, {
type: "binary"
});
let bColumnsAdded = false;
oWorkbook.SheetNames.forEach(function(sSheetName) {
// Here is your object for every sheet in workbook
oExcelData = XLSX.utils.sheet_to_row_object_array(oWorkbook.Sheets[sSheetName], {
defval: ""
});
//Transform data to A/B/C/D/E/F columns
oExcelData.forEach(function(oRow) {
let oNewRow = {};
let iIndex = 0;
for (let sProperty in oRow) {
let sColumn = String.fromCharCode(65 + iIndex);
let oNewColumn = {};
oNewRow[sColumn] = oRow[sProperty].toString().replace(/\s/g, '');
if (!bColumnsAdded) { //Only for the first row
oNewColumn.columnId = sProperty;
aColumns.push(oNewColumn);
}
iIndex++;
}
aData.push(oNewRow);
bColumnsAdded = true;
});
});
// Setting the data to the local model
let oLocalModel = this.getModel("localModel");
oLocalModel.setProperty("/items", aData);
oLocalModel.setProperty("/columns", aColumns);
this.getModel("appView").setProperty("/typeEnabled", true);
}.bind(this);
oReader.onerror = function(oException) {
this.getModel("appView").setProperty("/typeEnabled", false);
MessageBox.error(oException);
};
oReader.readAsBinaryString(oFile);
}
},
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
7 | |
5 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 |