C # Build Word document (Npoi)

Source: Internet
Author: User

Using Npoi. XWPF. Usermodel
1 xwpfdocument doc = new xwpfdocument (); Create a new Word document 2 3 xwpfparagraph p1 = doc. Createparagraph (); Add paragraph 4 p1 to the new document. Setalignment (Paragraphalignment.center); The paragraph is centered on its way 5 6 xwpfrun r1 = p1. Createrun (); Add text 7 r1 to the paragraph. SetText ("test paragraph One"); 8 9 Xwpfparagraph p2 = doc. Createparagraph (); ten P2. Setalignment (paragraphalignment.left); Xwpfrun r2 = p2. Createrun (); R2. SetText ("Test paragraph II"); R2. Setfontsize (16);//Set Font size
R2. Setblod (TRUE);//Set Bold
FileStream SW = file.create ("Cutput.docx"); //... Doc. Write (SW); //... SW. Close (); Generate files on the server FileInfo file = new FileInfo ("Cutput.docx");//File save path and name 21 Note: The parent folder where the file is saved needs to be added to the Everyone user and given full control privileges of response.clear (); Response.ClearHeaders (); 24 Response.Buffer = false;25 Response.ContentType = "Application/octet-stream"; response.appendheader ("Content-disposition", "attachment;filename=" + httputility.urlencode ("Output.docx", System.Text.Encoding. UTF8)); Response.appendheader ("Content-length", file. Length.tostring ()); Response.WriteFile (file. FullName); Response.Flush (); The above will generate the word file sent to the user browser file.delete ("Cutput.docx");

  

C # Build Word document (Npoi)

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.