Data output to the Word file or Excel file

zhaozj2021-02-16  43

There is often a case where you want to read the content in the database and generate an Excel file or a Word file. I will talk about my handling method and thinking. Improper, please expert

There is a simpler way: that is the front plus: response.contenttype = "Application / Msexcel" and then use Excel to open. However, this method will have a lot of blame, for example, some machines are open, some The machine is not good, the different Office version may not work, it is also possible to open a blank page, etc...

Second method: Through the experiment, we found that change an HTML form extension to XLS, double click, the computer actually uses Excel to open, take a closer look, the image is like the image, that is, if the excel of different versions To open. Possible form line is gone. Ok, this is good, the content in our database reads, generates a table in an HTML format, and write this form into an extension of XLS. Then, turn to this XLS file, almost very much. However, there will be three problems: 1. Sometimes open might be blank, 2. That is illegal, leave an Excel process. 3. Table line is gone The solution to these three issues is as follows: The first question: After generating this temporary XLS file, do not immediately turn to it, turn it back in a second, then turn again. The second question and the third question: I am in Excel Make a table, then save it as an HTML format, will find that if you turn to this file, the format is not wrong, there is no illegal operation prompt, and there is no more process. Then open this HTM file to see his code. Discover more than one large pile of code in front, there are more code after each in the form. Ok. We will also paint the gourd in the future, and use this format to generate a file that extends XLS (actually a HTML file). ).

The above is the method I use, please talk about your own way, I hope to get better ways, Amia's Email: zydn@meiyuan.net home: http://www.zydn.net/index.asp QQ: 8692589

转载请注明原文地址:https://www.9cbs.com/read-26123.html

New Post(0)