This article to share is a use of Aspose.word Third-party plug-in implementation of the example of Word, very practical, the need for small partners can refer to.
Using a Aspose.word Third-party plug-in to implement the server-side function of exporting Word without installing Office components
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107-108 |
#region the generated Excel file name and ensure the uniqueness of the file Random Rd = new Random (); DateTime dtime = DateTime.Now; String Filename = "Training Requirement table" + Dtime. Year.tostring () + dtime. Month.tostring () + dtime. Day.tostring () + dtime. Hour.tostring () + dtime. Minute.tostring () + dtime. Second.tostring () + convert.tostring (Rd. Next () * + +) + ". Doc"; #endregion #region Define variables//Create document objects that invoke the module to set the Word Font and table format string serverpath = Constants.getappsettingvalue (" Locallogicpath ") + Constants.getappsettingvalue (" localtemplate ") +" Px_xqjh_tx.doc "; Document doc = new document (Serverpath); Establish Documentbuilder object Documentbuilder builder = new Documentbuilder (DOC); #endregion #region page settings, set the page to landscape layout, set the paper type to A4 paper or set the paper layout builder by the width of the page. Pagesetup.papersize = papersize.a4; Builder. Pagesetup.orientation = Aspose.Words.Orientation.Landscape; #endregion #region Set Word global font style and font size builder. RowFormat.Borders.LineStyle = Linestyle.thick; Builder. Rowformat.heightrule = Heightrule.auto; Builder. Rowformat.alignment = RowaLignment. Center; Builder. Font.Name = "Imitation-gb2312"; Builder. Font.Name = "Song Body"; Builder. Font.Size = 10.5; Number Fifth #endregion list<double> widthlist = new list<double> (); Double remarkwidth = 0; for (int k = 0; k < k++) {Builder. Movetocell (0, 1, k, 0); Move cell double width = builder. cellformat.width;//gets the cell width widthlist.add (width); Remarkwidth + = width; //universal.exceptionlog (k.tostring (), width. ToString ()); } DataTable dtable = Getquestionlist (); if (dtable!= null && dtable. Rows.Count > 0) {#region Draw the table and set the---------start Doc. range.bookmarks["TBDW"]. Text = This.lblcom.Text; Builder. MoveToBookmark ("Pxtx"); Start adding value Aspose.Words.Tables.Table Table = Builder. Starttable (); Builder. Rowformat.headingformat = true; Builder. ParagraphFormat.Alignment = Paragraphalignment.center; #endregion #region Data set for (int i = 0; i < dtable. Rows.Count; i++) {for (int j = 0; J < dtable. columns.count-3; J + +) {#region column builder. Insertcell ();//Add a cells builder. CellFormat.Borders.LineStyle = Linestyle.single; Builder. CellFormat.Borders.Color = System.Drawing.Color.Black; Builder. CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb (255, 255, 255); Builder. Cellformat.width = Widthlist[j]; Builder. Cellformat.verticalmerge = Aspose.Words.Tables.CellMerge.None; Builder. Cellformat.verticalalignment = cellverticalalignment.top;//vertically Align Builder. ParagraphFormat.Alignment = paragraphalignment.left;//horizontally centered builder. Write (dtable. ROWS[I][J]. ToString (). Trim ()); //universal.exceptionlog ((i + 1). ToString () + "*" + (j + 1). ToString (), dtable. ROWS[I][J]. ToString (). Trim ()); #endregion} Builder. Endrow (); } #endregion #region Memo column builder. InsertCell ()//Add a cell builder. CellFormat.Borders.LineStyle = Linestyle.single; Builder. CellFormat.Borders.Color = System.Drawing.Color.Black; Builder. CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb (255, 255, 255); Builder. CellfOrmat. Width = Remarkwidth; Builder. Rowformat.height = 50; Builder. Cellformat.verticalmerge = Aspose.Words.Tables.CellMerge.None; Builder. Cellformat.verticalalignment = cellverticalalignment.top;//vertically Align Builder. ParagraphFormat.Alignment = paragraphalignment.left;//horizontally centered builder. Write ("remark:"); Builder. Endrow (); #endregion #region Draw the table and set the end of the---------builder. Endtable (); Doc. range.bookmarks["Pxtx"]. Text = ""; Clear out the Mark #endregion #region planning and approving person doc. range.bookmarks["Writername"]. Text = dtable. rows[0]["Reg_staff_name"]. ToString (); Doc. range.bookmarks["CheckName"]. Text = dtable. rows[0]["Check_man_name"]. ToString (); #endregion} dtable. Dispose (); #region save data. Doc. Save (Filename, Saveformat.doc, Savetype.openinword, Response); Save As Doc and open the #endregion |