Solved

Export CSV

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP equivalent to Windows findstr 3 70
SQL Filter Question 8 76
Use a variable for Class Name in Classic ASP 4 44
RegEx Help - open to other simple suggestions 8 35
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…
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…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

932 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

12 Experts available now in Live!

Get 1:1 Help Now