首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cfspreadsheet导致变量未定义错误

cfspreadsheet导致变量未定义错误
EN

Stack Overflow用户
提问于 2017-02-16 03:23:45
回答 1查看 335关注 0票数 0

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

我使用了Adobe - http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec17cba-7f87.html中的示例

我还查看了其他示例,但这些示例使用cfspreadsheet和poi或java的组合,如果可能的话,我更喜欢只使用cfspreadsheet。你知道我下面的代码问题是从哪里来的吗?谢谢。

代码语言:javascript
复制
<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未定义

代码语言:javascript
复制
<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" > 
EN

回答 1

Stack Overflow用户

发布于 2017-02-16 04:26:32

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

代码语言:javascript
复制
<cfcontent type="application/vnd.ms-excel" reset="Yes">

问题2.如果你想把两个工作表写到一个文件中,你不需要这样做:

代码语言:javascript
复制
OccurrenceData = SpreadsheetNew("Data"); 
Month = SpreadsheetNew("Month"); 

你可以这样做:

代码语言:javascript
复制
OccurrenceData = SpreadsheetNew("Data"); 
// do stuff with this sheet
SpreadsheetCreateSheet(OccurrenceData, "Month");
SpreadSheetSetActiveSheetNumber(OccurrenceData, 2);
// do stuff with this sheet

SpreadSheetWrite(OccurrenceData, whateverYourFileNameIs);

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42258339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档