I am trying to create a spreadsheet (.XLS file) using Adobe ColdFusion - 8.
The code that creates a spreadsheet is:
<cfsetting enablecfoutputonly="Yes">
<cfset date_from = "#URL.date_from#">
<cfset date_to = "#URL.date_to#">
<cfset query_id="#URL.queryID#">
<cfquery name="GetEmps" datasource="cfdocexamples">
<!--- My SQL Queries Goes Here--->
</cfquery>
<cfcontent type="application/msexcel">
<cfheader name="Content-Disposition" value="filename=Employees.xls">
<cfoutput>
<table cols="4">
<cfloop query="getData">
<tr>
<td>#uid#</td>
<td>#week#</td>
<td>#book_count#</td>
</tr>
</cfloop>
</table>
</cfoutput>
Whenever I run the page, an XLS sheet is created, but I cannot find any data. The size of the created XLS file is 0.
Please Note: The Query is correct(Since when I print the output as html, I can see the table without any error/warning).
** After reading comments: UPD**:
I had updated my code and only included important code snippet now.
UPD 2:
Whenever I commented the line <cfsetting enablecfoutputonly="Yes"> , xls file is created with expected data. However, when I opened the generated file, a dialogue appears:
Please note the spreadsheet generated is perfect. Only thing that is bothering me is the above warning.
Also Note: whenever I tried to open the spreadsheet in google-docs as a preview, it says, the file could not be opened due to corrupted format.
However, I am able to open it perfectly in an MS-Excel.
Even changing content type to : <cfcontent type="application/vnd.msexcel"> , I got the same warning.
While I cannot speak exactly how to implement this, I know the developers within my organization worked around it with the Apache POI. It seemed to do the trick for them. It does have to be completed with Java through Coldfusion. Here is an example of it.
Related
I have a action page that redirects to a page based on condition.
I thought of Including that page insted of redirection.
So i used cfinclude function to include this file.
But including that file doesn't work.
But when i open that page in browser it is working fine without error.
For Ex.
http://domain.com/page2.cfm?cutomerID=10
is working fine.
IN http://domain.com/page1.cfm
I am including below code.
<cfset url.customerID = 10>
<cfinclude template="page2.cfm">
Even i tried to add only HTML content which i get in page source for "http://domain.com/page2.cfm?cutomerID=10"
It is still not working including a coldfusion page with just html text without any coldfusion code.
Strange thing is When i tried to remove some text from this html content it works for some time but when i reload it stops and give the below error again.
I am not sure if cfinclude has to do anything page length or some other factors.
Screenshot for error is attached below.
Error Screenshot Image
If you are asking for a link you can have it as:
<cfoutput>
<cfset href="domain.com/page2.cfm?customerID=#customerid#&etc=#etc#" />
</cfoutput>
For your question you can use this:
<cfset custID = 10/>
<cfinclude template="page2.cfm">
In page2.cfm:
<cfif isDefined(url.customerID) || isDefined(custID)>
<!--- your etc code here --->
</cfif>
Note: If you don't want to use url.customerID you can simply delete the occurance
OK, so I've spent the last couple of days researching this issue on various websites including this one and I'm still no closer to having an answer. I have seen claims that this was a bug and was fixed on Adobe's end in one of the CF11 patches and I have even seen one answer that claimed that Adobe was emailing the fix directly to individuals - though no information on how to go about getting Adobe to do that was provided on that webpage.
We just updated our intranet to Coldfusion 11 and pages that have a cfgrid using the HTML format and bind data from a cfc no longer show the cfgrid on the page. Other pages that use the Flash format with cfgrid (which apparently can't use the bind attribute with Flash) do work. These HTML cfgrid pages were working properly in Coldfusion 9 before we migrated to 11.
I have simplified the code as much as I can to eliminate other error possibilities - i.e. I've stripped out formatting and am pulling only a couple columns from the database. Here is the code I am currently working on in my dev sandbox:
<cfgrid format="html"
name="userGrid"
bind="cfc:editorFunc.getGridData({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
pagesize="20">
<cfgridcolumn name="REGION" header="Region">
<cfgridcolumn name="managmentArea" header="Management Area">
</cfgrid>
Here is the code in the cfc (the query does produce results when dumped to the page):
<cffunction name="getGridData" access="remote">
<cfargument name="page">
<cfargument name="pageSize">
<cfargument name="gridsortcolumn">
<cfargument name="gridsortdir">
<cfquery name="records" datasource="webData">
SELECT REGION, managmentArea
FROM areaDesc
ORDER BY Region ASC
</cfquery>
<cfset result = queryConvertForGrid(duplicate(records), arguments.page, arguments.pagesize)>
<cfreturn result>
</cffunction>
Has anyone had any luck getting a cfgrid like this to work in CF11? I could try a JQuery solution like JGrid, however I would prefer to figure out the existing issue with this code if possible.
Any help is much appreciated.
Add this..
<cfif not len(trim(arguments.gridsortcolumn))>
<cfset arguments.gridsortcolumn = "REGION">
<cfset arguments.gridsortdir = "desc">
</cfif>
query....
ORDER BY #arguments.gridsortcolumn# #arguments.gridsortdir#
I am severely new to ColdFusion... I have searched for help on this statement and have found a bunch of material, but still don't understand what is going on. All of the parts of this statement make sense, but when I put them all together, it's confusing... the ColdFusion 8: IsDefined("URL.variable) and is not"" thread is the closest, but I still don't understand. This is the 1st statement in the index.cfm file of my application. It's not throwing an error, I just want to understand how it works. Thank you.
I have yet to be able to successfully post code here, so here is a link to a text version of the index.cfm.
Edit:
The code below should be the relevant sections related to URL.openFile
<cfif isdefined("URL.openFile")>
<cfquery name="getFile" datasource="xxxxxxxx">
SELECT filename, filename2, filecontent, filesize
FROM Help_FooterInfo
WHERE Help_id=5 and Section='Registration'
</cfquery>
<cfset sproot=#getDirectoryFromPath(getTemplatePath())#>
<cfset newDest = #sproot#&"temp\">
<cfoutput query="getFile">
<cfheader name="Content-Disposition" value="attachment; filename=#getfile.FileName2#">
<cfcontent type="application/msword" variable="#getfile.filecontent#">
</cfoutput>
</cfif>
...
<cfquery name="getRegistration" datasource="xxxxxxxx">
select * from help_footerinfo where help_id=5
</cfquery>
....
<cfoutput>#getRegistration.Content#</cfoutput><br>
<a href="<cfif #getRegistration.filename2# neq "">index.cfm?openfile=Yes</cfif>" target="_blank">
<u><cfoutput>#getRegistration.FileName#</cfoutput></u>
</a>
The error message I am receiving (see comment below): ORA-00942: table or view does not exist (ColdFusion application)
This:
<cfif IsDefined("URL.variable") and URL.variable is not "" >
means, "If url.variable actually exists and is not an empty string".
A better alternative for isDefined("URL.variable") is StructKeyExists(url,"variable").
Other alternatives for is not "" include len(trim(url.variable)) gt 0, and isNumeric(url.variable).
I am using Coldfusion 8 and I am trying to serve a file of 15mo with cf_content. The problem is that the download freezes randomly. At the moment, I only tried locally, therefore the network is not the problem. I have tried with smaller files and freezes happen less often. I have no idea of the root of the problem. Here is my coldfusion code:
<cfheader name="Content-Disposition" value="attachment; filename=test.zip">
<cfcontent type="application/zip" file="C:\Test.zip" deletefile="no">
I tried to download the file with Chrome, IE and with a piece of java code to download the file (freeze on the read method after some iteration).
Do you have any idea of how I can easily stream a file using Coldfusion? Maybe it is possible using a Java Custom tags but how to write bytes to page as the custom tag write method of the Response object only allows to write a String?
I did this for a client. I am gathering a number of documents and zipping them for download. Rather than stream them, I save the zip file on the server:
<cfzip action="zip" file="#expandpath('/data/briefcase/')##session.order_id#.zip" source="#expandpath('/data/briefcase/')##session.order_id#" overwrite="yes" storepath="no">
Then I provide the user a link to download the file. That way, if it fails, they can always try again.
I then wrote a scheduled task that runs every day and delete any zip files more than 24 hours old.
<cfdirectory action="list" directory="#expandpath('/data/briefcase/')#" name="filelist" >
<cfquery name="filter_file" dbtype="query" >
SELECT * from filelist WHERE datelastmodified < #dateadd("h", -48, now())# AND type = 'File'
</cfquery>
<cfquery name="filter_dir" dbtype="query" >
SELECT * from filelist WHERE datelastmodified < #dateadd("h", -48, now())# AND type = 'Dir'
</cfquery>
<cfset path = expandpath('/data/briefcase/')>
<cfoutput query="filter_file">
<cfif fileexists('#directory#/#name#')>
<cffile action="delete" file="#directory#/#name#" >
</cfif>
</cfoutput>
<cfoutput query="filter_dir">
<cfif directoryexists('#directory#/#name#')>
<cfdirectory action="delete" directory="#directory#/#name#" recurse="true" >
</cfif>
</cfoutput>
See if helps to prepend your code with:
<cfheader name="Content-Length" value="#GetFileInfo('C:\Test.zip').size#">
That tells the browser how much data to expect.
I am using <cfdocument> tag of coldfusion 7. Using CFEclipse and working on MacOS.
I have written the following code:
<cfdocument format="pdf">
SitePoint.com - Introduction to ColdFusion 7
PDF Generation
This is an example of PDF generation using ColdFusion 7.
</cfdocument>
But instead of asking me to save this file in .pdf format, its trying to open it in .cfm format.
How can I save it in .pdf format? Thanks!
Unless you tell it otherwise, the webserver returns the results of a CFM call as text. You need to use CFContent with CFHeader to alert the browser that the results it will be recieving are of a different type. Something like:
<cfheader name="Content-Disposition" value="inline; filename=document.pdf">
<cfcontent type="application/x-pdf">
<cfdocument>...</cfdocument>
I may have the MIME type wrong there. I'm doing this from memory. Check the docs for more help.
If you are on CF8 or higher then use the saveAsName attribute:
<cfdocument saveAsName=""
Either that or the method suggested by Ben above should work
You might also need to import the style sheet as well. So you can get the desired formatting. It needs to be imported after cfdocument.
<cfdocument
format="pdf"
filename = "canwriteurfile.pdf"
overwrite = "yes"
marginBottom = ".2"
marginLeft = ".4"
marginRight = ".4"
marginTop = ".2">
<style type="text/css">#import "pdf.css";</style>
BLAHHH BLAHHH PDF FORMATTING STUFF
</cfdocument>
Try:
<cfdocument format="PDF" name="myPDF">
<html>
<body>
SitePoint.com - Introduction to ColdFusion 7
PDF Generation
This is an example of PDF generation using ColdFusion 7.
</body>
</html>
</cfdocument>
<cfpdf action = "write" destination = "pdf_path" source = "myPDF" overwrite = "yes"/>
<cflocation url="pdf_path"/>
Whis this you save the PDF on disk