public static Table GetFooterTable(Reports.Footer footer)
        {
            Table      table      = new Table();
            TableStyle tableStyle = new TableStyle()
            {
                Val = "TableGrid"
            };

            table.AppendChild(tableStyle);

            TableProperties tblProp = new TableProperties(
                new TableBorders(
                    new TopBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.None)
            },
                    new BottomBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.None)
            },
                    new LeftBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.None)
            },
                    new RightBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.None)
            },
                    new InsideHorizontalBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.None)
            },
                    new InsideVerticalBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.None)
            }
                    ),
                //new TableCellMargin()
                //{
                //    TopMargin = new TopMargin() { Width = new StringValue("400") },
                //    BottomMargin = new BottomMargin() { Width = new StringValue("400") },
                //    LeftMargin = new LeftMargin() { Width = new StringValue("400") },
                //    RightMargin = new RightMargin() { Width = new StringValue("400") }
                //},
                new TableJustification()
            {
                Val = TableRowAlignmentValues.Left
            },
                new TableWidth()
            {
                Type = TableWidthUnitValues.Pct, Width = new StringValue("5000")
            }
                );

            // Append the TableProperties object to the empty table.
            table.AppendChild <TableProperties>(tblProp);

            TableGrid grid = new TableGrid(new GridColumn()
            {
                Width = new StringValue("1500")
            }, new GridColumn()
            {
                Width = new StringValue("1500")
            });

            table.AppendChild <TableGrid>(grid);


            var cellProperties = new TableCellProperties()
            {
                TableCellWidth = new TableCellWidth()
                {
                    Width = new StringValue("2500"), Type = TableWidthUnitValues.Pct
                }
            };

            TableRow  tr1 = new TableRow();
            TableCell tc1 = new TableCell(new Paragraph(new Run(new Text(footer.Left.Title))));

            tc1.AppendChild <TableCellProperties>((TableCellProperties)cellProperties.Clone());
            tr1.Append(tc1);

            TableCell tc2 = new TableCell(new Paragraph(new Run(new Text(footer.Right.Title))));

            tc2.AppendChild <TableCellProperties>((TableCellProperties)cellProperties.Clone());
            tr1.Append(tc2);

            table.Append(tr1);

            TableRow tr2 = new TableRow();

            TableCell tc3 = new TableCell(new Paragraph(new Run(new Text(footer.Left.Text))));

            tc3.AppendChild <TableCellProperties>((TableCellProperties)cellProperties.Clone());
            tr2.Append(tc3);

            TableCell tc4 = new TableCell(new Paragraph(new Run(new Text(footer.Right.Text))));

            tc4.AppendChild <TableCellProperties>((TableCellProperties)cellProperties.Clone());
            tr2.Append(tc4);

            table.Append(tr2);

            return(table);
        }
Exemplo n.º 2
0
        public Table AppendTotalPriceTableInfo(List <string> tableData, Table table, bool header)
        {
            TableRow tr = new TableRow();
            PreviousTablePropertyExceptions ptpex = new PreviousTablePropertyExceptions();
            TableCellMarginDefault          tcm   = new TableCellMarginDefault();

            tcm.TopMargin = new TopMargin()
            {
                Width = "0", Type = TableWidthUnitValues.Dxa
            };

            tcm.BottomMargin = new BottomMargin()
            {
                Width = "0", Type = TableWidthUnitValues.Dxa
            };
            ptpex.Append(tcm);
            tr.Append(ptpex);

            TableCell tc;



            TableCellProperties tcp = new TableCellProperties(new TableCellVerticalAlignment()
            {
                Val = TableVerticalAlignmentValues.Center
            });

            tcp.TableCellMargin = new TableCellMargin(new RightMargin()
            {
                Type = TableWidthUnitValues.Pct, Width = "50"
            });
            tcp.TableCellMargin.LeftMargin = new LeftMargin()
            {
                Type = TableWidthUnitValues.Pct, Width = "50"
            };
            tcp.TableCellMargin.TopMargin = new TopMargin()
            {
                Type = TableWidthUnitValues.Pct, Width = "1"
            };
            tcp.TableCellBorders = new TableCellBorders(
                new TopBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.None), Size = 0, Space = 0
            },
                new BottomBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.None), Size = 0, Space = 0
            },
                new LeftBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.None), Size = 0, Space = 0
            },
                new RightBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.None), Size = 0, Space = 0
            },
                new InsideHorizontalBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.None), Size = 0, Space = 0
            },
                new InsideVerticalBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.None), Size = 0, Space = 0
            }
                );


            ParagraphProperties ppl = new ParagraphProperties(new Justification()
            {
                Val = JustificationValues.Left
            });
            ParagraphProperties ppr = new ParagraphProperties(new Justification()
            {
                Val = JustificationValues.Right
            });

            ppl.Append(new KeepLines());
            ppl.Append(new KeepNext());
            SpacingBetweenLines sp = new SpacingBetweenLines();

            sp.After = "0";
            ppl.Append(sp);

            ppr.Append(new KeepLines());
            ppr.Append(new KeepNext());
            SpacingBetweenLines spr = new SpacingBetweenLines();

            spr.After = "0";
            ppr.Append(spr);



            RunProperties rp = new RunProperties(new Bold()
            {
                Val = false
            });
            Shading shading = new Shading();

            rp.Bold.Val = false;
            rp.RunFonts = new RunFonts()
            {
                Ascii = "Calibri"
            };
            rp.FontSize = new FontSize()
            {
                Val = new StringValue("26")
            };

            shading = new Shading()
            {
                Val = ShadingPatternValues.Clear, Color = "auto"
            };

            tcp.Shading = shading;
            for (int i = 0; i < tableData.Count; i++)
            {
                tc = new TableCell();
                //TableStyle tableStyle = new TableStyle() { Val = "TableGrid" };

                // Make the table width 100% of the page width.
                TableWidth tableWidth = new TableWidth()
                {
                    Width = "5000", Type = TableWidthUnitValues.Dxa
                };
                //tcp.Append(tableStyle, tableWidth);
                tcp.Append(tableWidth);

                if (i == 0 || i == 2 || i == 4)
                {
                    tcp.TableCellWidth = new TableCellWidth()
                    {
                        Width = "4900", Type = TableWidthUnitValues.Dxa
                    };
                    tc.Append((ParagraphProperties)ppr.Clone());
                    tc.Append((TableCellProperties)tcp.Clone());
                }
                else
                {
                    tcp.TableCellWidth = new TableCellWidth()
                    {
                        Width = "100", Type = TableWidthUnitValues.Dxa
                    };
                    tc.Append((ParagraphProperties)ppl.Clone());
                    tc.Append((TableCellProperties)tcp.Clone());
                }

                Run r = new Run();
                r.PrependChild <RunProperties>((RunProperties)rp.Clone());
                r.Append(new Text(tableData[i].ToString()));
                tc.Append(new Paragraph(r));
                tr.Append(tc);
            }



            table.Append(tr);

            return(table);
        }
        public static Table GetTable(Reports.Table dataTable)
        {
            var tableWidth = dataTable.Data.GetLength(1) > 2 ? "5000" : "3000";

            Table table = new Table();

            TableStyle tableStyle = new TableStyle()
            {
                Val = "TableGrid"
            };

            table.AppendChild(tableStyle);

            var borderColor = "909090";

            // Create a TableProperties object and specify its border information.
            TableProperties tblProp = new TableProperties(
                new TableBorders(
                    new TopBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.BasicThinLines), Size = 2, Color = new StringValue(borderColor)
            },
                    new BottomBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.BasicThinLines), Size = 2, Color = new StringValue(borderColor)
            },
                    new LeftBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.BasicThinLines), Size = 2, Color = new StringValue(borderColor)
            },
                    new RightBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.BasicThinLines), Size = 2, Color = new StringValue(borderColor)
            },
                    new InsideHorizontalBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.BasicThinLines), Size = 2, Color = new StringValue(borderColor)
            },
                    new InsideVerticalBorder()
            {
                Val = new EnumValue <BorderValues>(BorderValues.BasicThinLines), Size = 2, Color = new StringValue(borderColor)
            }
                    ),
                new TableCellMargin()
            {
                TopMargin = new TopMargin()
                {
                    Width = new StringValue("100")
                },
                BottomMargin = new BottomMargin()
                {
                    Width = new StringValue("100")
                },
                LeftMargin = new LeftMargin()
                {
                    Width = new StringValue("200")
                },
                RightMargin = new RightMargin()
                {
                    Width = new StringValue("200")
                }
            },
                new TableJustification()
            {
                Val = TableRowAlignmentValues.Center
            },
                new TableWidth()
            {
                Type = TableWidthUnitValues.Pct, Width = new StringValue(tableWidth)
            }
                );

            // Append the TableProperties object to the empty table.
            table.AppendChild <TableProperties>(tblProp);

            //table.AppendChild(grid);

            var cellProperties = new TableCellProperties()
            {
                TableCellWidth = new TableCellWidth()
                {
                    Width = new StringValue("1250"), Type = TableWidthUnitValues.Pct
                },
                TableCellMargin = new TableCellMargin()
                {
                    BottomMargin = new BottomMargin()
                    {
                        Width = new StringValue("100"), Type = TableWidthUnitValues.Dxa
                    },
                    TopMargin = new TopMargin()
                    {
                        Width = new StringValue("100"), Type = TableWidthUnitValues.Dxa
                    },
                    LeftMargin = new LeftMargin()
                    {
                        Width = new StringValue("100"), Type = TableWidthUnitValues.Dxa
                    },
                    RightMargin = new RightMargin()
                    {
                        Width = new StringValue("100"), Type = TableWidthUnitValues.Dxa
                    }
                },
                TableCellVerticalAlignment = new TableCellVerticalAlignment()
                {
                    Val = TableVerticalAlignmentValues.Center
                }
            };

            if (dataTable.Header != null)
            {
                TableRow tr = new TableRow();

                for (int i = 0; i < dataTable.Header.Length; i++)
                {
                    var       title = dataTable.Header[i];
                    TableCell tc1   = new TableCell();

                    var justification = ((i > 0) ? JustificationValues.Right : JustificationValues.Left);

                    var paragraph = new Paragraph()
                    {
                        ParagraphProperties = new ParagraphProperties()
                        {
                            Justification = new Justification()
                            {
                                Val = justification
                            },
                            ContextualSpacing = new ContextualSpacing()
                            {
                                Val = false
                            },
                        }
                    };

                    var run = paragraph.AppendChild(new Run());
                    run.AppendChild(new Text(title));
                    run.RunProperties = new RunProperties();
                    run.RunProperties.AppendChild(new Bold());
                    run.RunProperties.AppendChild(new Color()
                    {
                        Val = "4682B4"
                    });

                    var properties = (TableCellProperties)cellProperties.Clone();
                    properties.TableCellWidth = new TableCellWidth()
                    {
                        Width = getWidthPercentage(i).ToString(), Type = TableWidthUnitValues.Pct
                    };
                    tc1.AppendChild <TableCellProperties>(properties);
                    tc1.Append(paragraph);

                    tr.Append(tc1);
                }

                table.Append(tr);
            }

            int rows    = dataTable.Data.GetLength(0);
            int columns = dataTable.Data.GetLength(1);

            for (int i = 0; i < rows; i++)
            {
                TableRow tr = new TableRow();
                for (int j = 0; j < columns; j++)
                {
                    TableCell tc1        = new TableCell();
                    var       properties = (TableCellProperties)cellProperties.Clone();
                    properties.TableCellWidth = new TableCellWidth()
                    {
                        Width = getWidthPercentage(j).ToString(), Type = TableWidthUnitValues.Pct
                    };
                    tc1.AppendChild <TableCellProperties>(properties);

                    var justification = ((j > 0) ? JustificationValues.Right : JustificationValues.Left);

                    var paragraph = new Paragraph()
                    {
                        ParagraphProperties = new ParagraphProperties()
                        {
                            Justification = new Justification()
                            {
                                Val = justification
                            }
                        }
                    };

                    var run = paragraph.AppendChild(new Run());
                    run.RunProperties       = new RunProperties();
                    run.RunProperties.Color = new Color()
                    {
                        Val = "363844"
                    };
                    run.AppendChild(new Text(dataTable.Data[i, j]));
                    tc1.Append(paragraph);

                    tr.Append(tc1);
                }
                table.Append(tr);
            }
            return(table);
        }
Exemplo n.º 4
0
        public Table AppendInvoiceTableInfo(List <string> tableData, Table table, bool header)
        {
            TableRow tr = new TableRow();
            PreviousTablePropertyExceptions ptpex = new PreviousTablePropertyExceptions();
            TableCellMarginDefault          tcm   = new TableCellMarginDefault();

            tcm.TopMargin = new TopMargin()
            {
                Width = "0", Type = TableWidthUnitValues.Dxa
            };

            tcm.BottomMargin = new BottomMargin()
            {
                Width = "0", Type = TableWidthUnitValues.Dxa
            };
            ptpex.Append(tcm);
            tr.Append(ptpex);

            TableCell tc;



            TableCellProperties tcp = new TableCellProperties(new TableCellVerticalAlignment()
            {
                Val = TableVerticalAlignmentValues.Center
            });

            tcp.TableCellMargin = new TableCellMargin(new RightMargin()
            {
                Type = TableWidthUnitValues.Pct, Width = "50"
            });
            tcp.TableCellMargin.LeftMargin = new LeftMargin()
            {
                Type = TableWidthUnitValues.Pct, Width = "50"
            };
            tcp.TableCellMargin.TopMargin = new TopMargin()
            {
                Type = TableWidthUnitValues.Pct, Width = "1"
            };



            ParagraphProperties ppp = new ParagraphProperties(new Justification()
            {
                Val = JustificationValues.Center
            });

            ppp.Append(new KeepLines());
            ppp.Append(new KeepNext());
            SpacingBetweenLines sp = new SpacingBetweenLines();

            sp.After = "0";
            ppp.Append(sp);



            if (!header)
            {
                RunProperties rp = new RunProperties(new Bold()
                {
                    Val = false
                });
                Shading shading = new Shading();
                rp.Bold.Val = false;
                rp.RunFonts = new RunFonts()
                {
                    Ascii = "Calibri"
                };
                rp.FontSize = new FontSize()
                {
                    Val = new StringValue("22")
                };

                //shading = new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = "e3e6e7" };
                shading = new Shading()
                {
                    Val = ShadingPatternValues.Clear, Color = "auto"
                };
                tcp.Shading = shading;
                for (int i = 0; i < tableData.Count; i++)
                {
                    tc = new TableCell();
                    //TableStyle tableStyle = new TableStyle() { Val = "TableGrid" };

                    // Make the table width 100% of the page width.
                    TableWidth tableWidth = new TableWidth()
                    {
                        Width = "50000", Type = TableWidthUnitValues.Auto
                    };
                    tcp.Append(tableWidth);
                    tc.Append((TableCellProperties)tcp.Clone());

                    tc.Append((ParagraphProperties)ppp.Clone());

                    Run r = new Run();
                    r.PrependChild <RunProperties>((RunProperties)rp.Clone());
                    r.Append(new Text(tableData[i].ToString()));
                    tc.Append(new Paragraph(r));
                    tr.Append(tc);
                }
            }
            else
            {
                RunProperties rp = new RunProperties(new Bold()
                {
                    Val = true
                }, new TabChar());
                rp.Bold.Val = true;
                rp.RunFonts = new RunFonts()
                {
                    Ascii = "Arial"
                };
                rp.FontSize = new FontSize()
                {
                    Val = new StringValue("20")
                };
                //Color color = new Color() { Val = "365F91", ThemeColor = ThemeColorValues.Accent1, ThemeShade = "BF" };
                Shading shading = new Shading()
                {
                    Val = ShadingPatternValues.Clear, Color = "auto", Fill = "a7c6d7"
                };
                //ppp.Shading = shading;

                tcp.TableCellMargin.TopMargin.Width = "200";
                tcp.Shading = shading;

                for (int i = 0; i < tableData.Count; i++)
                {
                    tc = new TableCell();
                    TableStyle tableStyle = new TableStyle()
                    {
                        Val = "TableGrid"
                    };

                    // Make the table width 100% of the page width.
                    TableWidth tableWidth = new TableWidth()
                    {
                        Width = "50000", Type = TableWidthUnitValues.Auto
                    };
                    tcp.Append(tableStyle, tableWidth);
                    tc.Append((TableCellProperties)tcp.Clone());
                    tc.Append((ParagraphProperties)ppp.Clone());


                    Run r = new Run();
                    r.PrependChild <RunProperties>((RunProperties)rp.Clone());
                    r.Append(new Text(tableData[i].ToString()));
                    tc.Append(new Paragraph(r));
                    tr.Append(tc);
                }
            }


            table.Append(tr);

            return(table);
        }