Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Export CSV

Posted on 2001-08-24
1
1,274 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
ID: 6422790
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using querystring in a hyperlink 3 56
ASP SQL Syntax Duplicate Key 7 110
Hide cell in a table 2 27
ASP exit 10 19
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 …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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