예제 #1
0
        /// <summary>
        /// The write table.
        /// </summary>
        /// <param name="t">
        /// The t.
        /// </param>
        public void WriteTable(Table t)
        {
            var p      = new System.Windows.Documents.Paragraph();
            var figure = new Figure();
            var table  = new System.Windows.Documents.Table();

            // if (t.HasHeader())
            // {
            // var trg1 = new TableRowGroup();
            // SetStyle(trg1, Style.TableHeaderStyle);
            // var r = new TableRow();
            // foreach (var c in columns)
            // {
            // var cell = new TableCell();
            // var run = new Run() { Text = c.Header };
            // cell.Blocks.Add(new System.Windows.Documents.Paragraph(run));
            // r.Cells.Add(cell);
            // }
            // trg1.Rows.Add(r);
            // table.RowGroups.Add(trg1);
            // }
            var trg2 = new TableRowGroup();

            // SetStyle(trg2, Style.TableTextStyle);
            foreach (var row in t.Rows)
            {
                var r = new TableRow();
                if (row.IsHeader)
                {
                    SetStyle(r, row.IsHeader ? this.Style.TableHeaderStyle : this.Style.TableTextStyle);
                }

                for (int j = 0; j < t.Columns.Count; j++)
                {
                    TableCell c    = row.Cells[j];
                    var       cell = new System.Windows.Documents.TableCell();
                    var       run  = new Run {
                        Text = c.Content
                    };
                    cell.Blocks.Add(new System.Windows.Documents.Paragraph(run));
                    r.Cells.Add(cell);
                }

                trg2.Rows.Add(r);
            }

            table.RowGroups.Add(trg2);

            figure.Blocks.Add(this.CreateParagraph(t.Caption, this.Style.FigureTextStyle));
            figure.Blocks.Add(table);
            p.Inlines.Add(figure);
            this.doc.Blocks.Add(p);
        }
        /// <summary>
        /// Writes the table.
        /// </summary>
        /// <param name="t">
        /// The t.
        /// </param>
        public void WriteTable(Table t)
        {
            if (t.Rows == null || t.Columns == null)
            {
                return;
            }

            this.WriteStartElement("table");

            // WriteAttributeString("border", "1");
            // WriteAttributeString("width", "60%");
            if (t.Caption != null)
            {
                this.WriteStartElement("caption");
                this.WriteString(t.GetFullCaption(this.style));
                this.WriteEndElement();
            }

            this.WriteRows(t);

            this.WriteEndElement(); // table
        }
        /// <summary>
        /// Writes the items.
        /// </summary>
        /// <param name="t">
        /// The table.
        /// </param>
        public void WriteRows(Table t)
        {
            IList<TableColumn> columns = t.Columns;

            foreach (var c in columns)
            {
                this.WriteStartElement("col");
                this.WriteAttributeString("align", GetAlignmentString(c.Alignment));
                if (double.IsNaN(c.Width))
                {
                    this.WriteAttributeString("width", c.Width + "pt");
                }

                this.WriteEndElement();
            }

            foreach (var row in t.Rows)
            {
                if (row.IsHeader)
                {
                    this.WriteStartElement("thead");
                }

                this.WriteStartElement("tr");
                int j = 0;
                foreach (var c in row.Cells)
                {
                    bool isHeader = row.IsHeader || t.Columns[j++].IsHeader;

                    this.WriteStartElement("td");
                    if (isHeader)
                    {
                        this.WriteAttributeString("class", "header");
                    }

                    this.WriteString(c.Content);
                    this.WriteEndElement();
                }

                this.WriteEndElement(); // tr
                if (row.IsHeader)
                {
                    this.WriteEndElement(); // thead
                }
            }
        }
        /// <summary>
        /// The write table.
        /// </summary>
        /// <param name="t">
        /// The t.
        /// </param>
        public void WriteTable(Table t)
        {
            this.body.Append(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.Append(tableStyle1);
            tableProperties1.Append(tableWidth1);
            tableProperties1.Append(tableLook1);

            var tableGrid1 = new TableGrid();
            foreach (var tc in t.Columns)
            {
                // tc.Width
                var gridColumn1 = new GridColumn { Width = "3070" };
                tableGrid1.Append(gridColumn1);
            }

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

                if (row.IsHeader)
                {
                    var trp = new TableRowProperties();
                    var tableHeader1 = new TableHeader();
                    trp.Append(tableHeader1);
                    tr.Append(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.Append(
                        new BottomBorder
                            {
                                Val = BorderValues.Single,
                                Size = (UInt32Value)4U,
                                Space = (UInt32Value)0U,
                                Color = "auto"
                            });
                    borders.Append(
                        new TopBorder
                            {
                                Val = BorderValues.Single,
                                Size = (UInt32Value)4U,
                                Space = (UInt32Value)0U,
                                Color = "auto"
                            });
                    borders.Append(
                        new LeftBorder
                            {
                                Val = BorderValues.Single,
                                Size = (UInt32Value)4U,
                                Space = (UInt32Value)0U,
                                Color = "auto"
                            });
                    borders.Append(
                        new RightBorder
                            {
                                Val = BorderValues.Single,
                                Size = (UInt32Value)4U,
                                Space = (UInt32Value)0U,
                                Color = "auto"
                            });
                    tcp.Append(borders);

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

                table.Append(tr);
            }

            this.body.Append(table);
        }
        /// <summary>
        /// The write table.
        /// </summary>
        /// <param name="t">
        /// The t.
        /// </param>
        public void WriteTable(Table t)
        {
            var p = new System.Windows.Documents.Paragraph();
            var figure = new Figure();
            var table = new System.Windows.Documents.Table();

            // if (t.HasHeader())
            // {
            // var trg1 = new TableRowGroup();
            // SetStyle(trg1, Style.TableHeaderStyle);
            // var r = new TableRow();
            // foreach (var c in columns)
            // {
            // var cell = new TableCell();
            // var run = new Run() { Text = c.Header };
            // cell.Blocks.Add(new System.Windows.Documents.Paragraph(run));
            // r.Cells.Add(cell);
            // }
            // trg1.Rows.Add(r);
            // table.RowGroups.Add(trg1);
            // }
            var trg2 = new TableRowGroup();

            // SetStyle(trg2, Style.TableTextStyle);
            foreach (var row in t.Rows)
            {
                var r = new TableRow();
                if (row.IsHeader)
                {
                    SetStyle(r, row.IsHeader ? this.Style.TableHeaderStyle : this.Style.TableTextStyle);
                }

                for (int j = 0; j < t.Columns.Count; j++)
                {
                    TableCell c = row.Cells[j];
                    var cell = new System.Windows.Documents.TableCell();
                    var run = new Run { Text = c.Content };
                    cell.Blocks.Add(new System.Windows.Documents.Paragraph(run));
                    r.Cells.Add(cell);
                }

                trg2.Rows.Add(r);
            }

            table.RowGroups.Add(trg2);

            figure.Blocks.Add(this.CreateParagraph(t.Caption, this.Style.FigureTextStyle));
            figure.Blocks.Add(table);
            p.Inlines.Add(figure);
            this.doc.Blocks.Add(p);
        }
        /// <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>
        /// Writes the table.
        /// </summary>
        /// <param name="t">
        /// The t.
        /// </param>
        public void WriteTable(Table t)
        {
            this.WriteIndentedLine(@"\begin{table}[h]");
            this.Indent();
            int columns = t.Columns.Count;
            string cols = "|";

            foreach (var t1 in t.Columns)
            {
                cols += t1.Alignment.ToString().ToLower()[0];
                cols += "|";
            }

            this.WriteIndentedLine(@"\begin{center}");
            this.Indent();
            this.WriteIndentedLine(@"\begin{tabular}[h]{" + cols + "}");
            this.Indent();
            this.WriteIndentedLine(@"\hline");
            foreach (var row in t.Rows)
            {
                this.WriteIndent();
                for (int j = 0; j < columns; j++)
                {
                    TableCell cell = row.Cells[j];
                    string text = LatexEncodeText(cell.Content);
                    Write(text);
                    if (j < columns - 1)
                    {
                        this.Write(" & ");
                    }
                }

                this.WriteLine(@"\\");
            }

            this.WriteIndentedLine(@"\hline");
            this.UnIndent();
            this.WriteIndentedLine(@"\end{tabular}");
            this.UnIndent();
            this.WriteIndentedLine(@"\end{center}");
            this.WriteIndentedLine(@"\caption{" + LatexEncodeText(t.Caption) + "}");

            // WriteLine(@"\label{ex:table}");
            this.UnIndent();
            this.WriteIndentedLine(@"\end{table}");
            this.WriteLine();
        }
예제 #8
0
        /// <summary>
        /// Writes the specified table.
        /// </summary>
        /// <param name="table">The table.</param>
        void IReportWriter.WriteTable(Table table)
        {
            if (table.Rows == null)
            {
                return;
            }

            var pdfTable = new MigraDoc.DocumentObjectModel.Tables.Table
                {
                    Borders = { Width = 0.25, Left = { Width = 0.5 }, Right = { Width = 0.5 } },
                    Rows = { LeftIndent = 0 }
                };

            //// pdfTable.Style = "Table";
            //// pdfTable.Borders.Color = TableBorder;

            int columns = table.Columns.Count;

            for (int j = 0; j < columns; j++)
            {
                var pdfColumn = pdfTable.AddColumn();

                // todo: the widths are not working
                //// pdfColumn.Width = Unit.FromMillimeter(table.Columns[j].ActualWidth);
                pdfColumn.Format.Alignment = ConvertToParagraphAlignment(table.Columns[j].Alignment);
            }

            foreach (var tr in table.Rows)
            {
                var pdfRow = pdfTable.AddRow();
                for (int j = 0; j < columns; j++)
                {
                    bool isHeader = tr.IsHeader || table.Columns[j].IsHeader;

                    var c = tr.Cells[j];
                    var pdfCell = pdfRow.Cells[j];
                    pdfCell.AddParagraph(c.Content ?? string.Empty);
                    pdfCell.Style = isHeader ? "TableHeader" : "TableText";
                    pdfCell.Format.Alignment = ConvertToParagraphAlignment(table.Columns[j].Alignment);
                }
            }

            // table.SetEdge(0, 0, t.Columns.Count, t.Items.Count(), Edge.Box, BorderStyle.Single, 1.5, Colors.Black);
            if (table.Caption != null)
            {
                var pa = this.CurrentSection.AddParagraph();
                pa.AddFormattedText(table.GetFullCaption(this.style), "TableCaption");
            }

            this.CurrentSection.Add(pdfTable);
        }
        /// <summary>
        /// The write table.
        /// </summary>
        /// <param name="t">
        /// The t.
        /// </param>
        public void WriteTable(Table t)
        {
            this.tableCounter++;
            this.WriteLine(string.Format("Table {0}. {1}", this.tableCounter, t.Caption));
            this.WriteLine();
            int rows = t.Rows.Count;
            int cols = t.Columns.Count;

            var columnWidth = new int[cols];
            int totalLength = 0;
            for (int j = 0; j < cols; j++)
            {
                columnWidth[j] = 0;
                foreach (var tr in t.Rows)
                {
                    TableCell cell = tr.Cells[j];
                    string text = cell.Content;
                    columnWidth[j] = Math.Max(columnWidth[j], text != null ? text.Length : 0);
                }

                totalLength += columnWidth[j];
            }

            // WriteLine("-".Repeat(totalLength));
            foreach (var tr in t.Rows)
            {
                for (int j = 0; j < cols; j++)
                {
                    TableCell cell = tr.Cells[j];
                    string text = cell.Content;
                    bool isHeader = tr.IsHeader || t.Columns[j].IsHeader;
                    this.Write(GetCellText(j, cols, PadString(text, t.Columns[j].Alignment, columnWidth[j]), isHeader));
                }

                this.WriteLine();
            }

            this.WriteLine();
        }
예제 #10
0
        /// <summary>
        /// The write table.
        /// </summary>
        /// <param name="t">The table.</param>
        public void WriteTable(Table t)
        {
            if (t.Caption != null)
            {
                this.tableCounter++;
                this.WriteLine("Table {0}. {1}", this.tableCounter, t.Caption);
            }

            this.WriteLine();
            int cols = t.Columns.Count;

            var columnWidth = new int[cols];
            for (int j = 0; j < cols; j++)
            {
                columnWidth[j] = 0;
                foreach (var tr in t.Rows)
                {
                    var cell = tr.Cells[j];
                    var text = cell.Content;
                    columnWidth[j] = Math.Max(columnWidth[j], text != null ? text.Length : 0);
                }
            }

            // WriteLine("-".Repeat(totalLength));
            foreach (var tr in t.Rows)
            {
                for (int j = 0; j < cols; j++)
                {
                    var cell = tr.Cells[j];
                    var text = cell.Content;
                    this.Write(GetCellText(j, cols, PadString(text, t.Columns[j].Alignment, columnWidth[j])));
                }

                this.WriteLine();
            }

            this.WriteLine();
        }