Ejemplo n.º 1
0
        /// <summary>
        /// create a table
        /// </summary>
        public static Table AddTable(this WordprocessingDocument doc, int rowCount, int colCount)
        {
            var tbl     = new Table();
            var tblProp = tbl.AppendChild(new TableProperties());

            var docSize    = doc.GetMainSection().GetPageSize();
            var pageMargin = doc.GetMainSection().GetPageMargin();
            var colSizeMM  = (docSize.widthMM - pageMargin.leftMM - pageMargin.rightMM) / colCount;

            for (int r = 0; r < rowCount; ++r)
            {
                var tr = new TableRow();

                for (int c = 0; c < colCount; ++c)
                {
                    var tc        = new TableCell();
                    var tcwidthpc = (100d / colCount).Pct();
                    if (c == colCount - 1)
                    {
                        tcwidthpc = 5000 - (100d / colCount).Pct() * colCount - 1;
                    }
                    tc.Append(new TableCellProperties(
                                  new TableCellWidth()
                    {
                        Type  = TableWidthUnitValues.Dxa,
                        Width = colSizeMM.MMToTwip().ToString()
                    }));
                    tr.AppendChild(tc);
                }

                tbl.AppendChild(tr);
            }

            var body = doc.Body();

            return(body.AppendChild(tbl));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// retrieve default section of the document
 /// </summary>
 public static SectionProperties GetMainSection(this WordprocessingDocument doc)
 {
     return(doc.Body().Descendants <SectionProperties>().FirstOrDefault());
 }