0

我正在尝试使用 cfspreadsheet 读取在多个选项卡上具有预定义图表的电子表格,但是在处理数据时,我得到变量未定义。

我使用了 Adob​​e 的示例 - 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" > 
4

1 回答 1

0

第一个问题。这可能弊大于利。

<cfcontent type="application/vnd.ms-excel" reset="Yes">

问题 2。如果要将两张表写入一个文件,请不要这样做:

OccurrenceData = SpreadsheetNew("Data"); 
Month = SpreadsheetNew("Month"); 

你做这样的事情:

OccurrenceData = SpreadsheetNew("Data"); 
// do stuff with this sheet
SpreadsheetCreateSheet(OccurrenceData, "Month");
SpreadSheetSetActiveSheetNumber(OccurrenceData, 2);
// do stuff with this sheet

SpreadSheetWrite(OccurrenceData, whateverYourFileNameIs);

我也建议你一次做一件事。写一点代码,运行一下,看看结果。然后添加更多代码,运行它,然后查看结果。这将帮助您隔离导致错误的代码。

于 2017-02-15T20:26:32.370 回答