0
我試圖讀取一個電子表格,它使用cfspreadsheet在多個選項卡上有預定義的圖表,但是當涉及到處理數據時,我得到的變量是未定義的。cfspreadsheet導致變量未定義的錯誤
我使用的例子從Adobe - http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec17cba-7f87.html
我也看了其它的例子,但這些例子使用cfspreadsheet和POI或Java的組合,我寧願如果可能的話只使用cfspreadsheet。任何想法在下面的問題來自哪裏看我的代碼?謝謝。
<cfcontent type="application/vnd.ms-excel" reset="Yes">
<cfquery name="GetData" datasource="#request.dsn#">
SELECT *
FROM v_Occurrences
</cfquery>
<cfset strFileName = "OccurrenceData" & "#now().getTime()#" & "#UserID#">
<!---
<cfdump var="#GetData#">
--->
<cfset filepath = "file:///...OccurenceData.xls">
<!--- Write the two sheets to a single file --->
<cfspreadsheet
action ="read"
columnnames = "Occurence_Date,Full_Name_Client"
columns = "2"
excludeHeaderRow = "false"
headerrow = "1"
query="GetData"
rows = "2"
src ="#filepath#">
<cfscript>
OccurrenceData = SpreadsheetNew("Data");
Month = SpreadsheetNew("Month");
Person = SpreadsheetNew("Person");
SpreadsheetAddRows(occurrencedata,getdata);
</cfscript>
<!--- Write the two sheets to a single file --->
<cfspreadsheet
action="write"
filename="#filepath#"
name="OccurrenceData"
overwrite="true"
sheetname="Data" >
<cfspreadsheet
action="Update"
filename="#filepath#"
name="Month"
sheetname="Month">
<cfspreadsheet
action="Update"
filename="#filepath#"
name="Person"
sheetname="Person" >
<cfspreadsheet
action="read"
src="#filepath#"
sheetname="occurrencedata"
query="GetData">
這裏就是錯誤發生:變量Occurrence_Data未定義
<cfscript>
SpreadsheetAddRow(OccurrenceData,"Date,Name",1,1);
SpreadsheetAddRow(OccurrenceData,
"#Dateformat(Occurrence_Date,'mm/dd/yyyy')#,#Full_Name_Client#",
2,1,true);
</cfscript>
<cfspreadsheet
action="write"
autosize="true"
filename="#strFileName#.xls"
overwrite="true"
password="password"
query="GetData"
sheetname="Data" >
因此,我調整了我的代碼並將其簡化爲下面的內容,但沒有收到任何錯誤,但我也沒有收到Excel表單 - 只是一個空白屏幕。我知道我需要調整SpreadsheetAddRow行以循環我的數據,以便您可以看到以下更改: spObj = SpreadsheetNew(「Data」); SpreadsheetAddRows(spObj,#getdata#); SpreadsheetAddRow(spObj,「Date,Name」,1,1); SpreadsheetCreateSheet(spObj,「Month」); SpreadSheetSetActiveSheetNumber(spObj,2); –