cfspreadsheet导致变量未定义错误

时间:2017-02-15 19:23:45

标签: excel coldfusion 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" > 

1 个答案:

答案 0 :(得分:0)

问题编号1.这可能弊大于利。

<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);

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