How to collect data into Excel

Source: Internet
Author: User
I often see some people asking how to transfer the Table data to Excel. Many people consider using execl to solve this problem first. appliction: I have used appliction. First, I have to master some of its internal usage. Second, it involves security when used on the client. The following describes three methods:
Method 1: Implemented in plain text format
This method is quite simple. The following code is provided for you to understand.
<% Set fso = server. createobject ("scripting. filesystemobject ")
StrExcelFile = server. MapPath ("txtToExcel.xls ")
If fso. fileExists (strExcelFile) then fso. deletefile strExcelFile
Set destination file = fso. CreateTextFile (strExcelFile, True)
Using File. WriteLine ("df" & vbTab & "345" & vbLf & "fe" & vbTab & "mon" & vbLf)
Closing file. Close
Set fso = nothing
Response. write "OK"
%>
Principle:
I believe everyone knows that Excel can open text files (what? You don't know, you should first go back to work as a clerk for two months and then program again, so you don't understand how to break the rules), and Excel will process the text content in it as follows: if you encounter a [Tab] Tab key, you will jump out of a column. If you encounter a [line break], you will change the next line. Therefore, we can sort out this rule to generate a single table-type Excel file,
Advantages:
Easy to master, just plain text sorting (ha! It wasn't just a text game! When it comes to games, let's get started)
Disadvantages:
Low efficiency. If you convert a table with more content into an Excel file, you need to execute a long loop (). The document format can only be a rule row and column format, and you cannot set more tables.
Method 2: Use OWC to implement:
This method is also simple (OWC! Don't learn new things again? Don't worry, it's very simple, as long as you have a good head of men, OK, what? It's not enough. I'm sorry, I'm addicted to it, but I am not familiar with it (I didn't see anyone else on the Internet ), the code is also given first:
<Script language = "javascript">
Function exportExcel (atblData ){
If (typeof (EXPORT_OBJECT )! = "Object "){
Document. body. insertAdjacentHTML ("afterBegin", "<OBJECT style = 'display: none' classid = clsid: 0002e510-0000-0000-c000-00000046 id = EXPORT_OBJECT> </Object> ");
}
With (EXPORT_OBJECT ){
DataType = "HTMLData ";

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.