Aspose.words Generating Reports

Source: Internet
Author: User

1. Introduction of Aspose.Words.dll


2.

A. Create a Word template and insert bookmarks where you want to read the data dynamically, bookmarks are not displayed by default and can be set to display in Word settings;



B. Single-line text can be set to replace field, case reference: Http://my.oschina.net/dancefires/blog/217858?fromerr=LCF2VyNJ



3. Inserting text in C # code

String tmppath = Server.MapPath ("~/test.docx");//Read template wordstring appimg = Server.MapPath ("~/admin/project/ajax/image/ "+ Datasettablename +"/appchart.png ");//Read the picture to be inserted datatable appdatetable = Getanalysisdata (Datasettablename," Appdate " , 15, "15", "Country", "line");//Obtain the analysis result data document DOC = new document (Tmppath); Load template Documentbuilder builder = new Documentbuilder (DOC);p Rinttablefmat (builder, appdatetable, appimg, "Ipcbu", Doc, 10 0);//Call Insert table and picture method string[] FieldNames = new string[] {"UserName", "Createtime"};//single-line text entry, which corresponds to the field set in the template <span style= " Color:rgb (51, 51, 51); font-family: ' Microsoft yahei ', Verdana, Sans-serif, song body; font-size:13px; letter-spacing:0.5px; line-height:22.5px; " >mergefield</span>object[] fieldvalues = new object[] {User.Identity.Name, DateTime.Now.ToShortDateString () };//defines the value of the input doc. Mailmerge.execute (FieldNames, fieldvalues); Execute the input doc. Save (datasettablename+ "report. Doc", Saveformat.doc, Savetype.openinword, Response);//Save and download

        <summary>////Print data to Word form///</summary>//<param name= "Builder" &GT;DOCU Mentbuilder builder = new Documentbuilder (DOC);</param>//<param name= "DT" > Data sheet </param>/ <param name= "img" > Inserted picture </param>//<param name= "Mark" >word label </param>//&lt ;p Aram Name= "Doc" >document doc = new Document (Tmppath); Loaded templates </param>///<param Name= "width" > cell width </param> public void Printtablefmat (DOCUMENTB Uilder Builder, DataTable DT, string img, string mark, Document doc,int width) {Builder. MoveToBookmark (Mark); Start adding value Builder.            Starttable (); Builder.            Rowformat.alignment = Rowalignment.center; Builder.            CellFormat.Borders.LineStyle = Linestyle.single; Builder.            CellFormat.Borders.Color = Color.Black; Builder.            Cellformat.verticalalignment = Cellverticalalignment.center; BuiLder.            ParagraphFormat.Alignment = Paragraphalignment.center; Builder.            Bold = true; for (var i = 0; i < dt. Columns.count; i++) {Builder.                InsertCell (); Builder.                Cellformat.width = Width; Builder. Write (dt. Columns[i].                Columnname.tostring ()); Builder.                Cellformat.verticalalignment = Cellverticalalignment.center; Builder.            ParagraphFormat.Alignment = Paragraphalignment.center; } builder.            Endrow (); Start adding values for (var i = 0; i < dt. Rows.Count; i++) {for (var j = 0; j < dt. Columns.count; J + +) {Builder. InsertCell ();//Add a cell builder.                    CellFormat.Borders.LineStyle = Linestyle.single; Builder.                    CellFormat.Borders.Color = System.Drawing.Color.Black; Builder.                    Cellformat.width = Width; Builder. CellformAt.                    Verticalmerge = Aspose.Words.Tables.CellMerge.None; Builder. cellformat.verticalalignment = cellverticalalignment.center;//Vertical Center alignment builder. ParagraphFormat.Alignment = paragraphalignment.center;//Horizontal Center aligns the builder. Write (dt. ROWS[I][J].                ToString ()); } builder.            Endrow (); } builder.            Writeln (""); Builder.            Writeln (""); Builder.            Writeln (""); Builder.            Insertimage (IMG, 450, 250); Doc. Range.bookmarks[mark]. Text = ""; Clear out the Mark}


Aspose.words Generating Reports

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.