• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Create Excel and save it to server

Explorer ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

Hi all,

i create a xsl file with:

 

<cfcontent type="application/vnd.ms-excel" >
<cfheader name="Content-Disposition" value="filename=fehlmenge2.xls">

 

But the browser wat everytime to download the file.

i want to make a shedule cfm site and save the file to the server... 

but how can i say save as to server not open in browser?

 

Kindly regards.

thorsten

 

Views

621

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 11, 2021 Apr 11, 2021

Let's say,

1.  our location is the webroot.

2.  the name of the page that generates the Excel sheet is generateExcel.cfm. That is,

 

<!--- generateExcel.cfm --->
<!--- Send the contents, consisting of Excel binary data, to page output --->
<cfcontent type="application/vnd.ms-excel" >
<cfheader name="Content-Disposition" value="inline;filename=fehlmenge2.xls">

 

Then a possible solution is to create a new CFM page, say, saveExcel.cfm. This page GETs the Excel contents by HTTP and saves it at a lo

...

Votes

Translate

Translate
Participant ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

My guess is that you're generating an HTML table and passing that to the browser with an xls extension.    These aren't excel files and if you look at them in notepad, you'll see it's just HTML.   If you want a true xls or xlsx file use spreadsheetnew.   xlsx files will be smaller in size.   You can also use cfspreadsheet if you want xls.

 

Lots of examples online, but this is one I found quickly:

https://blog.mattclemente.com/2019/10/11/til-generating-xlsx-files-with-coldfusion.html

 

If you really want to save an HTML content then just surround the table with cffile.   Make sure you specify a full path for the filename or it might not save where you expect it to.

<cffile action="write" file="#filename#">

    your html table

</cffile>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

<cfcontent type="application/vnd.ms-excel" >
<cfheader name="Content-Disposition" value="filename=fehlmenge2.xls">

 

Are genrating an excel... if i show the page the excel file will automatically download.. and i can open it normal in excel.

but i want to genrate on a sheduler the excel files . in couse of that i donwt want to download the file by load the page.. 

 

i know cfspreadsheet. But the simple way to genrate an excel by a table wth cfcontent and cfheader is simpler...

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 11, 2021 Apr 11, 2021

Copy link to clipboard

Copied

Let's say,

1.  our location is the webroot.

2.  the name of the page that generates the Excel sheet is generateExcel.cfm. That is,

 

<!--- generateExcel.cfm --->
<!--- Send the contents, consisting of Excel binary data, to page output --->
<cfcontent type="application/vnd.ms-excel" >
<cfheader name="Content-Disposition" value="inline;filename=fehlmenge2.xls">

 

Then a possible solution is to create a new CFM page, say, saveExcel.cfm. This page GETs the Excel contents by HTTP and saves it at a location on the server:

 

<!--- saveExcel.cfm --->
<!---
The page generateExcel.cfm generates Excel content. The current page gets the binary content and saves it to a location on the ColdFusion server.
 --->
<cfhttp url="http://localhost:8500/generateExcel.cfm" method="get" getasbinary="yes" charset="utf-8">
<cffile action="write" file="C:\ColdFusion2021\cfusion\wwwroot\docs\ExcelDoc.xls" output="#cfhttp.filecontent#">
Excel file saved to server.

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Fine i think thats the solution.....

 

But now a have the next problem.

My site is with letsencrypt ssl... i get anytime the message:

 

connection failure.....

 

If i try cfhttp with for example google.de all is ok...

Kindly regards

thorsten

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

LATEST

It would be better to mark @BKBK 's response as the answer to this thread's problem and start a new thread with your new problem, otherwise this thread will become confusing for people looking for answers to similar problems.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation