2017-02-17 146 views
-1

我想用接下來的Java腳本代碼:參考錯誤:「工作簿」沒有定義

function dumpVal(file) { 
if (file !=null) { 
var wb = new Workbook.create(file); 
var sheet = wb.getSheet("Tabelle1"); 
for (myrow = 1; !isCellEmpty(sheet, myrow, 0); myrow++) { 
dataset.setColumnValue("A",getNumericValue(sheet,myrow,0)); 
dataset.storeResultRow(); 
} 
} 
return; 
} 

,但是當我編譯它,我收到一個錯誤信息:ReferenceError: "Workbook" is not defined. 有人能告訴我什麼是我做錯了?

+0

定義對象'Workbook'的代碼在哪裏? –

+1

嘗試像這樣 - > var wb = new Workbook()。create(file); –

+2

@DeepakSharma - 如果未定義'Workbook',則將其作爲函數調用將無濟於事。 (並且不要在評論中回答,使用答案來解答)。 – Quentin

回答

1

您收到錯誤與代碼followig行:

var wb = new Workbook; 

,在您創建工作簿(新工作簿)你指的是所謂的「工作簿」類別的點。此時你的腳本沒有一個名爲Workbook的類。

解決方案: 您應該檢查您的腳本,如果包含類和它的命名。 也許這個課程稍後會被初始化!

爲了調試,你可以嘗試之前創建類的一行:

class Workbook{ } 

如果你現在收到一個錯誤,因爲工作簿需要一個叫做「創造」的方法,你就知道這個類就是缺少。

-1

我認爲要分析從Web應用程序Excel文件,您使用的是圖書館發展爲Excel不是web應用程序加載項:如果您想分析的Excel中

Excel JavaScript API programming overview

This article describes how to use the Excel JavaScript API to build add-ins for Excel 2016. It introduces key concepts that are fundamental to using the APIs, such as RequestContext, JavaScript proxy objects, sync(), Excel.run(), and load(). The code examples at the end of the article show you how to apply the concepts.

source : https://dev.office.com/docs/add-ins/excel/excel-add-ins-javascript-programming-overview

Web應用程序,我建議使用這個庫:

https://github.com/SheetJS/js-xlsx

我沒有使用它,所以我不能garanty它,但你可以看看類似圖書館的。

+0

請[僅限鏈接回答](http://meta.stackoverflow.com/tags/link-only-answers/info)。答案是「幾乎不超過鏈接到外部網站」[可能會被刪除](http://stackoverflow.com/help/deleted-answers)。 – Quentin

+0

好的,對於建議tnx,我會更加小心。 –