Output page information to excel

Source: Internet
Author: User

Http://blog.csdn.net/mengKzhaoyun/archive/2010/05/06/5564013.aspx

To output page information to excel, Silverlight APIs cannot allow customers to directly access excel. Therefore, a powerful WebService is used to output excel. After mengk traveled through the network, it found that there are four methods for. Net operations (read/write) Excel:

 

A. Use third-party controls

Third-party controls are charged and free of charge.ProgramThanks to the efforts of our staff, we now have satisfactory free controls.

 

B. Call the official COM Component

The official COM component is very powerful and can be used to create exquisite Excel files. However, there are also some disadvantages:

B1. process exclusive: to operate an Excel file, you need to open a process.

B2. difficult to release normally: when using this kind of supervisor to operate excelit, this question should be answered. excelapp.quit(later, excel.exe still exists, which is extremely serious.

 

C. Use oledb

When Excel is used as a database, we can perform select, update, and insert operations (Note: delete cannot be executed ), when writing data, you can create an exquisite template in advance to compensate for its functional shortcomings.

 

D. use ASP. NET

In this example, you can use the rendercontrol (htmltextwrite write) of the DataGrid to output an Excel file with only other blank tables, in essence, this Excel file is only a special HTML file that changes the suffix to the suffix of the Excel file and then displays it in the Excel file. You need to save it in order to convert it into a real Excel file.

Newbie operations are prone to garbled code. This solution is to pay attention to encoding, not justCodeAnd pay attention to the configuration in global webconfig.

 

Simple comparison

Method
Memory usage
Speed
Concurrency Endurance
Beautiful
 
A
Average
Second stream
B
US-
 
B
Very
Downstream
C
US ++
 
C
Average
Tri-stream
A
Us
 
D
Average
First Class
S
Beauty --
 

 

Mengk only uses methods B and D. Some people say that method B can start a unique instance com process, sending Requests to the com process can solve the problem of slow startup of COM, which can be well handled by concurrency. I personally think the security of such a process is extremely complicated. You can try it.

 

Mengk encountered problems:

1. When the COM component is used, the quit method is called, so that excelapp = null, there is still no way to release excel.exe.

This problem occurs when the program fails to release all referenced COM objects. Generally, exceptions are not handled. Note the workbook here. before saving, refresh the updated content in time. Then, check all the changed but unsaved workbooks to save them one by one. Finally, call system. runtime. interopservices. marshal. the releasecomobject () method releases objects such as range, sheet, book, and app.

2. garbled characters are generated when an Excel file is output to the client.

Note that the configuration in the program is consistent with that in webconfig.

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/mengKzhaoyun/archive/2010/05/06/5564013.aspx

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.