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