Solved

Export CSV

Posted on 2001-08-24
1
1,254 Views
Last Modified: 2007-11-27
Question:

I have the following code below export out as CSV and have excel auto import.

How do I get it to auto fit columns?

==============CODE===============
response.addheader "Content-disposition", "attachment; filename=" & WebIDocument.Name & ".csv"
     
'response.ContentType = "application/csv"
response.ContentType = "application/vnd.ms-excel"

     Set WebIRS = WebIDocument.GetDPResult(,false)
     nRows = WebIRS.RecordCount
     WebIRS.MoveFirst()
     nCols = WebIRS.Fields.Count
     
     For i = 1 To nCols
          Response.Write (Chr(34))
          Response.Write (WebIRS(i).Name)
          Response.Write (Chr(34))
          If i <> nCols Then
               Response.Write Chr(44)
          Else
               Response.Write  (Chr(13) & Chr(10))
          End If
     Next
     For i = 1 To nRows
          nCols = WebIRS.Fields.Count

          For j = 1 To nCols
               Response.Write (Chr(34))
               Response.Write (WebIRS(j))
               Response.Write (Chr(34))
               If j <> nCols Then
                    Response.Write Chr(44)
               Else
                    Response.Write (Chr(13) & Chr(10))
               End If
          Next
          WebIRS.MoveNext()
     Next
0
Comment
Question by:smilepak
1 Comment
 
LVL 8

Accepted Solution

by:
Dave_Greene earned 200 total points
Comment Utility
I think the only way to get the autofit to work is through OLE automation

Here is an example

Dim Excel
 Dim oSheet
 Dim oRng
 
 Excel.Workbooks.OpenText "c:\file.txt"
 
 Set oSheet = Excel.ActiveSheet
 Set oRng = oSheet.Range("A1", "Z1")
 oRng.EntireColumn.AutoFit
 Excel.ActiveWorkbook.RefreshAll
 
 Excel.ActiveWorkbook.SaveAs "c:\test.xls", FileFormat:=xlNormal
 Excel.Quit
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now