private static void PrettyWaresTable(Table waresTable, TableDesign design) { waresTable.Rows.ForEach(x => x.Cells.ForEach(y => y.Paragraphs.First().Alignment = Alignment.center)); waresTable.SetColumnWidth(0, 30); waresTable.SetColumnWidth(3, 70); waresTable.Design = design; waresTable.Alignment = Alignment.center; }
public void InsertTable(string bookMark, ITableInsert tableInsert, TableDesign tableDesign = TableDesign.TableGrid) { var item = _doc.Bookmarks[bookMark]; if (item != null) { var table = _doc.AddTable(tableInsert.RowCount, tableInsert.ColumnCount); table.Design = tableDesign; tableInsert.InsertHead(table); tableInsert.FillData(table); item.Paragraph.InsertTableAfterSelf(table); } }
public ListConsole(PhoneBook phoneBook, string filterType) { if (filterType != string.Empty) Console.WriteLine("Contacts filtered by birthday " + filterType + "." + Environment.NewLine); var design = new TableDesign(); Console.WriteLine(string.Format("INDEX" + design.SpaceLength(8, 5) + "| NAME" + design.SpaceLength(30, 4) + "| PHONE" + design.SpaceLength(20, 5) + "| BIRTHDATE")); Console.WriteLine(string.Format(design.SpaceLength(90, 0, "-"))); foreach (KeyValuePair<string, Contact> currentItem in phoneBook) { string index = currentItem.Key; string name = currentItem.Value.Name; string phone = currentItem.Value.PhoneNumber; string born = MakeDateLength(currentItem.Value.BirthDate); Console.WriteLine(string.Format( "{0}" + design.SpaceLength(8, index.ToString().Length) + "| {1}" + design.SpaceLength(30, name.Length) + "| {2}" + design.SpaceLength(20, phone.Length) + "| {3}", index, name, phone, born.Substring(0, 4) + "-" + born.Substring(4, 2) + "-" + born.Substring(6, 2) + AddBornMessageIfExist(born))); } }
private static void AddTable(DocX doc, List <UpdateRecord> records, TableDesign td) { Table t = doc.AddTable(1, 4); t.Alignment = Alignment.left; t.Design = td; t.SetColumnWidth(0, 90); t.SetColumnWidth(1, 70); t.SetColumnWidth(2, 70); t.SetColumnWidth(3, 310); int c = 0; t.Rows[0].Cells[c++].Paragraphs.First().Append("Name"); t.Rows[0].Cells[c++].Paragraphs.First().Append("Health"); t.Rows[0].Cells[c++].Paragraphs.First().Append("Exit Date\r\nOriginal\r\nCurrent"); t.Rows[0].Cells[c++].Paragraphs.First().Append("Comment"); foreach (var record in records) { var row = t.InsertRow(); c = 0; row.Cells[c++].Paragraphs.First().Append(record.Name); row.Cells[c++].Paragraphs.First().Append(record.Health).FormatHealth(); row.Cells[c++].Paragraphs.First() .Append(record.ExitDateOriginal.FormatDate()) .Append(System.Environment.NewLine) .Append(System.Environment.NewLine) .Append(record.ExitDateCurrent.FormatDate()); row.Cells[c++].Paragraphs.First().Append(record.Comment); } doc.InsertTable(t); }
internal Table(DocX document, XElement xml) : base(document, xml) { autofit = AutoFit.ColumnWidth; this.Xml = xml; this.mainPart = document.mainPart; XElement properties = xml.Element(XName.Get("tblPr", DocX.w.NamespaceName)); XElement style = properties?.Element(XName.Get("tblStyle", DocX.w.NamespaceName)); if (style != null) { XAttribute val = style.Attribute(XName.Get("val", DocX.w.NamespaceName)); if (val != null) { String cleanValue = val.Value.Replace("-", string.Empty); if (Enum.IsDefined(typeof(TableDesign), cleanValue)) { design = (TableDesign)Enum.Parse(typeof(TableDesign), cleanValue); } else { design = TableDesign.Custom; } } else design = TableDesign.None; } else design = TableDesign.None; XElement tableLook = properties?.Element(XName.Get("tblLook", DocX.w.NamespaceName)); if (tableLook != null) { TableLook = new TableLook { FirstRow = tableLook.GetAttribute(XName.Get("firstRow", DocX.w.NamespaceName)) == "1", LastRow = tableLook.GetAttribute(XName.Get("lastRow", DocX.w.NamespaceName)) == "1", FirstColumn = tableLook.GetAttribute(XName.Get("firstColumn", DocX.w.NamespaceName)) == "1", LastColumn = tableLook.GetAttribute(XName.Get("lastColumn", DocX.w.NamespaceName)) == "1", NoHorizontalBanding = tableLook.GetAttribute(XName.Get("noHBand", DocX.w.NamespaceName)) == "1", NoVerticalBanding = tableLook.GetAttribute(XName.Get("noVBand", DocX.w.NamespaceName)) == "1" }; } }
internal Table(DocX document, XElement xml) : base(document, xml) { autofit = AutoFit.ColumnWidth; this.Xml = xml; XElement properties = xml.Element(XName.Get("tblPr", DocX.w.NamespaceName)); XElement style = properties.Element(XName.Get("tblStyle", DocX.w.NamespaceName)); if (style != null) { XAttribute val = style.Attribute(XName.Get("val", DocX.w.NamespaceName)); if (val != null) { try { design = (TableDesign)Enum.Parse(typeof(TableDesign), val.Value.Replace("-", string.Empty)); } catch (Exception) { design = TableDesign.Custom; } } else design = TableDesign.None; } else design = TableDesign.None; XElement tableLook = properties.Element(XName.Get("tblLook", DocX.w.NamespaceName)); if (tableLook != null) { TableLook = new TableLook(); TableLook.FirstRow = tableLook.GetAttribute(XName.Get("firstRow", DocX.w.NamespaceName)) == "1"; TableLook.LastRow = tableLook.GetAttribute(XName.Get("lastRow", DocX.w.NamespaceName)) == "1"; TableLook.FirstColumn = tableLook.GetAttribute(XName.Get("firstColumn", DocX.w.NamespaceName)) == "1"; TableLook.LastColumn = tableLook.GetAttribute(XName.Get("lastColumn", DocX.w.NamespaceName)) == "1"; TableLook.NoHorizontalBanding = tableLook.GetAttribute(XName.Get("noHBand", DocX.w.NamespaceName)) == "1"; TableLook.NoVerticalBanding = tableLook.GetAttribute(XName.Get("noVBand", DocX.w.NamespaceName)) == "1"; } }
internal Table(DocX document, XElement xml) { autofit = AutoFit.ColoumnWidth; this.xml = xml; this.document = document; XElement properties = xml.Element(XName.Get("tblPr", DocX.w.NamespaceName)); rows = (from r in xml.Elements(XName.Get("tr", DocX.w.NamespaceName)) select new Row(document, r)).ToList(); rowCount = rows.Count; if (rows.Count > 0) if (rows[0].Cells.Count > 0) columnCount = rows[0].Cells.Count; XElement style = properties.Element(XName.Get("tblStyle", DocX.w.NamespaceName)); if (style != null) { XAttribute val = style.Attribute(XName.Get("val", DocX.w.NamespaceName)); if (val != null) { try { design = (TableDesign)Enum.Parse(typeof(TableDesign), val.Value.Replace("-", string.Empty)); } catch (Exception e) { design = TableDesign.Custom; } } else design = TableDesign.None; } else design = TableDesign.None; }