【发布时间】:2013-08-15 04:42:18
【问题描述】:
您好,我必须处理超过 65536 行的数据。因此它分为 2 个不同的 Excel 表格,分别命名为“Details”和“Details_1”。
基本上发生的事情是上传 Excel 表格,并使用“cfspreadsheet”“读取”这些数据。 一旦读取,它就会被插入到 SQL 表中。
我正在使用组件功能来阅读这 1/2 张纸。思路是cfif Query recordcount() from "cfspreadsheet" 大于65533,然后再读第二张表。然后使用 QoQ 和 UNION ALL 创建一个组合查询。(大多数情况只有 1 张,但在某些情况下超过 2 张。)
它工作了一段时间。然后突然停止工作。我不确定错误/错误是否已经潜入其中导致它停止。以下是我的代码
<cftry>
<cfset fileEXCL = "#ExpandPath('../folder')#/#arguments.xclfile#" />
<!---when there e 2 Sheets --->
<!---get info from sheet1 as a "query1"--->
<cfspreadsheet action="read" src="#fileEXCL#" sheet="1" query="Query1" headerrow="1" />
<!--- recordcount for "sheet1" as "count1"--->
<cfset count1 =#Query1.recordcount#>
<!--- case when excel has more than 65533 rows
;THIS IMPLIES THAT THERE 2 SHEETS)--->
<cfif count1 gt 65533>
<!--- take info from sheet 2 as a "query2" and count as "count2"--->
<cfspreadsheet action="read" src="#fileEXCL#" sheet="2" query="Query2" headerrow="1" />
<cfset count2 =#Query2.recordcount#>
<!---club both query's using QoQ and call it "excelQuery"--->
<cfquery dbtype="query" name="excelQuery">
SELECT * FROM Query1
UNION ALL
SELECT * FROM Query2
</cfquery>
<!---total record count for "sheet1" & "sheet2"--->
<cfset rowCount =#excelQuery.recordcount#>
<cfelse>
<!---this case there is just 1 query "Query1" ;rename it "excelQuery"--->
<cfquery dbtype="query" name="excelQuery">
SELECT * FROM Query1
</cfquery>
<!--- recordcount for "sheet1"--->
<cfset rowCount =#excelQuery.recordcount#>
</cfif>
<cflog file="Collections" application="yes" text="#Session.user_info.uname# logged in. Data file #fileEXCL# read. Recordcount:#rowCount#" type="Information">
<cfset ins =insertUserLog("#Session.user_name#","#Session.user_code#","file #fileEXCL# read. ","Recordcount:#rowCount#","")>
<cfcatch type="any" >
<cflog file="Collections" application="yes" text="Error in reading Data file #fileEXCL#." type="Error">
<cfset ins =insertUserLog("#Session.user_name#","#Session.user_code#","error file","failed","#cfcatch.Message#")>
<cfreturn 1>
</cfcatch>
</cftry>
** 我做了以下事情:- a) 试图转储每个工作表的单个 Query 的 Query1 和 Query2 ! 如果它的行数超过 65536 行,IE 页面仍然挂起 无法读取表格 1 和 2。
b) 我已经放置了错误处理来捕获特定的错误,例如“数据库”
c) 当我将行数减少到 65536 以下或删除行数较多的工作表时,它会起作用。
正如我之前所说,这是一个正常工作的代码,然后突然失效了。 **
【问题讨论】:
-
您能否量化“停止工作”是否出错(如果是,请发布完整错误)?它会产生不正确的结果吗?它显然什么都不做吗?另外,到目前为止,您完成了哪些故障排除?这似乎更像是一个“修复我的代码”练习,而不是问一个特定的问题。
-
您使用的是什么版本的 Excel?
-
您是否尝试过将 excel 设为数据源而不使用 cfspreadsheet?
-
不要以这种方式偏离主题,而是使用 .csv 选项而不是 xls 格式?这将使您超过 65k 行限制
-
现在在 CodeReview 上:codereview.stackexchange.com/questions/29790/…
标签: sql excel coldfusion coldfusion-9 cfspreadsheet