Supplement: MSO-NUMBER-FORMAT: General; à mso-number-format: @; this can avoid digital transfer of scientific counting and zero disappearance. Use
SQL
of
SELECT
The result of the query is output
Excel
Format file, this program you only need to make a recordset
SQL
of
SELECT
Query the statement and a file name, the program can output
Excel
The format file, this program consists of three files, the file name of the first file is:
TOEXCEL.ASP
Is the primary file, the content is as follows:
<%
'The front is to link to the database, please write the relevant statement yourself, this is slightly
SQL = session ("TOEXCELSQL") 'This is the query statement to output Excel, such as "Samplect * form cai where gender =' female '"
Filename = "excel.xls" '' The file name of the Excel file to output, you only have to change the above two sentences, do not change anything else.
'You just modify the above two variables. Others I have done it.
Call ToExcel (FileName, SQL)
Set conn = Nothing
Function ReadText (filename) 'This is a function for reading the file.
Set Adf = Server.createObject ("AdoDb.Stream")
WITH ADF
.Type = 2
.LINESEPARATOR = 10
.Open
.Loadfromfile (server.mappath (filename))
.Charset = "GB2312"
.Position = 2
Readtext = .readText
.Cancel ()
.Close ()
End with
Set ads = Nothing
END FUNCTION
Sub Savetext (filename, data) 'This is a function for writing files.
Set fs = creteObject ("scripting.filesystemobject")
Set ts = fs.createtextfile (server.mappath (filename), true)
Ts.writeline (DATA)
Ts.close
SET TS = Nothing
SET FS = Nothing
End Sub
Sub toExcel (filename, SQL) 'This is a SQL statement and filename generates an Excel file
SET RS = Server.createObject ("AdoDb.Recordset")
RS.Open SQL, CONN, 1, 3
TOEXCELLR = "
" & formatdatetime (rs (FieldName (I)), 2) & " p> td>"
Else
TOEXCELLR = TOEXCELLR & "
p> td>"
END IF
Else
TOEXCELLR = TOEXCELLR & " | " & RS (FieldName (i)) & " td>"
END IF
NEXT
TOEXCELLR = TOEXCELLR & " TR>"
rs.movenext
loop
TOEXCELLR = TOEXCELLR & " TABLE>"
Tou = readtext ("Tou.txt")
Di = readtext ("di.txt")
TOEXCELLR = Tou & ToExcellr & Di
Call SaveText (FileName, TOEXCELLR)
End Sub
%>
is generating an exlu file title>
hEAD>
Generating an EXLCE file ....
Body>
Html>
************** The second file name is: di.txt content is as follows:
td>
| td>
| td>
| td>
TR>
TABLE>
*********** The file name of the third file is: Tou.txt content is as follows:
XMLns: x = "URN: Schemas-Microsoft-Com: Office: Excel"
XMLns = "http://www.w3.org/tr/rec-html40">
o: OfficedocumentSettings>
xml>
{MSO-Displayed-Decimal-Separetor: "/."
MSO-Displayed-Thousand-Separetor: "/,";
@PAGE
{margin: 1.0in .75in 1.0in .75in;
MSO-HEADER-Margin: .5in;
MSO-FOOTER-Margin: .5in;
TR
{MSO-HEIGHT-SOURCE: AUTO;
MSO-Ruby-Visibility: none;
COL
{MSO-Width-Source: Auto;
MSO-Ruby-Visibility: none;
Br
{MSO-DATA-Placement: Same-Cell;
.style0
{MSO-NUMBER-FORMAT: General;
Text-align: general;
Vertical-align: bottom;
White-space: nowrap;
MSO-ROTATE: 0;
MSO-Background-Source: Auto;
MSO-PATTERN: AUTO;
Color: WindowText;
FONT-SIZE: 9.0pt;
Font-Weight: 400;
Font-style: Normal;
Text-decoration: none;
FONT-FAMILY: Song;
MSO-generic-font-family: auto;
MSO-FONT-CHARSET: 134;
Border: none;
MSO-PROTECTION: LOCKED VISIBLE;
MSO-Style-Name: General;
MSO-style-id: 0;}
TD
{MSO-style-parent: style0;
Padding-top: 1px;
Padding-right: 1px;
Padding-left: 1px;
MSO-IGNORE: PADDING;
Color: WindowText;
FONT-SIZE: 9.0pt;
Font-Weight: 400;
Font-style: Normal;
Text-decoration: none;
FONT-FAMILY: Song;
MSO-generic-font-family: auto;
MSO-FONT-CHARSET: 134;
MSO-NUMBER-FORMAT: General;
Text-align: general;
Vertical-align: bottom;
Border: none;
MSO-Background-Source: Auto;
MSO-PATTERN: AUTO;
MSO-PROTECTION: LOCKED Visible;
White-space: nowrap;
MSO-ROTATE: 0;
.xl24
{MSO-style-parent: style0;
Border: .5pt solid windowtext;}
.xl25
{MSO-style-parent: style0;
MSO-NUMBER-FORMAT: "Long Date";
Text-align: Left;
Border: .5pt solid windowtext;}
Ruby
{Ruby-align: Left;}
RT
{Color: WindowText;
FONT-SIZE: 9.0pt;
Font-Weight: 400;
Font-style: Normal;
Text-decoration: none;
FONT-FAMILY: Song;
MSO-generic-font-family: auto;
MSO-FONT-CHARSET: 134;
MSO-CHAR-TYPE: NONE;
DISPLAY: NONE;
->
style>
sheet1 x: name>
225 x: defaultRowheight>
9 x: PapersizeIndex>
-3 x: HorizontalResolution>
0 x: VerticalResolution>
x: print>
3 x: Number>
24 x: activeRow>
5 x: ActiveCol>
x: pane>
x: panes>
false x: protectcontents>
false x: protectobjects>
False x: ProtectsCenarios>
x: WorksheetOptions>
x: Excelworksheet>
Sheet2 x: name>
225 x: defaultRowheight>
false x: protectcontents>
false x: protectobjects>
False x: ProtectsCenarios>
x: WorksheetOptions>
x: Excelworksheet>
Sheet3 x: name>
225 x: defaultRowheight>
false x: protectcontents>
false x: protectobjects> false x: protectscenarios>
x: WorksheetOptions>
x: Excelworksheet>
x: Excelworksheets>
6600 x: windowheight>
12000 x: WindowWidth>
0 x: Windowtopx>
1395 x: windowtopy>
false x: protectstructure>
false x: protectWindows>
x: Excelworkbook>
xml>
hEAD>
转载请注明原文地址:https://www.9cbs.com/read-80491.html
| |