login about faq

Hello,

I am revamping a user report from html to csv. Depending on the user's options this report can be very large. I would like to stream the report to the browser the same way that I can stream or chunk a pdf or zip file to the browser. I think I am on the right track but I have two issues. First, Excel reports the file is incomplete and second, all the the data is on a single line

Thanks,

Erik

Code

Set oStr = Server.CreateObject("Chilkat_9_5_0.StringArray")
oStr.LoadFromText oCsv.SaveToString

With Response
  .Buffer = true
  .Expires = 0
  .Clear
  .ContentType = "text/csv"
  .AddHeader "content-length", oStr.Length -1
  .AddHeader "content-disposition", "inline; filename=""Report.csv"""
  .flush

End With

Idx = 0: Ctr = 0
For Idx = 0 To oStr.Count -1
  Ctr = Ctr + 1
  If Ctr = 100 Then
    Response.Flush
    Ctr = 0

  End If

  Response.Write oStr.GetString(Idx) & vbLf

Next
Response.Flush
oStr.Clear
Set oStr = Nothing

asked Jun 25 '15 at 14:34

emartinson's gravatar image

emartinson
148162030


A few thoughts:

  1. Perhaps Excel is expecting CRLF instead of LF line-endings? Try setting the CSV Crlf property to 1.
  2. Similarly to #1, you are appending vbLf to each Response.Write - try vbCrLf instead.
  3. Again in the same vein as above - try setting the StringArray object CRLF property to 1.
  4. You are setting the Content-Length header to the size-1, but I think it should be set to the size.
  5. Not sure if you need the trailing vbCrLf on the last write? I would experiment with and without.
link

answered Jun 25 '15 at 20:16

jpbro's gravatar image

jpbro ♦
1.1k2618

Number 1 had no effect on the data/ I even upgraded to ver .51. Number 4 is the odd duck here and also the key to the entire issue. No matter what value I set the con-len with, it did not send display correctly. It did work however if I removed the header completely. Must be an excel thing. Number 5, I added vbNewLine which is the same as vbCrLf.

(Jun 29 '15 at 15:47) emartinson
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×8
×6
×3

Asked: Jun 25 '15 at 14:34

Seen: 1,614 times

Last updated: Jun 29 '15 at 15:47

powered by OSQA