ASP export Excel Data FSO cell format

Source: Internet
Author: User

<! -- # Include file = "../Conn. asp" -->
<%

Dim S, SQL, filename, FS, myfile, X

Set FS = server. Createobject ("scripting. FileSystemObject ")
'-- Suppose you want to store the generated Excel file as follows:
Filename = server. mappath ("users.xls ")
'-- If the original Excel file exists, delete it.
If fs. fileexists (filename) then
FS. deletefile (filename)
End if
'-- Create an Excel file
Set myfile = FS. createtextfile (filename, true)

'Set rs = server. Createobject ("ADODB. recordset ")
'-- Check the data you want to put in Excel from the database.
'SQL = "select * From tb_execl order by ID DESC"
'Rs. Open SQL, Conn
Starttime = request ("starttime ")
Endtime = request ("endtime ")
Startendtime = "addtime between #" & starttime & "00:00:00 # And #" & endtime & "23:59:59 #"

Strsql = "select * From myeky_myusr"
Set rstdata into conn.exe cute (strsql)
If not rstdata. EOF and not rstdata. bof then

Dim trline, responsestr
Strline = ""
For each X in rstdata. Fields
Strline = strline & X. Name & CHR (9)
Next

'-- Write the column name of the table to excel first
Myfile. writeline strline

Do while not rstdata. EOF
Strline = ""

For each X in rstdata. Fields
Strline = strline & X. Value & CHR (9)
Next
Myfile. writeline strline

Rstdata. movenext
Loop

End if

Response. write "the Excel file is generated successfully. Click <a href =" "users.xls" "target =" _ blank ""> download </a>! "

Rstdata. Close
Set rstdata = nothing
Conn. Close
Set conn = nothing
%>

Problem:
Generate data in an Excel file. For example, the date and time type shows 8 # by default; the value is 20071022130515 after the number is too long, and the default value is 20071022130515. The default value is 2.0071e + 13;
How to export an Excel file. By default, the date type is-10-23, not 8 #. If the value is too long, the display is normal.
1. How to set the export cell format during export
2. How to control the column width and column height;
3. How to merge cells during export;

1st answers to this question:
Add 'to the number to display all the numbers.

Others have been written in VB:
Dim mexapp as Excel. Application
Dim mexbook as Excel. Workbook 'workbook
Dim mexsheet as Excel. worksheet 'Worksheet

2nd answers to this question:
Set mexapp = Createobject ("Excel. application") 'defines the XLS object
Set mexbook = mexapp. workbooks. Open (fielpath & "/" & xlfielname & ". xls") 'defines the workbook object
Set mexsheet = mexbook. worksheets (1) 'defines the worksheet object

Mexsheet. cells. numberformatlocal = "@" 'is set to text format
.....

'Automatic column Adjustment
For column = 1 to rstfield
Mexico. Columns (Column). autofit
Next

3rd answers to this question:
3. How to merge cells during export;

Follow

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.