Use Aspose. Cells to export Excel (C #) using a template #),

Source: Internet
Author: User

Use Aspose. Cells to export Excel (C #) using a template #),
Preface

With the popularity of the Internet, web projects gradually become the mainstream. I believe that most developers write the upload and export functions of Excel and Word in their development projects. This article only discusses exporting Excel. C # many third-party components support exporting Excel files, such as npoi?aspose.cellsand spire.xls. Here we use Aspose. Cells and the templates we have written.

I. Prepare a database

I created a very simple table and added some data. Structure:

 

Ii. Create an Excel template

Create an excel file, the first row title, and the second row add content. The second row is in the format of & = [data source table name]. Column name. The "data source table name" is the name of the DataTable returned by the background, and the "column name" is the name of the corresponding title column in the database. The details are as follows:

Iii. How to export an Excel file in the background

The Code is as follows:

Then, write a method in the Controller and call ExportExcel. This method is called by frontend js.

4. Call in view

Use js to call methods in the Controller. Be sure not to use ajax. Only window. location. href can be used.

 

V. Implementation results

Click "Export" on the page to bring up the file storage dialog box. The effect is as follows:

Open Excel and check the content:

The data in the database table is filled in Excel. Achieve the desired effect.

Vi. Conclusion

This sharing ends now. If this article is helpful to you, please comment or recommend it!

Project Source: https://github.com/liuyang-1990/ExportDemo

Author: NaYoung
Source: http://www.cnblogs.com/liuyoung/p/7736811.html
You are welcome to repost it, but you must keep the complete article for any repost. The original Article and the original article link are displayed in the prominent area. If you have any questions or authorization negotiation, please leave a message for me

 

Related Article

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.