private Image ConvertTableCellToImage(TableCell obj) { Document doc = new Document(); Section section = doc.AddSection(); Table table = section.AddTable(); table.AddRow().Cells.Add(obj.Clone()); Image image = doc.SaveToImages(0, ImageType.Bitmap); doc.Close(); return(CutImageWhitePart(image as Bitmap, 1)); }
private void CreateTable(int row, int column) { TableRow tableRow = new TableRow(); TableCell tableCell = new TableCell(); tableCell.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" })); tableCell.Append(new Paragraph(new Run(new Text()))); for (int i = 0; i < column; i++) { tableCell = (TableCell)tableCell.Clone(); tableRow.Append(tableCell); } for (int i = 0; i < row; i++) { tableRow = (TableRow)tableRow.Clone(); table.Append(tableRow); } }
private void button3_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; string curDir = System.IO.Directory.GetCurrentDirectory(); string шаблон = curDir + @"\Платежи7улицы.docx"; if (!System.IO.File.Exists(шаблон.ToString())) { MessageBox.Show("Нет файла " + шаблон.ToString()); Cursor = Cursors.Default; return; } try { var template = new System.IO.FileInfo(шаблон); string tempFile = curDir + @"\temp\temp.docx"; клTemp.закрытьWord(); template.CopyTo(tempFile, true); string наименФилиала = de.филиалы .OrderBy(n => n.порядок) .First().наимен; using (WordprocessingDocument package = WordprocessingDocument.Open(tempFile, true)) { var tables = package.MainDocumentPart.Document.Body.Elements <Table>(); Table table1 = tables.First(); Table table2 = tables.Last(); клXML.ChangeTextInCell(table1, 0, 1, клУслуга.наимен); клXML.ChangeTextInCell(table1, 1, 1, клУлица.наимен); клXML.ChangeTextInCell(table1, 2, 1, наименФилиала); клXML.ChangeTextInCell(table1, 2, 2, DateTime.Today.ToShortDateString()); TableRow firstRow = table2.Elements <TableRow>().First(); TableRow lastRow = table2.Elements <TableRow>().Last(); TableCell lastCell0 = firstRow.Elements <TableCell>().Last(); TableCell lastCell = lastRow.Elements <TableCell>().Last(); int домов = архив.Columns.Count - 1; for (int k = 0; k < домов - 1; k++) { TableCell newCell0 = lastCell0.Clone() as TableCell; firstRow.AppendChild <TableCell>(newCell0); TableCell newCell = lastCell.Clone() as TableCell; lastRow.AppendChild <TableCell>(newCell); } for (int k = 1; k <= домов; k++) { клXML.ChangeTextInCell(table2, 0, k, архив.Columns[k].Caption); } lastRow = table2.Elements <TableRow>().Last(); int квартир = архив.Rows.Count; for (int i = 1; i < квартир; i++) { TableRow newRow = lastRow.Clone() as TableRow; table2.AppendChild(newRow); } int j = 0; foreach (DataRow uRow in архив.Rows) { j++; клXML.ChangeTextInCell(table2, j, 0, uRow.Field <int>("квартира").ToString()); int r = 0; foreach (DataColumn nCol in архив.Columns) { r++; if (r > 1) { клXML.ChangeTextInCell(table2, j, r - 1, uRow.Field <string>(r - 1).ToString()); } } } } Cursor = Cursors.Default; клXML.просмотрWord(tempFile); } catch (Exception ex) { MessageBox.Show($"Ошибка {ex.Message}"); } }
private static Table smethod_3(Class857 A_0, Class106 A_1, Class975 A_2) { int num = 0; Table table = new Table(A_0.method_9()); int num2 = smethod_4(A_0, A_1, A_2); foreach (Class571 class4 in A_2) { TableCell cell = new TableCell(A_0.method_9()); TableRow lastRow = null; if (table.FirstRow != null) { lastRow = table.LastRow; cell = (TableCell)Class681.smethod_15(lastRow.FirstChild); } table.method_13(new TableRow(A_0.method_9(), class4.method_2())); for (int i = 0; i < class4.Count; i++) { Class1140 class3 = class4.method_0(i); if (class3.method_8() == null) { class3.method_9((TableCell)cell.Clone()); if ((class3.method_4() == CellMerge.Continue) && (i != 0)) { class3.method_8().CellFormat.PreferredWidth.method_50(0f); class3.method_8().CellFormat.PreferredWidth.method_52(FtsWidth.Point); } if (((class3.method_6() == CellMerge.Continue) && (lastRow != null)) && (lastRow.Cells[i] != null)) { class3.method_8().CellFormat.PreferredWidth.method_50(((float)A_1.method_20().method_1(i).method_12()) / 20f); class3.method_8().CellFormat.PreferredWidth.method_52(FtsWidth.Point); } } else if (class3.method_4() != CellMerge.Continue) { int num6 = 0; for (int k = 0; k < class3.method_0(); k++) { if ((A_1 != null) && ((i + k) < A_1.method_20().Count)) { Class94 class2 = A_1.method_20().method_1(i + k); if (class2 != null) { num6 += (class2.method_12() == -2147483648) ? num2 : class2.method_12(); } } } class3.method_8().CellFormat.PreferredWidth.method_50(((float)num6) / 20f); class3.method_8().CellFormat.PreferredWidth.method_52(FtsWidth.Point); } class3.method_8().CellFormat.HorizontalMerge = class3.method_4(); class3.method_8().CellFormat.VerticalMerge = class3.method_6(); table.LastRow.Cells.Add(class3.method_8()); cell = class3.method_8(); } if ((class4.method_0(0).method_6() == CellMerge.Continue) && (lastRow != null)) { table.LastRow.RowFormat.LeftIndent = lastRow.RowFormat.LeftIndent; } for (int j = 1; j < class4.method_4(); j++) { table.method_13(table.LastRow); } } if (A_1 != null) { string str = A_1.method_12(); if (str != null) { if (!(str == BookmarkStart.b("吥䐧ܩ堫䰭", num))) { if (str == BookmarkStart.b("䨥娧ܩ堫䰭", num)) { table.TableFormat.Bidi = false; } } else { table.TableFormat.Bidi = true; } } table.DocxTableFormat.Format.HorizontalAlignment = (RowAlignment)A_1.method_14(); } if ((A_1 != null) && (A_1.method_16() != -2147483648)) { table.PreferredWidth = new PreferredWidth(WidthType.Twip, (short)A_1.method_16()); } return(table); }