You should send headers before any page/file output - this is same for all 
languages and caused by HTTP protocol format.

среда, 20 июня 2012 г., 10:24:42 UTC+4 пользователь ravi prakash написал:
>
>
> Hi Andrew, 
>
>   Thanks for your quick response. I tried your first option. 
>   Say, i have data from database in array called results, 
>
>   for(var i = 0; i < results.length; i++) { 
>
>        body = ''; 
>        body =  results[i]+'\n'; 
>        res.write(body); 
>   } 
>   res.setHeader('Content-disposition', 'attachment; 
> filename='sample.csv'); 
>   res.setHeader('Content-type', 'text/csv'); 
>   res.end(''); 
>
>  I want to write data in chunks since my array is very big. I used 
> res.write() for this. By doing this my response is written directly to 
> browser 
>  and file download option is not asked. How can i solve this? 
>
>  -Ravi 
>
>
>
>
>
>
>
>
> On Jun 20, 10:40 am, Andrew Stone <[email protected]> wrote: 
> > Hi Ravi, 
> > 
> > Since you already have the csv content generated you just want to send 
> > it out with res.write() or res.end() depending upon whether you are 
> > writing it out in chunks or not (streaming). 
> > 
> > To get the CSV to be a downloadable file you need to add the 
> > 'content-type' and 'content-disposition' headers to your response: 
> >  res.header('content-type','text/csv'); 
> >  res.header('content-disposition', 'attachment; filename=report.csv'); 
> > 
> > For more complex stuff, ya-csv looks useful. 
> > 
> > -Andrew 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > On Wed, Jun 20, 2012 at 1:47 AM, Matthew Vickers <[email protected]> 
> wrote: 
> > > I have used ya-csv in the past, it works well for our basic usage. 
> > 
> > >https://github.com/koles/ya-csv 
> > 
> > > Matt 
> > 
> > > ----- "ravi prakash" <[email protected]> wrote: 
> > 
> > >> Hi group, 
> > 
> > >> How can i generate a excel/csv file from nodejs application. Say, I 
> > >> have a link in webpage and on click of link, i query database and put 
> > >> result into excel/csv file. Finally the file download  must be 
> > >> opened. 
> > >> I am building application using nodejs+express. 
> > 
> > >> My goal is to export data into a excel/csv file ie generate excel/csv 
> > >> file from my application. 
> > 
> > >> Say i have link in webpage ----- 
> > 
> > >>       <a href='/report'>Export</a> 
> > 
> > >> Server side i have code ------ 
> > 
> > >> app.get('/report', function(req, res) { 
> > 
> > >>    //get data from db 
> > 
> > >>    How to put data to csv/excel file ??? 
> > 
> > >> } 
> > 
> > >> -- 
> > >> Job Board:http://jobs.nodejs.org/ 
> > >> Posting guidelines: 
> > >>https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines 
> > >> You received this message because you are subscribed to the Google 
> > >> Groups "nodejs" group. 
> > >> To post to this group, send email to [email protected] 
> > >> To unsubscribe from this group, send email to 
> > >> [email protected] 
> > >> For more options, visit this group at 
> > >>http://groups.google.com/group/nodejs?hl=en?hl=en 
> > 
> > > -- 
> > > Job Board:http://jobs.nodejs.org/ 
> > > Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines 
> > > You received this message because you are subscribed to the Google 
> > > Groups "nodejs" group. 
> > > To post to this group, send email to [email protected] 
> > > To unsubscribe from this group, send email to 
> > > [email protected] 
> > > For more options, visit this group at 
> > >http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to