Solved

Export CSV

Posted on 2001-08-24
1
1,267 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

815 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

10 Experts available now in Live!

Get 1:1 Help Now