Web page data export method overview-export excel

Source: Internet
Author: User

Preface:
With the widespread use of BS architecture, the corresponding data storage technology should also be improved, corresponding to the Web page, that is, the HTML file we generally recognize, A file composed of a combination of labeled keywords and data. To export Web page data, separate the data and format and save the data in another format.
Body:
The Analysis of HTTP Response and other file header information is very useful for how to process Web pages. The following describes several common methods, which are technically and theoretically used.
The following code analyzes how to modify the http header file to generate an excel file for users to download for data export. The advantage of generating files on the server is that users who concurrently request this page will not overwrite the files on the server with the same name! Generally, the solution is based on the user name, ip address, and random number.
Dim resp As HttpResponse
Dim colCount As Integer = MyDataGrid. Columns. Count-1
Resp = Page. Response
Resp. ContentEncoding = System. Text. Encoding. GetEncoding ("GB2312") 'key to solving Chinese garbled characters
'Resp. Charset = "UTF-8"
'Resp. AddFileDependency (FileName)
'Resp. ContentType = "Text/HTML"
''Resp. AppendHeader ("Content-Type", "text/html; charset = gb2312 ")
Resp. ContentType = "Text/csv" 'by modifying the file type, you can download a csv file and modify the text/** content.
Resp. AppendHeader ("Content-Disposition", "attachment; filename =" + FileName + ". csv") 'is necessary to make it a download file.
'Actually, from the perspective of the type of the file to be downloaded, you can use txt, html, and xls files. Do you not know? Files saved as xls are included in a column.
Dim colHeaders As String = ""
'Imports System. Text

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.