internal void ApplyTableProperties(Table table, DocxNode node) { TableProperties tableProp = new TableProperties(); TableStyle tableStyle = new TableStyle() { Val = DocxTableProperties.tableGridName }; tableProp.Append(tableStyle); DocxTableStyle style = new DocxTableStyle(); style.Process(tableProp, this, node); table.AppendChild(tableProp); int count = GetTdCount(node); rowSpanInfo = new Dictionary <int, int>(); if (count > 0) { TableGrid tg = new TableGrid(); for (int i = 0; i < count; i++) { rowSpanInfo.Add(i, 0); tg.AppendChild(new GridColumn()); } table.AppendChild(tg); } }
public static TableGrid Col(this TableGrid Grid, int Width) { Grid.AppendChild(new GridColumn { Width = Width.ToString() }); return(Grid); }
public override void FillContent() { SetPlaceholder(NewSlidePart, "{title}", _forces.DiagramName); Table tbl = NewSlidePart.Slide.Descendants <Table>().First(); TableGrid tableGrid = tbl.TableGrid; for (int i = 0; i != _forces.GetDecisions().Length; i++) { var gc = new GridColumn { Width = 1234000L }; tableGrid.AppendChild(gc); } // insert the concern header and the decisions names TableRow decRow = tbl.Descendants <TableRow>().First(); foreach ( TableCell decCell in _forces.GetDecisions() .Select(decision => CreateTextCell(decision.Name))) { decRow.AppendChild(decCell); } foreach (var concernsPerForce in _forces.GetConcernsPerForce()) { IEAElement force = concernsPerForce.Key; List <IEAElement> concerns = concernsPerForce.Value; foreach (IEAElement concern in concerns) { var forceRow = new TableRow { Height = 370840L }; forceRow.AppendChild(CreateTextCell(force.Name)); forceRow.AppendChild(CreateTextCell(concern.Name)); // insert ratings foreach (Rating rating in _forces.GetRatings()) { if (rating.ForceGUID != force.GUID || rating.ConcernGUID != concern.GUID) { continue; } if (_forces.GetDecisions().Any(decision => rating.DecisionGUID == decision.GUID)) { forceRow.AppendChild(CreateTextCell(rating.Value)); } } tbl.AppendChild(forceRow); } } }
//public static void DuplicateTable(Body body, int tableIndex) //{ // Table tb1 = body.Elements<Table>().ElementAt(tableIndex); // //var elementIndex = body.ToList().IndexOf(tb1); // Table tb2 = (Table)tb1.CloneNode(true); // Paragraph p = new Paragraph(new Run(new Break() { Type = BreakValues.Page })); // body.InsertAfter(p, tb1); // body.InsertAfter(tb2, p); //} //private static Paragraph saparetor = new Paragraph(); //public static void DuplicateTable(Body body, int tableIndex, OpenXmlElement saparator) //{ //} //向右插入資料並保持原格式 public static void TableColumnInsert(Table tb, DataTable data) { int widthCount = 0; TableGrid tg = tb.Elements <TableGrid>().First(); for (int j = 0; j < data.Rows.Count; j++) { DataRow dr = data.Rows[j]; GridColumn gc = (GridColumn)tg.Elements <GridColumn>().Last().CloneNode(true); widthCount += Convert.ToInt32(gc.Width.Value); tg.AppendChild <GridColumn>(gc); for (int i = 0; i < data.Columns.Count; i++) { var row = tb.Elements <TableRow>().ElementAt(i); var newCell = (TableCell)(row.Elements <TableCell>().LastOrDefault <TableCell>() ?? new TableCell()).CloneNode(true); var newParagraph = newCell.Elements <Paragraph>().FirstOrDefault() ?? new Paragraph(); Run newRun = (Run)(newParagraph.Elements <Run>().FirstOrDefault <Run>() ?? new Run()).CloneNode(true); Text text = newRun.Elements <Text>().FirstOrDefault() ?? new Text(); if (newParagraph.Parent == null) { newCell.AppendChild <Paragraph>(newParagraph); } if (text.Parent == null) { newRun.AppendChild <Text>(text); } text.Text = dr[i].ToString(); newParagraph.RemoveAllChildren <Run>(); newParagraph.AppendChild <Run>(newRun); row.AppendChild <TableCell>(newCell); } } //設定新的寬度 var tbW = tb.Elements <TableProperties>().First <TableProperties>().Elements <TableWidth>().First <TableWidth>(); tbW.Width.Value = (Convert.ToInt32(tbW.Width.Value) + widthCount).ToString(); }
private void InsertTableWord(WordprocessingDocument doc) { // Encuentra la segunda tabla en el documento. Table table = doc.MainDocumentPart.Document.Body.Elements <Table>().ElementAt(1); // Encuentra la segunda fila en la tabla. TableRow row = table.Elements <TableRow>().ElementAt(1); // Encuentra la celda a modificar. TableCell cell = row.Elements <TableCell>().First(); // Crea la tabla. Table tbl = new Table(); // Establece estiloy y anchura a la tabla. TableProperties tableProp = new TableProperties(); TableStyle tableStyle = new TableStyle() { Val = "TableGrid" }; // Hace que la tabla ocupe el 100% de la pagina. TableWidth tableWidth = new TableWidth() { Width = "5000", Type = TableWidthUnitValues.Pct }; // Aplicar propiedades a la tabla. tableProp.Append(tableStyle, tableWidth); tbl.AppendChild(tableProp); // Define las columnas de la tabla. TableGrid tg = new TableGrid(); foreach (DataColumn column in ds.Tables[0].Columns) { tg.AppendChild(new GridColumn()); } tbl.AppendChild(tg); // Fila para las columnas de la tabla. TableRow tblRowColumns = new TableRow(); tbl.AppendChild(tblRowColumns); // Obtiene y asigna nombres a las columnas de la tabla. foreach (DataColumn column in ds.Tables[0].Columns) { TableCell tblCell = new TableCell(new Paragraph(new Run(new Text(column.ColumnName)))); tblRowColumns.AppendChild(tblCell); } // Agrega el resto de las filas a la tabla. foreach (DataRow dtRow in ds.Tables[0].Rows) { TableRow tblRow = new TableRow(); for (int i = 0; i < dtRow.Table.Columns.Count; i++) { TableCell tblCell = new TableCell(new Paragraph(new Run(new Text(dtRow[i].ToString())))); tblRow.AppendChild(tblCell); } tbl.AppendChild(tblRow); } // Agrega la tabla al placeholder correspondiente. cell.AppendChild(new Paragraph(new Run(tbl))); }
private void AddSecondPageTable(Body body) { Table personalInfoTable = new Table(); TableProperties tableProps = new TableProperties(); AddTableBorders(tableProps); TableStyle tableStyle = new TableStyle() { Val = "TableGrid" }; TableWidth tableWidth = new TableWidth() { Width = "5000", Type = TableWidthUnitValues.Pct }; tableProps.Append(tableStyle, tableWidth); TableGrid tableGrid = new TableGrid(); personalInfoTable.AppendChild(tableProps); for (int x = 0; x < 6; x++) { tableGrid.AppendChild(new GridColumn()); } personalInfoTable.AppendChild(tableGrid); for (int x = 0; x < 7; x++) { TableRow pesonalTableRow = new TableRow(); List <TableCell> cells = new List <TableCell>(); for (int i = 0; i < 6; i++) { TableCell cell = new TableCell(); TableCellProperties tableCellProperties = new TableCellProperties(); tableCellProperties.TableCellVerticalAlignment = new TableCellVerticalAlignment(); tableCellProperties.TableCellVerticalAlignment.Val = TableVerticalAlignmentValues.Center; VerticalMerge verticalMerge = new VerticalMerge(); HorizontalMerge horizontalMerge = new HorizontalMerge(); if (x == 0) { horizontalMerge.Val = i == 0 ? MergedCellValues.Restart : MergedCellValues.Continue; tableCellProperties.AppendChild(horizontalMerge); if (i == 0) { SetCellText(cell, "Time Table", true); } else { SetCellText(cell, "", false); } } else if (i == 0) { verticalMerge.Val = x == 1 ? MergedCellValues.Restart : MergedCellValues.Continue; tableCellProperties.AppendChild(verticalMerge); if (x == 1) { SetCellText(cell, "Hours", true); } else { SetCellText(cell, "", false); } } else if (x == 1) { switch (i) { case 1: SetCellText(cell, "Mon", true); break; case 2: SetCellText(cell, "Tue", true); break; case 3: SetCellText(cell, "Wed", true); break; case 4: SetCellText(cell, "Thu", true); break; case 5: SetCellText(cell, "Fri", true); break; } } else if (x == 4) { horizontalMerge.Val = i == 1 ? MergedCellValues.Restart : MergedCellValues.Continue; tableCellProperties.AppendChild(horizontalMerge); if (i == 1) { SetCellText(cell, "Lunch", true); } else { SetCellText(cell, "", false); } } else if (x == 2 || x == 5) { switch (i) { case 1: case 3: SetCellText(cell, "Science", false); break; case 2: case 4: SetCellText(cell, "Maths", false); break; } } else if (x == 3 || x == 6) { switch (i) { case 1: case 4: SetCellText(cell, "Social", false); break; case 2: SetCellText(cell, "History", false); break; case 3: SetCellText(cell, "English", false); break; } } if (x == 2 && i == 5) { SetCellText(cell, "Arts", false); } else if (x == 3 && i == 5) { SetCellText(cell, "Sports", false); } else if (i == 5 && (x == 5 || x == 6)) { if (x == 5) { verticalMerge.Val = MergedCellValues.Restart; SetCellText(cell, "Project", false); } else { verticalMerge.Val = MergedCellValues.Continue; SetCellText(cell, "", false); } tableCellProperties.AppendChild(verticalMerge); } cell.AppendChild(tableCellProperties); cells.Add(cell); } pesonalTableRow.Append(cells); personalInfoTable.AppendChild(pesonalTableRow); } body.AppendChild(personalInfoTable); }
internal static Tuple <Table, TableLook> CreateTable(Models.Document document, Models.Table table, ContextModel context, OpenXmlPart documentPart, IFormatProvider formatProvider) { Table wordTable = new Table(); TableProperties wordTableProperties = new TableProperties(); var tableLook = new TableLook() { FirstRow = OnOffValue.FromBoolean(false), LastRow = OnOffValue.FromBoolean(false), FirstColumn = OnOffValue.FromBoolean(false), LastColumn = OnOffValue.FromBoolean(false), NoHorizontalBand = OnOffValue.FromBoolean(false), NoVerticalBand = OnOffValue.FromBoolean(false) }; wordTableProperties.AppendChild(tableLook); //The type must be Dxa, if the value is set to Pct : the open xml engine will ignored it ! wordTableProperties.TableIndentation = new TableIndentation() { Width = table.TableIndentation.Width, Type = TableWidthUnitValues.Dxa }; wordTable.AppendChild(wordTableProperties); if (table.Borders != null) { TableBorders borders = table.Borders.Render(); wordTableProperties.AppendChild(borders); } // add column width definitions if (table.ColsWidth != null) { wordTable.AppendChild(new TableLayout() { Type = TableLayoutValues.Fixed }); TableGrid tableGrid = new TableGrid(); foreach (int width in table.ColsWidth) { tableGrid.AppendChild(new GridColumn() { Width = width.ToString(CultureInfo.InvariantCulture) }); } wordTable.AppendChild(tableGrid); } if (table.TableWidth != null) { wordTable.AppendChild(new TableWidth() { Width = table.TableWidth.Width, Type = table.TableWidth.Type.ToOOxml() }); } // add header row if (table.HeaderRow != null) { wordTable.AppendChild(table.HeaderRow.Render(document, wordTable, context, documentPart, true, false, formatProvider)); tableLook.FirstRow = OnOffValue.FromBoolean(true); } return(new Tuple <Table, TableLook>(wordTable, tableLook)); }
static Table NewTable(int columnCt) { // Create a table. Table tbl = new Table(); // Set the style and width for the table. TableProperties tableProp = new TableProperties(); TableStyle tableStyle = new TableStyle() { Val = "TableGrid" }; // Make the table width 100% of the page width. TableWidth tableWidth = new TableWidth() { Width = "5000", Type = TableWidthUnitValues.Pct }; // Apply tableProp.Append(tableStyle, tableWidth); tbl.AppendChild(tableProp); // Add columns to the table. TableGrid tg = new TableGrid(); for (int i = 0; i < columnCt; i++) { tg.AppendChild(new GridColumn()); } tbl.AppendChild(tg); //body.AppendChild(tbl); return tbl; }
private static Table genTable(List <CalcCore.CalcValueBase> calcVals, MainDocumentPart mainPart) { Table tableOfInputs = new Table(); var tableGrid = new TableGrid(); tableGrid.AppendChild(new GridColumn()); tableGrid.AppendChild(new GridColumn()); tableGrid.AppendChild(new GridColumn()); tableOfInputs.AppendChild(tableGrid); var tableProps = new TableProperties(); tableProps.AppendChild(new TableLayout() { Type = TableLayoutValues.Fixed }); tableProps.AppendChild(new TableWidth() { Width = "9000", Type = TableWidthUnitValues.Dxa }); tableProps.AppendChild(new TableBorders() { InsideHorizontalBorder = new InsideHorizontalBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); tableProps.AppendChild(new TableBorders() { BottomBorder = new BottomBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); tableProps.AppendChild(new TableBorders() { TopBorder = new TopBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); //tableProps.AppendChild(new TableBorders() { LeftBorder = new LeftBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); //tableProps.AppendChild(new TableBorders() { InsideVerticalBorder = new InsideVerticalBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); //tableProps.AppendChild(new TableBorders() { RightBorder = new RightBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); tableOfInputs.AppendChild(tableProps); foreach (var item in calcVals) { TableRow row = new TableRow(); var para1 = new Paragraph(); TableCell cell1 = new TableCell(); // insert symbol as image var parser = new TexFormulaParser(); if (item.Symbol != "") { TexFormula formulaToParse = new TexFormula(); try { parser = new TexFormulaParser(); formulaToParse = parser.Parse(item.Symbol); } catch (Exception) { parser = new TexFormulaParser(); formulaToParse = parser.Parse("Error in LaTeX string..."); } var formulaImage = formulaToParse.RenderToPng(100, 0, 0, "Franklin Gothic Book"); ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Png); using (var stream = new MemoryStream(formulaImage)) { imagePart.FeedData(stream); var img = new BitmapImage(); img.BeginInit(); img.StreamSource = stream; img.CacheOption = BitmapCacheOption.OnLoad; img.EndInit(); img.Freeze(); var paraImage = AddImageToBody(mainPart.GetIdOfPart(imagePart), img.Width * 2.54 / 600, img.Height * 2.54 / 600); para1.AppendChild(new Run(paraImage)); } } else { para1.AppendChild(new Run(new Text(" "))); } //var myMath = new M.OfficeMath(new M.Run(new M.Text(item.Symbol) { Space = SpaceProcessingModeValues.Preserve })); //para1.AppendChild(myMath); //para1.AppendChild(new Run(new Text(" ") { Space = SpaceProcessingModeValues.Preserve })); cell1.Append(para1); cell1.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1200" })); var para2 = new Paragraph(new Run(new Text(item.Name))); TableCell cell2 = new TableCell(); cell2.AppendChild(para2); cell2.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "6100" })); var para3 = new Paragraph(); if (item.Type == CalcValueType.DOUBLE) { // insert symbol as image parser = new TexFormulaParser(); string toRender = item.ValueAsString + item.Unit; if (toRender != "") { TexFormula formulaToParse = new TexFormula(); try { parser = new TexFormulaParser(); formulaToParse = parser.Parse(toRender); } catch (Exception) { parser = new TexFormulaParser(); formulaToParse = parser.Parse("Error in LaTeX string..."); } var formulaImage = formulaToParse.RenderToPng(100, 0, 0, "Franklin Gothic Book"); ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Png); using (var stream = new MemoryStream(formulaImage)) { imagePart.FeedData(stream); var img = new BitmapImage(); img.BeginInit(); img.StreamSource = stream; img.CacheOption = BitmapCacheOption.OnLoad; img.EndInit(); img.Freeze(); var paraImage = AddImageToBody(mainPart.GetIdOfPart(imagePart), img.Width * 2.54 / 600, img.Height * 2.54 / 600); para3.AppendChild(new Run(paraImage)); } } else { para3.AppendChild(new Run(new Text(" "))); } //myMath = new DocumentFormat.OpenXml.Math.OfficeMath(new M.Run(new M.Text(item.ValueAsString + item.Unit) { Space = SpaceProcessingModeValues.Preserve })); //para3.AppendChild(myMath); //para3.AppendChild(new Run(new Text(" ") { Space = SpaceProcessingModeValues.Preserve })); } else if (item.Type == CalcValueType.SELECTIONLIST) { para3.AppendChild(new Run(new Text(item.ValueAsString))); } else { cell2.AppendChild(new Paragraph(new Run(new Text(item.ValueAsString)))); } TableCell cell3 = new TableCell(); cell3.Append(para3); cell3.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1700" })); row.Append(cell1, cell2, cell3); tableOfInputs.AppendChild(row); } return(tableOfInputs); }
private static Table genFormulaeTable(List <Formula> formulae, MainDocumentPart mainPart) { Table tableOfInputs = new Table(); var tableGrid = new TableGrid(); tableGrid.AppendChild(new GridColumn()); tableGrid.AppendChild(new GridColumn()); tableGrid.AppendChild(new GridColumn()); tableOfInputs.AppendChild(tableGrid); var tableProps = new TableProperties(); tableProps.AppendChild(new TableLayout() { Type = TableLayoutValues.Fixed }); tableProps.AppendChild(new TableWidth() { Width = "9000", Type = TableWidthUnitValues.Dxa }); tableProps.AppendChild(new TableBorders() { InsideHorizontalBorder = new InsideHorizontalBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); tableProps.AppendChild(new TableBorders() { BottomBorder = new BottomBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); tableProps.AppendChild(new TableBorders() { TopBorder = new TopBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); //tableProps.AppendChild(new TableBorders() { LeftBorder = new LeftBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); //tableProps.AppendChild(new TableBorders() { InsideVerticalBorder = new InsideVerticalBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); //tableProps.AppendChild(new TableBorders() { RightBorder = new RightBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); tableOfInputs.AppendChild(tableProps); foreach (var item in formulae) { TableRow row = new TableRow(); var para = new Paragraph(); para.AppendChild((new Run(new Text(item.Ref)))); TableCell cell1 = new TableCell(); cell1.Append(para); cell1.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1200" })); TableCell cell2 = new TableCell(); cell2.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "6100" })); cell2.AppendChild(new Paragraph(new Run(new Text(item.Narrative)))); //foreach (var formula in item.Expression) //{ // var mathPara = new Paragraph(); // var myMath = new M.OfficeMath(new M.Run(new M.Text(formula + Environment.NewLine) { Space = SpaceProcessingModeValues.Preserve })); // mathPara.AppendChild(myMath); // mathPara.AppendChild(new Run(new Text(" ") { Space = SpaceProcessingModeValues.Preserve })); // cell2.AppendChild(mathPara); //} foreach (var formula in item.Expression) { if (formula != "") { TexFormula formulaToParse = new TexFormula(); try { var parser = new TexFormulaParser(); formulaToParse = parser.Parse(formula); } catch (Exception) { var parser = new TexFormulaParser(); formulaToParse = parser.Parse("Error in LaTeX string..."); } var test = formulaToParse.GetRenderer(TexStyle.Script, 100, "Franklin Gothic Book"); if (test.RenderSize.Width > 0 && test.RenderSize.Height > 0) { var formulaImage = formulaToParse.RenderToPng(100, 0, 0, "Franklin Gothic Book"); ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Png); using (var stream = new MemoryStream(formulaImage)) { imagePart.FeedData(stream); var img = new BitmapImage(); img.BeginInit(); img.StreamSource = stream; img.CacheOption = BitmapCacheOption.OnLoad; img.EndInit(); img.Freeze(); var paraImage = AddImageToBody(mainPart.GetIdOfPart(imagePart), img.Width * 2.54 / 600, img.Height * 2.54 / 600); cell2.AppendChild(new Paragraph(new Run(paraImage))); } } GC.WaitForPendingFinalizers(); } //var myMath = new M.OfficeMath(new M.Run(new M.Text(formula + Environment.NewLine) { Space = SpaceProcessingModeValues.Preserve })); //mathPara.AppendChild(myMath); //mathPara.AppendChild(new Run(new Text(" ") { Space = SpaceProcessingModeValues.Preserve })); //cell2.AppendChild(mathPara); } if (item.Image != null) { ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Png); var tempFile = Path.GetTempFileName(); PngBitmapEncoder png = new PngBitmapEncoder(); //CHANGEBITMAP //png.Frames.Add(BitmapFrame.Create(item.Image)); var width = Math.Min(10d, item.Image.Width * 2.54 / 96); var height = ((double)item.Image.Height / (double)item.Image.Width) * width; using (SkiaSharp.SKWStream stm = new SkiaSharp.SKFileWStream(tempFile)) { item.Image.Encode(stm, SkiaSharp.SKEncodedImageFormat.Png, 0); } using (FileStream stream = new FileStream(tempFile, FileMode.Open)) { imagePart.FeedData(stream); } var paraImage = AddImageToBody(mainPart.GetIdOfPart(imagePart), width, height); cell2.AppendChild(new Paragraph(new Run(paraImage))); } TableCell cell3 = new TableCell(); cell3.Append(new Paragraph(new Run(new Text(item.Conclusion)))); cell3.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1700" })); row.Append(cell1, cell2, cell3); tableOfInputs.AppendChild(row); } return(tableOfInputs); }
public static void CreateTable(WordprocessingDocument wordprocessingDocument, int colcount, int rowcount, int begintag) { //WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(fileName, true); //Body body = wordprocessingDocument.MainDocumentPart.Document.Body; Table tb = new Table(); //Table properties TableProperties tableProp = new TableProperties(); TableBorders tbb = new TableBorders( new TopBorder { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 7 }, new BottomBorder { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 7 }, new LeftBorder { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 7 }, new RightBorder { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 7 }, new InsideHorizontalBorder { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 7 }, new InsideVerticalBorder { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 7 } ); TableWidth tableWidth = new TableWidth() { Width = "2800", Type = TableWidthUnitValues.Pct }; tableProp.Append(tableWidth, tbb); tb.AppendChild(tableProp); //Table column TableGrid tg = new TableGrid(); for (int i = 1; i < colcount; i++) { GridColumn gc = new GridColumn(); tg.AppendChild(gc); } tb.AppendChild(tg); //Table row for (int j = 0; j < rowcount; j++) { TableRow tr = new TableRow(); for (int k = 0; k < colcount; k++) { TableCell tc = new TableCell(new Paragraph(new Run(new Text(ToHexString(txtPatentlist[begintag][0]))))); tr.Append(tc); begintag++; } tb.AppendChild(tr); } body.AppendChild(tb); //wordprocessingDocument.MainDocumentPart.Document.Save(); //wordprocessingDocument.Close(); }
private static Table genTable(List <CalcValueBase> calcVals) { Table tableOfInputs = new Table(); var tableGrid = new TableGrid(); tableGrid.AppendChild(new GridColumn()); tableGrid.AppendChild(new GridColumn()); tableGrid.AppendChild(new GridColumn()); tableOfInputs.AppendChild(tableGrid); var tableProps = new TableProperties(); tableProps.AppendChild(new TableLayout() { Type = TableLayoutValues.Fixed }); tableProps.AppendChild(new TableWidth() { Width = "9000", Type = TableWidthUnitValues.Dxa }); tableProps.AppendChild(new TableBorders() { InsideHorizontalBorder = new InsideHorizontalBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); tableProps.AppendChild(new TableBorders() { BottomBorder = new BottomBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); tableProps.AppendChild(new TableBorders() { TopBorder = new TopBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); //tableProps.AppendChild(new TableBorders() { LeftBorder = new LeftBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); //tableProps.AppendChild(new TableBorders() { InsideVerticalBorder = new InsideVerticalBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); //tableProps.AppendChild(new TableBorders() { RightBorder = new RightBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } }); tableOfInputs.AppendChild(tableProps); foreach (var item in calcVals) { TableRow row = new TableRow(); var para1 = new Paragraph(); var myMath = new M.OfficeMath(new M.Run(new M.Text(item.Symbol) { Space = SpaceProcessingModeValues.Preserve })); para1.AppendChild(myMath); para1.AppendChild(new Run(new Text(" ") { Space = SpaceProcessingModeValues.Preserve })); TableCell cell1 = new TableCell(); cell1.Append(para1); cell1.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1200" })); var para2 = new Paragraph(new Run(new Text(item.Name))); TableCell cell2 = new TableCell(); cell2.AppendChild(para2); cell2.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "6100" })); var para3 = new Paragraph(); if (item.Type == CalcValueType.DOUBLE) { myMath = new M.OfficeMath(new M.Run(new M.Text(item.ValueAsString + item.Unit) { Space = SpaceProcessingModeValues.Preserve })); para3.AppendChild(myMath); para3.AppendChild(new Run(new Text(" ") { Space = SpaceProcessingModeValues.Preserve })); } else if (item.Type == CalcValueType.SELECTIONLIST) { para3.AppendChild(new Run(new Text(item.ValueAsString))); } else { cell2.AppendChild(new Paragraph(new Run(new Text(item.ValueAsString)))); } TableCell cell3 = new TableCell(); cell3.Append(para3); cell3.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1700" })); row.Append(cell1, cell2, cell3); tableOfInputs.AppendChild(row); } return(tableOfInputs); }
internal void ApplyTableProperties(Table table, DocxNode node) { TableProperties tableProp = new TableProperties(); TableStyle tableStyle = new TableStyle() { Val = DocxTableProperties.tableGridName }; tableProp.Append(tableStyle); DocxTableStyle style = new DocxTableStyle(); style.Process(tableProp, this, node); table.AppendChild(tableProp); int count = GetTdCount(node); rowSpanInfo = new Dictionary<int, int>(); if (count > 0) { TableGrid tg = new TableGrid(); for (int i = 0; i < count; i++) { rowSpanInfo.Add(i, 0); tg.AppendChild(new GridColumn()); } table.AppendChild(tg); } }