# Name the excel file generated by region and ensure the uniqueness of the file Random rd = new Random (); DateTime dtime = DateTime. Now; String Filename = "training demand table" + dtime. year. toString () + dtime. month. toString () + dtime. day. toString () + dtime. hour. toString () + dtime. minute. toString () + dtime. second. toString () + Convert. toString (rd. next (99) * 97 + 100) + ". doc "; # Endregion # Region defines Variables // Create a Document Object and call 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 ); // Create a DocumentBuilder object DocumentBuilder builder = new DocumentBuilder (doc ); # Endregion # Region page settings: Set the page to horizontal layout, set the paper type to A4 paper, or set the page width // Set the paper Layout Builder. PageSetup. PaperSize = PaperSize. A4; // Builder. PageSetup. Orientation = Aspose. Words. Orientation. Landscape; # Endregion # Region: set the global font style and font size of word Builder. RowFormat. Borders. LineStyle = LineStyle. Thick; Builder. RowFormat. HeightRule = HeightRule. Auto; Builder. RowFormat. Alignment = RowAlignment. Center; // Builder. Font. Name = "-GB2312 "; Builder. Font. Name = ""; Builder. Font. Size = 10.5; // 5 # Endregion List <double> widthList = new List <double> (); Double remarkWidth = 0; For (int k = 0; k <18; k ++) { Builder. MoveToCell (0, 1, k, 0); // move the cell Double width = builder. CellFormat. Width; // obtain 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 a table and set it to start --------- Doc. Range. Bookmarks ["tbdw"]. Text = this. lblcom. Text; Builder. MoveToBookmark ("pxtx"); // start adding a value Aspose. Words. Tables. Table table = builder. StartTable (); Builder. RowFormat. HeadingFormat = true; Builder. ParagraphFormat. Alignment = ParagraphAlignment. Center; # Endregion # Region Dataset 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 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 = widthList [j]; Builder. CellFormat. VerticalMerge = Aspose. Words. Tables. CellMerge. None; Builder. CellFormat. VerticalAlignment = CellVerticalAlignment. Top; // vertical center alignment Builder. ParagraphFormat. Alignment = ParagraphAlignment. Left; // align horizontally Builder. Write (dtable. Rows [I] [j]. ToString (). Trim ()); // Universal. predictionlog (I + 1 ). toString () + "*" + (j + 1 ). toString (), dtable. rows [I] [j]. toString (). trim ()); # Endregion } Builder. EndRow (); } # Endregion # Region remarks 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; // vertical center alignment Builder. ParagraphFormat. Alignment = ParagraphAlignment. Left; // align horizontally Builder. Write ("Remarks :"); Builder. EndRow (); # Endregion # Region draw a table and set the end --------- Builder. EndTable (); Doc. Range. Bookmarks ["pxtx"]. Text = ""; // clear the mark # Endregion # Region scheduler preparation and approver 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 it as doc and open # Endregion |