2017-02-09 132 views
1

我一直在嘗試將.csv文件轉換爲.xls或.xlsx,並且我一直在成功地這樣做。但問題是該文件沒有打開。這表明無法打開文件格式。如何將csv文件轉換爲sapui5中的xls或xlsx?

這些是我一直在使用的以下代碼。

1. var oExport = new sap.ui.core.util.Export({ 
       exportType : new sap.ui.core.util.ExportType({ 
        separatorChar : ",", 
        fileExtension : "xlsx", 
        mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", 
       }), 
       models : oModel, 

       rows : { 
        path : "/" 
       }, 
       columns : [ itemsArray ] 
      }); 
      oExport.saveFile(oFileName).always(function() { 
       this.destroy(); 
      }); 

當我像這樣下載文件大小爲零。因此它沒有任何價值。我嘗試了另一種方式。

2.var oExport = new sap.ui.core.util.Export({ 
       exportType : new sap.ui.core.util.ExportTypeCSV({ 
        separatorChar : ",", 
        fileExtension : "xlsx", 
        mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", 
       }), 
       models : oModel, 

       rows : { 
        path : "/" 
       }, 
       columns : [ itemsArray ] 
      }); 
      oExport.saveFile(oFileName).always(function() { 
       this.destroy(); 
      }); 

當我使用上面的代碼文件將有一些數據,但無法打開它。任何人都可以幫助我嗎?

謝謝。

+0

您是否從Netweaver網關OData服務獲取數據? –

+0

謝謝你回覆,你好,我正在獲取數據表單網關。但我試圖下載前端(視圖)中可見的數據。我可以下載數據表格網關,但結果不會如我所料。我只是想將csv轉換爲xls或xlsx。 – Farooq

+0

如果您直接從網關下載,則向odata請求添加參數(?$ format = xlsx)可以完成該任務。通過UI5,CSV導出開箱即可使用,Excel導出會很棘手 –

回答

0

AFAIK sapui5不提供該功能。所以你可能需要自己管理它。

這可能會幫助你https://github.com/SheetJS/js-xlsx

我們用它來讀取xlsx文件,但看起來它可以幫助您編寫它們。

+0

謝謝你的建議。我一定會通過它。 – Farooq