Many people ask this question in the forum. Because the code is long and the answers provided by many people are not complete, some people who are new to the Forum may take a lot of detours, here we will summarize the generation process and principles, hoping to give you a reference and help.
1. first, generate an Excel file. You need to understand the format of this file, such as the file header information, file body (body part), and file bottom information; in this way, we can detect the structure of an Excel file, create an Excel file, open it, and save it as a webpage, in this way, we can obtain all the code in Excel on the webpage, and store the information and basic information of a few files. We can read the content of these two files when we generate an Excel file like tou.txt and di.txt, and then the file body information, because the output content will generate different content based on our queries, you can directly write the content when writing a program. (For the content part, we can follow the table we prepared, to control the structure of the output content)
Note: After you save excelas as a Web page, you can directly change the extended name to .xls, and the system can still access it. With such content, we can either generate an Excel file of .htmor directly generate an Excel file of .xls.
2. The actual generation process.
The workbook file of catalog.
3. Example
File Header: tou.txt
Bottom file: di.txt
Generation part:
Sub toexcel (filename)
The 'toexcellr variable saves the file body information. You can see that the structure here is table control,
Toexcellr = "<Table width = '000000' border = '0' cellspacing = '0' cellpadding = '0'> <tr align = 'center'>"
Toexcellr = toexcellr & "<TD> company name </TD>"
Toexcellr = toexcellr & "<TD> company name </TD>"
Toexcellr = toexcellr & "<TD> the owner of the overseas task notice </TD>"
Toexcellr = toexcellr & "<TD> Number of copies required for the overseas task notice </TD>"
Toexcellr = toexcellr & "</tr> <tr>"
Toexcellr = toexcellr & "<TD> July Network </TD>"
Toexcellr = toexcellr & "<TD> julyweb </TD>"
Toexcellr = toexcellr & "<TD> July Network </TD>"
Toexcellr = toexcellr & "<TD> 1 </TD>"
Toexcellr = toexcellr & "</tr>"
Toexcellr = toexcellr & "</table>"
Tou = readtext ("tou.txt ")
DI = readtext ("di.txt ")
Toexcellr = tou & toexcellr & di
Call savetext (filename, toexcellr)
End sub
'--------------- Auxiliary function, a function for reading files, and a function for writing files
Function readtext (filename) 'is a function used to read files.
'Response. Write server. mappath (filename)
'Response. End
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
Set ads = nothing
End Function
Sub savetext (filename, data) 'is a function used to write files.
Set FS = Createobject ("scripting. FileSystemObject ")
Set Ts = FS. createtextfile (server. mappath (filename), true)
TS. writeline (data)
TS. Close
Set Ts = nothing
Set FS = nothing
End sub