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

Page loads - generates Excel object - create link to download Excel spreadsheet

LEGEND ,
Oct 14, 2015 Oct 14, 2015

Copy link to clipboard

Copied

Hello, all,

I'm helping one of my developers with a project, and I've got one requirement that I'm not entirely sure how to proceed with it.

The page in question runs a SELECT query from the database and displays the tabular information in a table.  As the table is being generated, I'm using spreadsheetnew() and associated commands to create an Excel object from said data.

Now, it would be real easy to introduce code that would automatically offer the Excel object as a spreadsheet upon page load.  What is being requested is for there to be a link to start that stream/download upon click; in case the user doesn't want to save or open the spreadsheet.

I don't want to run the query a second time to generate the Excel object.  Is there a way for me to pass the Excel object to another page to start the stream/download?

V/r,

^_^

Views

372

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 ,
Oct 14, 2015 Oct 14, 2015

Copy link to clipboard

Copied

The client might want to restart the download later, should something go wrong. Another client might also wish to download the file. So you would need a persistent solution.

One way to achieve this is to create a directory beforehand. Write the Excel object as a file to that directory. Then give the URL of the Excel file to the clients.

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
LEGEND ,
Oct 14, 2015 Oct 14, 2015

Copy link to clipboard

Copied

Thanks for the reply, BKBK‌, but this isn't for a public-facing page; this is an internal-only web application, and there's no telling how often the database is updated, so a direct-to-download (or -open) after the data is aggregated is the call.

V/r,

^_^

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 ,
Oct 14, 2015 Oct 14, 2015

Copy link to clipboard

Copied

What about the usual combination,

<cfheader>

<cfcontent>

on the current page.

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
LEGEND ,
Oct 14, 2015 Oct 14, 2015

Copy link to clipboard

Copied

That would automatically download the file as soon as that part of the code is loaded.  The user may not want to open or save the file.  The link is for in case the user does want to open/save.

V/r,

^_^

PS.  If I cannot pass the Excel object, then I can (I suppose) convert the query object into a JSON object, post that to a new page, deserialize the JSON back into a query, generate the Excel object from that and put the CFCONTENT/CFHEADER in that new page.

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 ,
Oct 14, 2015 Oct 14, 2015

Copy link to clipboard

Copied

WolfShade wrote:

That would automatically download the file as soon as that part of the code is loaded. 

You could, for example, use threads to ensure that download is only possible after the page finishes processing.

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
LEGEND ,
Oct 14, 2015 Oct 14, 2015

Copy link to clipboard

Copied

BKBK wrote:

You could, for example, use threads to ensure that download is only possible after the page finishes processing.

WolfShade wrote:

The user may not want to open or save the file.  The link is for in case the user does want to open/save.

V/r,

^_^

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 ,
Oct 16, 2015 Oct 16, 2015

Copy link to clipboard

Copied

This is confusing me now. You said links were out, didn't you?

In any case, I fail to see the relevance to threads of the open, save and link use cases. Could you please explain. Thanks.

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
LEGEND ,
Oct 16, 2015 Oct 16, 2015

Copy link to clipboard

Copied

Hi, BKBK,

Per my OP:

WolfShade wrote:

What is being requested is for there to be a link to start that stream/download upon click; in case the user doesn't want to save or open the spreadsheet.

Threads can be useful for making sure that a page loads before certain processing is completed.  At least, that's what I'm led to believe - I've never used threads, before.  I'm sure there are other case-scenarios where threads are useful.

But in this case threads would be unnecessary, as the Excel object is being created on-the-fly as the display data is being created by CF, and I can use JavaScript window.onload to create a link _after_ the page loads (when the Excel object will be ready, at this point.)  But I guess I'm confused, too, as I don't understand your reasoning for suggesting them _in place of_ a link to download the Excel spreadsheet after the page loads.  It seemed (to me) that you were still suggesting having the spreadsheet automatically offered to the user once the page was done loading.  I'm looking for a way to have the user click a link to stream/download the spreadsheet _if the user wants it_.

If you can recommend a way to pass the Excel object to another page for streaming the Excel object, that's what I am asking.  If not, I could replace the Excel object code with code to create a custom query object (the original developer is using a query within a query loop to aggregate the data) that I can flatten into a JSON string and submit via form to a new window.  I'd like to keep the code I've written, so far; but I can do this option if passing an Excel object is not possible.

V/r,

^_^

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 ,
Oct 17, 2015 Oct 17, 2015

Copy link to clipboard

Copied

LATEST

WolfShade wrote:

... the Excel object is being created on-the-fly as the display data is being created by CF, and I can use JavaScript window.onload to create a link _after_ the page loads (when the Excel object will be ready, at this point.) ...I don't understand your reasoning for suggesting them [threads] _in place of_ a link to download the Excel spreadsheet after the page loads.

I am not suggesting threads in place of a link. In fact, I am suggesting you use threads to create the link.

Threads are relevant because timing - before and after loading - is important here. Plus, you are running at least two processes simultaneously: generating a table and creating an Excel object.

Run these processes within respective threads, named th1 and th2, say. Then join the threads with something like

<cfthread action="join" name="th1,th2" timeout="1000" />

You can be sure that all the data will have been loaded after this line of code.

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