The way data is exported to a Word file or Excel file

Source: Internet
Author: User
Tags format blank page
excel|word| data often has to read the contents of the database and generate an Excel file or Word file. Let me talk about my approach and ideas. Please advise the Master


One of the easiest ways to do this is to:
Is the front Plus:
Response.ContentType = "Application/msexcel"
Then it will be opened with Excel.
However, this method will appear a lot of strange problems, such as some machine can be opened, some machines are not, different Office version may not be, but also open a blank page and so on.

The second method:
Through the experiment, we found that an HTML table extension to XLS, double-click, the computer actually opened with Excel, look closely, still like the model, that is, if different versions of Excel to open. Maybe the form line is gone.
Well, that's a good time to read the contents of our database, generate a table in HTML format, then write this table in a file with the extension xls, and then turn to the XLS file, almost done. However, there are three questions to be found: 1. Sometimes opening may be a blank, 2. Illegal operation when closing, and leave an Excel process. 3. The form line is gone.
The solutions to these three problems are as follows:
First question: After generating this temporary XLS file, do not immediately turn to it, after a two-second turn.
The second and third question:
I do a table in Excel, then save as HTML format, you will find that if you turn to this file, the format is not wrong, there is no illegal operation to close the hint, there is no more than that process. Then open this HTM file a look at its code, found in front of a lot of code, the table of each < Td> more code after that. Ok. We'll also dots in this format to generate a file with the extension XLS (which is actually an HTML file).

The above is my method, please talk about your own method, I hope to get a better way,
Ah Yu's email:zydn@meiyuan.net
Home: http://www.zydn.net/index.asp
qq:8692589



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.