public TableProperties GetTableProperties()
        {
            var result = new TableProperties();

            if (Width != null)
            {
                result.AppendChild(Width.ToTableWidthType <TableWidth>());
            }

            result.TableCellMarginDefault = new TableCellMarginDefault();

            if (CellLeftMargin != null)
            {
                result.TableCellMarginDefault.TableCellLeftMargin = CellLeftMargin.ToTableMargin <TableCellLeftMargin>();
            }

            if (CellTopMargin != null)
            {
                result.TableCellMarginDefault.TopMargin = CellTopMargin.ToTableWidthType <TopMargin>();
            }

            if (CellRightMargin != null)
            {
                result.TableCellMarginDefault.TableCellRightMargin =
                    CellRightMargin.ToTableMargin <TableCellRightMargin>();
            }

            if (CellBottomMargin != null)
            {
                result.TableCellMarginDefault.BottomMargin = CellBottomMargin.ToTableWidthType <BottomMargin>();
            }

            if (CellSpacing != null)
            {
                result.TableCellSpacing = new TableCellSpacing
                {
                    Width = CellSpacing
                };
            }

            result.TableBorders = Borders;

            return(result);
        }
        void ImportProjectsAndMilestones(MainDocumentPart mainPart, Word.SdtElement sdt, SPFile spreadsheetFileName)
        {
            ArrayList cellText = new ArrayList();

            // Create a Word table.
            Word.Table tbl = new Word.Table();
            Word.TableProperties tblPr = new Word.TableProperties();
            Word.TableStyle tblStyle = new Word.TableStyle();
            tblStyle.Val = "LightShading-Accent1";
            tblPr.AppendChild(tblStyle);

            Word.TableWidth tblW = new Word.TableWidth();
            tblW.Width = "5000";
            tblW.Type = Word.TableWidthUnitValues.Pct;
            tblPr.Append(tblW);
            tbl.AppendChild(tblPr);
            byte[] byteArray = spreadsheetFileName.OpenBinary();

            using (MemoryStream mem = new MemoryStream())
            {
                mem.Write(byteArray, 0, (int)byteArray.Length);

                using (SpreadsheetDocument mySpreadsheet = SpreadsheetDocument.Open(mem, true))
                {
                    WorkbookPart workbookPart = mySpreadsheet.WorkbookPart;
                    WorksheetPart worksheetPart = XLGetWorksheetPartByName(mySpreadsheet, "Sheet1");

                    Excel.SheetData sheetData =
                       worksheetPart.Worksheet.GetFirstChild<Excel.SheetData>();

                    foreach (Excel.Row r in sheetData)
                    {
                        foreach (Excel.Cell c in r)
                        {
                            cellText.Add(XLGetCellValue(c, workbookPart));
                        }
                        Word.TableRow tr = CreateRow(cellText);
                        tbl.Append(tr);
                        cellText = new ArrayList();
                    }
                }
            }
            // Swap out the content control for the SmartArt.
            OpenXmlElement parent = sdt.Parent;
            parent.InsertAfter(tbl, sdt);
            sdt.Remove();
        }
        /// <summary>
        /// The write table.
        /// </summary>
        /// <param name="t">The t.</param>
        public void WriteTable(Table t)
        {
            this.body.AppendChild(CreateParagraph(t.GetFullCaption(this.style), TableCaptionId));

            var table = new DocumentFormat.OpenXml.Wordprocessing.Table();

            var tableProperties1 = new TableProperties();
            var tableStyle1      = new TableStyle {
                Val = "TableGrid"
            };
            var tableWidth1 = new TableWidth {
                Width = "0", Type = TableWidthUnitValues.Auto
            };
            var tableLook1 = new TableLook
            {
                Val              = "04A0",
                FirstRow         = true,
                LastRow          = false,
                FirstColumn      = true,
                LastColumn       = false,
                NoHorizontalBand = false,
                NoVerticalBand   = true
            };

            tableProperties1.AppendChild(tableStyle1);
            tableProperties1.AppendChild(tableWidth1);
            tableProperties1.AppendChild(tableLook1);

            var tableGrid1 = new TableGrid();

            // ReSharper disable once UnusedVariable
            foreach (var tc in t.Columns)
            {
                // TODO: use tc.Width to set the width of the column
                var gridColumn1 = new GridColumn {
                    Width = "3070"
                };
                tableGrid1.AppendChild(gridColumn1);
            }

            foreach (var row in t.Rows)
            {
                var tr = new TableRow();

                if (row.IsHeader)
                {
                    var trp          = new TableRowProperties();
                    var tableHeader1 = new TableHeader();
                    trp.AppendChild(tableHeader1);
                    tr.AppendChild(trp);
                }

                int j = 0;
                foreach (var c in row.Cells)
                {
                    bool isHeader = row.IsHeader || t.Columns[j++].IsHeader;
                    var  cell     = new TableCell();
                    var  tcp      = new TableCellProperties();
                    var  borders  = new TableCellBorders();
                    borders.AppendChild(
                        new BottomBorder
                    {
                        Val   = BorderValues.Single,
                        Size  = 4U,
                        Space = 0U,
                        Color = "auto"
                    });
                    borders.AppendChild(
                        new TopBorder
                    {
                        Val   = BorderValues.Single,
                        Size  = 4U,
                        Space = 0U,
                        Color = "auto"
                    });
                    borders.AppendChild(
                        new LeftBorder
                    {
                        Val   = BorderValues.Single,
                        Size  = 4U,
                        Space = 0U,
                        Color = "auto"
                    });
                    borders.AppendChild(
                        new RightBorder
                    {
                        Val   = BorderValues.Single,
                        Size  = 4U,
                        Space = 0U,
                        Color = "auto"
                    });
                    tcp.AppendChild(borders);

                    cell.AppendChild(tcp);
                    string styleId = isHeader ? "TableHeader" : "TableText";
                    cell.AppendChild(CreateParagraph(c.Content, styleId));
                    tr.AppendChild(cell);
                }

                table.AppendChild(tr);
            }

            this.body.AppendChild(table);
        }
        /// <summary>
        /// The write table.
        /// </summary>
        /// <param name="t">The t.</param>
        public void WriteTable(Table t)
        {
            this.body.AppendChild(CreateParagraph(t.GetFullCaption(this.style), TableCaptionId));

            var table = new DocumentFormat.OpenXml.Wordprocessing.Table();

            var tableProperties1 = new TableProperties();
            var tableStyle1 = new TableStyle { Val = "TableGrid" };
            var tableWidth1 = new TableWidth { Width = "0", Type = TableWidthUnitValues.Auto };
            var tableLook1 = new TableLook
                {
                    Val = "04A0",
                    FirstRow = true,
                    LastRow = false,
                    FirstColumn = true,
                    LastColumn = false,
                    NoHorizontalBand = false,
                    NoVerticalBand = true
                };

            tableProperties1.AppendChild(tableStyle1);
            tableProperties1.AppendChild(tableWidth1);
            tableProperties1.AppendChild(tableLook1);

            var tableGrid1 = new TableGrid();
            // ReSharper disable once UnusedVariable
            foreach (var tc in t.Columns)
            {
                // TODO: use tc.Width to set the width of the column
                var gridColumn1 = new GridColumn { Width = "3070" };
                tableGrid1.AppendChild(gridColumn1);
            }

            foreach (var row in t.Rows)
            {
                var tr = new TableRow();

                if (row.IsHeader)
                {
                    var trp = new TableRowProperties();
                    var tableHeader1 = new TableHeader();
                    trp.AppendChild(tableHeader1);
                    tr.AppendChild(trp);
                }

                int j = 0;
                foreach (var c in row.Cells)
                {
                    bool isHeader = row.IsHeader || t.Columns[j++].IsHeader;
                    var cell = new TableCell();
                    var tcp = new TableCellProperties();
                    var borders = new TableCellBorders();
                    borders.AppendChild(
                        new BottomBorder
                            {
                                Val = BorderValues.Single,
                                Size = 4U,
                                Space = 0U,
                                Color = "auto"
                            });
                    borders.AppendChild(
                        new TopBorder
                            {
                                Val = BorderValues.Single,
                                Size = 4U,
                                Space = 0U,
                                Color = "auto"
                            });
                    borders.AppendChild(
                        new LeftBorder
                            {
                                Val = BorderValues.Single,
                                Size = 4U,
                                Space = 0U,
                                Color = "auto"
                            });
                    borders.AppendChild(
                        new RightBorder
                            {
                                Val = BorderValues.Single,
                                Size = 4U,
                                Space = 0U,
                                Color = "auto"
                            });
                    tcp.AppendChild(borders);

                    cell.AppendChild(tcp);
                    string styleId = isHeader ? "TableHeader" : "TableText";
                    cell.AppendChild(CreateParagraph(c.Content, styleId));
                    tr.AppendChild(cell);
                }

                table.AppendChild(tr);
            }

            this.body.AppendChild(table);
        }