转载:https://www.cnblogs.com/echo-web/p/9511119.html //检定原始记录——补偿器 public void CreatTable_Compensator( string path) { string realpath = @path + "\\补偿器.docx" ; try { if (File.Exists(realpath)) { //若存在则删除 File.Delete(realpath); } //File.Create(realpath).Close(); //创建表格 using ( var document = DocX.Create(realpath)) { var title = document.InsertParagraph().Append( "补偿器检定记录" ).Bold().FontSize(20); title.Alignment = Alignment.center; var table = document.AddTable(24, 6); table.Design = TableDesign.TableGrid; /*table.AutoFit = AutoFit.Window;*/ table.Alignment = Alignment.center; List<Row> rows = table.Rows; Row row0 = rows[0]; row0.Height = 50; row0.MergeCells(0, 2); row0.Cells[0].Paragraphs[0].Append( "设备ID:" + "18635445" ).FontSize(16).Font( new FontFamily( "Arial" )).Bold().Alignment = Alignment.center; row0.Cells[0].VerticalAlignment = VerticalAlignment.Center; row0.MergeCells(1, 3); row0.Cells[1].Paragraphs[0].Append( "仪器编号:" + "FH5919" ).FontSize(16).Font( new FontFamily( "Arial" )).Bold().Alignment = Alignment.center; row0.Cells[1].VerticalAlignment = VerticalAlignment.Center; //第二行 Row row1 = rows[1]; row1.MergeCells(0, 5); row1.Cells[0].Paragraphs[0].Append( "补偿范围检定记录" ).Bold().FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row1.Height = 60; row1.Cells[0].VerticalAlignment = VerticalAlignment.Center; //第三行 Row row2 = rows[2]; row2.MergeCells(0, 1); row2.Cells[0].Paragraphs[0].Append( "次序" ).FontSize(11).Font( new FontFamily( "等线" )).Alignment = Alignment.center; row2.MergeCells(1, 4); row2.Cells[1].Paragraphs[0].Append( "观测值显示" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; //第四行 Row row3 = rows[3]; row3.MergeCells(0, 1); row3.Cells[0].Paragraphs[0].Append( "1" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row3.MergeCells(1, 4); row3.Cells[1].Paragraphs[0].Append( "3.[1]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row3.Height = 35; row3.Cells[0].VerticalAlignment = VerticalAlignment.Center; row3.Cells[1].VerticalAlignment = VerticalAlignment.Center; //第五行 Row row4 = rows[4]; row4.MergeCells(0, 1); row4.Cells[0].Paragraphs[0].Append( "2" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row4.MergeCells(1, 4); row4.Cells[1].Paragraphs[0].Append( "4.[1]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row4.Height = 35; row4.Cells[0].VerticalAlignment = VerticalAlignment.Center; row4.Cells[1].VerticalAlignment = VerticalAlignment.Center; //第六行 Row row5 = rows[5]; row5.MergeCells(0, 1); row5.Cells[0].Paragraphs[0].Append( "计算结果" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; ; row5.MergeCells(1, 4); row5.Cells[1].Paragraphs[0].Append( "5.[1]" ).FontSize(11).Font( new FontFamily( "Arial" )); row5.Height = 35; row5.Cells[0].VerticalAlignment = VerticalAlignment.Center; row5.Cells[1].VerticalAlignment = VerticalAlignment.Center; //第七行 Row row6 = rows[6]; row6.MergeCells(0, 5); row6.Cells[0].Paragraphs[0].Append( "补偿器零位误差检定记录" ).FontSize(11).Font( new FontFamily( "Arial" )).Bold().Alignment = Alignment.center; row6.Height = 60; row6.Cells[0].VerticalAlignment = VerticalAlignment.Center; //第八行 Row row7 = rows[7]; row7.MergeCells(0, 1); row7.Cells[0].Paragraphs[0].Append( "次序" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row7.Cells[1].Paragraphs[0].Append( "方向" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row7.Cells[2].Paragraphs[0].Append( "Ⅰ" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row7.Cells[3].Paragraphs[0].Append( "Ⅱ" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row7.Cells[4].Paragraphs[0].Append( "平均" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; //第九行 Row row8 = rows[8]; row8.MergeCells(0, 1); //.InsertParagraph() row8.Cells[1].Paragraphs[0].Append( "XL" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row8.Cells[2].Paragraphs[0].Append( "8.[2]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row8.Cells[3].Paragraphs[0].Append( "8.[3]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row8.Height = 30; row8.Cells[1].VerticalAlignment = VerticalAlignment.Center; row8.Cells[2].VerticalAlignment = VerticalAlignment.Center; row8.Cells[3].VerticalAlignment = VerticalAlignment.Center; row8.Cells[0].Paragraphs[0].Append( "1" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row8.Cells[4].Paragraphs[0].Append( "8.4" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row8.Cells[0].VerticalAlignment = VerticalAlignment.Center; row8.Cells[4].VerticalAlignment = VerticalAlignment.Center; //第十行 Row row9 = rows[9]; row9.MergeCells(0, 1); table.MergeCellsInColumn(0, 8, 9); //列合并 table.MergeCellsInColumn(4, 8, 9); //列合并 row9.Cells[1].Paragraphs[0].Append( "YL" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row9.Cells[2].Paragraphs[0].Append( "9.[2]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row9.Cells[3].Paragraphs[0].Append( "9.[3]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row9.Height = 30; row9.Cells[1].VerticalAlignment = VerticalAlignment.Center; row9.Cells[2].VerticalAlignment = VerticalAlignment.Center; row9.Cells[3].VerticalAlignment = VerticalAlignment.Center; //第十一行 Row row10 = rows[10]; row10.MergeCells(0, 1); row10.Cells[1].Paragraphs[0].Append( "XL" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row10.Cells[2].Paragraphs[0].Append( "10.[2]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row10.Cells[3].Paragraphs[0].Append( "10.[3]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row10.Height = 30; row10.Cells[1].VerticalAlignment = VerticalAlignment.Center; row10.Cells[2].VerticalAlignment = VerticalAlignment.Center; row10.Cells[3].VerticalAlignment = VerticalAlignment.Center; row10.Cells[0].Paragraphs[0].Append( "2" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row10.Cells[4].Paragraphs[0].Append( "10.4" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row10.Cells[0].VerticalAlignment = VerticalAlignment.Center; row10.Cells[4].VerticalAlignment = VerticalAlignment.Center; //第十二行 Row row11 = rows[11]; row11.MergeCells(0, 1); table.MergeCellsInColumn(0, 10, 11); //第11和12列的第1行合并 table.MergeCellsInColumn(4, 10, 11); //第11和12列的第4行合并 row11.Cells[1].Paragraphs[0].Append( "YL" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row11.Cells[2].Paragraphs[0].Append( "11.[2]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row11.Cells[3].Paragraphs[0].Append( "11.[3]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row11.Height = 30; row11.Cells[1].VerticalAlignment = VerticalAlignment.Center; row11.Cells[2].VerticalAlignment = VerticalAlignment.Center; row11.Cells[3].VerticalAlignment = VerticalAlignment.Center; //第十三行 Row row12 = rows[12]; row12.MergeCells(0, 1); row12.Cells[0].Paragraphs[0].Append( "计算结果" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row12.MergeCells(1, 4); row12.Cells[1].Paragraphs[0].Append( "12.[1]" ).FontSize(11).Font( new FontFamily( "Arial" )); row12.Cells[0].VerticalAlignment = VerticalAlignment.Center; row12.Cells[1].VerticalAlignment = VerticalAlignment.Center; row12.Height = 35; //第十四行 Row row13 = rows[13]; row13.MergeCells(0, 5); row13.Cells[0].Paragraphs[0].Append( "倾斜补偿器误差检定记录" ).FontSize(11).Font( new FontFamily( "Arial" )).Bold().Alignment = Alignment.center; row13.Height = 60; row13.Cells[0].VerticalAlignment = VerticalAlignment.Center; //第十五行 Row row14 = rows[14]; row14.MergeCells(0, 1); row14.Cells[0].Paragraphs[0].Append( "补偿" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row14.Cells[1].Paragraphs[0].Append( "Ⅰ" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row14.Cells[2].Paragraphs[0].Append( "Ⅱ" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row14.Cells[3].Paragraphs[0].Append( "III" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row14.Cells[4].Paragraphs[0].Append( "平均" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row14.Cells[0].VerticalAlignment = VerticalAlignment.Center; row14.Cells[1].VerticalAlignment = VerticalAlignment.Center; row14.Cells[2].VerticalAlignment = VerticalAlignment.Center; row14.Cells[3].VerticalAlignment = VerticalAlignment.Center; row14.Cells[4].VerticalAlignment = VerticalAlignment.Center; //第十六行 Row row15 = rows[15]; row15.Cells[0].Width = 30f; row15.Cells[0].Paragraphs[0].Append( "竖" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row15.Cells[0].InsertParagraph().Append( "直" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row15.Cells[0].InsertParagraph().Append( "角" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row15.Cells[0].VerticalAlignment = VerticalAlignment.Center; row15.Cells[1].Paragraphs[0].Append( "M1(水平)" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row15.Cells[2].Paragraphs[0].Append( "15.[1]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row15.Cells[3].Paragraphs[0].Append( "15.[2]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row15.Cells[4].Paragraphs[0].Append( "15.[3]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row15.Cells[5].Paragraphs[0].Append( "15.[4]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; //第十七行 Row row16 = rows[16]; row16.Cells[1].Paragraphs[0].Append( "M2(上倾)" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row16.Cells[2].Paragraphs[0].Append( "16.[1]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row16.Cells[3].Paragraphs[0].Append( "16.[2]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row16.Cells[4].Paragraphs[0].Append( "16.[3]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row16.Cells[5].Paragraphs[0].Append( "16.[4]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; //第十八行 Row row17 = rows[17]; table.Rows.RemoveRange(3, 2); row17.Cells[1].Paragraphs[0].Append( "M3(下倾)" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row17.Cells[2].Paragraphs[0].Append( "17.[1]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row17.Cells[3].Paragraphs[0].Append( "17.[2]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row17.Cells[4].Paragraphs[0].Append( "17.[3]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row17.Cells[5].Paragraphs[0].Append( "17.[4]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; //第十九行 Row row18 = rows[18]; table.MergeCellsInColumn(0, 15, 18); //列合并 row18.Cells[1].Paragraphs[0].Append( "M4(再水平)" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row18.Cells[2].Paragraphs[0].Append( "18.[1]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row18.Cells[3].Paragraphs[0].Append( "18.[2]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row18.Cells[4].Paragraphs[0].Append( "18.[3]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row18.Cells[5].Paragraphs[0].Append( "18.[4]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; //第二十行 Row row19 = rows[19]; row19.Cells[0].Width = 30f; row19.Cells[0].Paragraphs[0].Append( "水" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row19.Cells[0].InsertParagraph().Append( "平" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row19.Cells[0].InsertParagraph().Append( "角" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row19.Cells[0].VerticalAlignment = VerticalAlignment.Center; row19.Cells[1].Paragraphs[0].Append( "N1(水平)" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row19.Cells[2].Paragraphs[0].Append( "19.[1]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row19.Cells[3].Paragraphs[0].Append( "19.[2]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row19.Cells[4].Paragraphs[0].Append( "19.[3]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row19.Cells[5].Paragraphs[0].Append( "19.[4]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; //第二十一行 Row row20 = rows[20]; row20.Cells[1].Paragraphs[0].Append( "N3(下倾)" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row20.Cells[2].Paragraphs[0].Append( "20.[1]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row20.Cells[3].Paragraphs[0].Append( "20.[2]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row20.Cells[4].Paragraphs[0].Append( "20.[3]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row20.Cells[5].Paragraphs[0].Append( "20.[4]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; //第二十二行 Row row21 = rows[21]; row21.Cells[1].Paragraphs[0].Append( "N3(下倾)" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row21.Cells[2].Paragraphs[0].Append( "21.[1]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row21.Cells[3].Paragraphs[0].Append( "21.[2]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row21.Cells[4].Paragraphs[0].Append( "21.[1]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row21.Cells[5].Paragraphs[0].Append( "21.[4]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; //第二十三行 Row row22 = rows[22]; table.MergeCellsInColumn(0, 19, 22); //列合并 row22.Cells[1].Paragraphs[0].Append( "N4(再水平)" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row22.Cells[2].Paragraphs[0].Append( "22.[1]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row22.Cells[3].Paragraphs[0].Append( "22.[2]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row22.Cells[4].Paragraphs[0].Append( "22.[3]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row22.Cells[5].Paragraphs[0].Append( "22.[4]" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; //第二十四行 Row row23 = rows[23]; row23.MergeCells(0, 1); row23.Cells[0].Paragraphs[0].Append( "计算结果" ).FontSize(11).Font( new FontFamily( "Arial" )).Alignment = Alignment.center; row23.MergeCells(1, 4); row23.Cells[1].Paragraphs[0].Append( "row23.Cells[1]" ).FontSize(11).Font( new FontFamily( "Arial" )); row23.Cells[0].VerticalAlignment = VerticalAlignment.Center; row23.Cells[1].VerticalAlignment = VerticalAlignment.Center; row23.Height = 35; var p1 = document.InsertParagraph(); p1.InsertTableAfterSelf(table); // 保存当前文档 document.Save(); //结果信息输出 } } catch (Exception ex) { Console.WriteLine(ex.Message); } } |