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.