Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Export CSV

Posted on 2001-08-24
1
Medium Priority
?
1,302 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 800 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 informatio…
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 video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

810 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