ASP. NET simple ooxml export Excel, Word

Source: Internet
Author: User

1) Introduction

Simple ooxml (Http://simpleooxml.codeplex.com/) isOpen Office SDK V2.0,It also supports open-source libraries exported from office2007 Excel and Word. Supports. Net 3.5 and later versions. Excel supports a variety of data formats, including strings, numbers, and dates. It supports deleting workbooks, pasting datatable, merging cells, and setting cell styles. Word supports the ability to output fields through bookmarks.

: Local download

2) Export Excel

         Protected   Void Button#click ( Object  Sender, eventargs e) {memorystream stream = Spreadsheetreader. Create (); spreadsheetdocument Doc = Spreadsheetdocument. Open (stream, True ); Worksheetpart = Spreadsheetreader. getworksheetpartbyname (Doc, "  Sheet1  "  ); Worksheetwriter writer = New  Worksheetwriter (Doc, worksheetpart); writer. pastetext (  "  B2  " , "  Hello World  " );  //  Save to the memory stream  Spreadsheetwriter. Save (DOC );  //  Write to response stream  Response. Clear (); response. addheader (  "  Content-Disposition  " , String. Format ( "  Attachment; filename = {0}  " ,"  Example1.xlsx  "  ); Response. contenttype = "  Application/vnd. openxmlformats-officedocument.spreadsheetml.sheet  "  ; Stream. writeto (response. outputstream); response. End ();} 

If you export an existing Excel template, you can

 
Memorystream stream = spreadsheetreader. Create ();

Change

 
Memorystream stream = spreadsheetreader.copy(“columnstemplate.xlsx");

3) Export word

        Public   Void  Documentpastetest () {memorystream stream = Documentreader. Copy ( String . Format ( "  {0} \ template.docx  "  , Testcontext. testdeploymentdir); wordprocessingdocument Doc = Wordprocessingdocument. Open (stream, True  ); Maindocumentpart mainpart = Doc. maindocumentpart; documentwriter writer =New  Documentwriter (mainpart); text name = Writer. pastetext ( "  Koos van der Merwe  " , "  Name  "  ); Text age = Writer. pastetext ( "  53  " , "  Age  " );  //  Save to the memory stream, and then to a file  Writer. Save (); documentwriter. streamtofile (  String . Format ( "  {0} \ templatetest.docx  "  , Getoutputfolder (), stream );} 

You can use the word bookmarks function to locate and paste text.

 

 

4) Conclusion

Simple ooxml is a very comprehensive and easy-to-use Excel and Word export solution. The only bad art is that it does not support export of Office 2003, and it is helpful for. net export data.

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.