Asp.net Import and Export Excel Summary

Source: Internet
Author: User
So far, I have written four articles about how to import and export Excel files. Article It is a step by step. Let's summarize it.
I have used four methods in total. Now I will comment on the advantages and disadvantages of each method:

1. Use the MSSQL xp_export shell command to export Excel
Advantages: Convenient and straightforward. You can use a simple SQL statement. For details, refer to the blog article xp_export shell to export excel.
Disadvantages: ① xp_cmdshell must be enabled in the MSSQL peripheral application configurator (of course, it can also be enabled using SQL statements)
② It is difficult to export files to the client. You need to first cache the exported files to the server and then read the cached files and download them to the client (it seems like this is the case, but I don't quite remember it)
③ The exported Excel file is not a real one. It can be read in the MSSQL query analyzer during import, and can be read using ado.net, but oledb cannot.

2. Use the stored procedure created by volume to export the Excel
Advantage: it is convenient and direct, and the stored procedure is ready-made. You only need to replace the table name. The most important thing is to export the true Excel file. For details, refer to another blog article on SQL export/import to excel.
Disadvantages: ① the same as the first method and the second method.
② Only excel of version 2000 is supported, but Excel of Version 2003 to version 2007 is not supported (If SQL is strong, write it by yourself)

3. Direct output using response
Advantage: it is convenient, and there is no compatibility problem. This method can be directly provided for download from the client. For details, refer to the blog article datatable Import and Export excel.
Disadvantages: ① the same as the third disadvantage of the first method
② Rewrite verifyrenderinginserverform (Control ){}

4. Use the COM component to export an Excel file
Advantage: to export to a real Excel file, you do not have to re-verifyrenderinginserverform. For details, refer to another blog article com to create and export an Excel file.
Disadvantages: ① There is a compatibility problem. Excel 2003 corresponds to com 11.0, and 07 corresponds to 12.0.
② Same as the second disadvantage of the first method
③CodeComplex and difficult to understand
④ The memory usage is large and the process is not easy to kill

Conclusion: In general, the above methods all have disadvantages over the advantages (-_-! (Personal opinion) after several nights of research, we finally imported and exported the Excel files in the fourth way, but the efficiency was relatively low. We hope that people can provide better solutions...

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.