0

I have a report stored as an .cfm file. I have been able to retrieve it fine with a cffile read. Now I want the option of retrieving only part of the report, say the first 50 lines. I decided to try a fileReadLine():

<cfset repname = url['rep']>
<cfset type = url['type']>

<cfset dataFile = fileOpen("/var/www/reports/moxrep/#repname#.cfm", "read" ) >
<cfset i = 0>
<cfoutput>
<cfloop 
condition = "NOT FileIsEOF(dataFile) AND i LT 100">
<cfset i = i + 1>
<cfset inf = fileReadLine( dataFile ) > 
 #inf#
</cfloop>
</cfoutput>
<cfset fileClose( dataFile ) >  

It did not retrieve things at all correctly. The formatting was messed up. All the dynamic data in the report was missing. The CSS links did not operate. And there were many extra blank lines.

Am I doing something wrong? Or is fileReadLine just not meant for retrieving a formatted report? And if not, is there any way to retrieve just part of the report with cffile?

4

2 回答 2

2

使用 cfhttp 获取报告,然后获取该结果并将其分解为您需要的内容。

于 2013-12-03T04:03:15.833 回答
0

我不确定您是否意识到 FileOpen() 函数实际上是在读取原始 CFML 模板,而不是实际执行填充您的报告的查询。使用 CFHTTP 标记绝对是一种更好的方法,但要小心,因为您呈现的页面可能包含报表正确呈现所必需的所有 CSS,因此请在报表上使用查看源代码来查看是否只需要 50 行。

在我脑海中燃烧的问题是“为什么”你只想要 50 行?你在预览报告吗?它只有一页长?您是否将其嵌入到仪表板中?您可能需要考虑修改 .cfm “报告”,以便您想在其他地方显示的区域用特定标签(例如 Span 甚至自定义的东西)包裹,然后当您使用 CFHTTP 获取报告时,您可以使用 XMLParse() 函数解析结果(假设格式正确)并呈现您真正想要的报告部分。

于 2013-12-05T06:45:09.860 回答