Ejemplo n.º 1
0
        private static Table CreateMailingLabels(List <HetOwner> owners)
        {
            try
            {
                var table = new Table();

                var tableProperties1 = new TableProperties();
                var tableStyle1      = new TableStyle {
                    Val = "TableGrid"
                };
                var tableWidth1 = new TableWidth {
                    Width = "100", Type = TableWidthUnitValues.Auto
                };

                var tableLook1 = new TableLook
                {
                    Val              = "04A0",
                    FirstRow         = true,
                    LastRow          = false,
                    FirstColumn      = true,
                    LastColumn       = false,
                    NoHorizontalBand = true,
                    NoVerticalBand   = true
                };

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

                table.AppendChild(tableProperties1);

                foreach (var ownerTuple in owners.ToTuples())
                {
                    var tableRow = new TableRow();

                    var rowProps = new TableRowProperties();
                    rowProps.AppendChild(new TableRowHeight {
                        Val = CentimeterToDxa(5.08), HeightType = HeightRuleValues.Exact
                    });
                    tableRow.AppendChild(rowProps);

                    tableRow.AppendChild(SetupCell(ownerTuple.Item1, 10.16, 0.27));
                    tableRow.AppendChild(SetupCell(ownerTuple.Item2, 10.16, 0.75)); //to add 0.48 cm

                    table.AppendChild(tableRow);
                }

                return(table);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Ejemplo n.º 2
0
        private void AddTableBorders(TableProperties tableProperties)
        {
            TableBorders tblBorders = new TableBorders();

            AddBorderValues(new TopBorder(), tblBorders);
            AddBorderValues(new BottomBorder(), tblBorders);
            AddBorderValues(new RightBorder(), tblBorders);
            AddBorderValues(new LeftBorder(), tblBorders);
            AddBorderValues(new InsideHorizontalBorder(), tblBorders);
            AddBorderValues(new InsideVerticalBorder(), tblBorders);
            tableProperties.AppendChild(tblBorders);
        }
        //.....................................................................
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private TableProperties MakeTableProperties( )
        {
            //// Create the table properties
            TableProperties properties = new TableProperties( );

            TableBorders borders = this.MakeTableBorders(BorderValues.Thick, "CC0000");

            //// Add the table borders to the properties
            properties.AppendChild(borders);

            return(properties);
        }
Ejemplo n.º 4
0
        public static TableProperties getTableProperties(BorderValues bvTop, string colorTop, BorderValues bvBott, string colorBott, BorderValues bvRight, string colorRight, BorderValues bvLeft, string colorLeft, BorderValues bvinsIdeHBorder, string colorInsideHBorder, BorderValues bvInsideVBorder, string colorInsideVBorder)
        {
            TableProperties tblProperties = new TableProperties();
            TableBorders    tblBorders    = new TableBorders();

            TopBorder topBorder = new TopBorder();

            topBorder.Val   = new EnumValue <BorderValues>(bvTop);
            topBorder.Color = colorTop;
            tblBorders.AppendChild(topBorder);

            BottomBorder bottomBorder = new BottomBorder();

            bottomBorder.Val   = new EnumValue <BorderValues>(bvBott);
            bottomBorder.Color = colorBott;
            tblBorders.AppendChild(bottomBorder);

            RightBorder rightBorder = new RightBorder();

            rightBorder.Val   = new EnumValue <BorderValues>(bvRight);
            rightBorder.Color = colorRight;
            tblBorders.AppendChild(rightBorder);

            LeftBorder leftBorder = new LeftBorder();

            leftBorder.Val   = new EnumValue <BorderValues>(bvLeft);
            leftBorder.Color = colorLeft;
            tblBorders.AppendChild(leftBorder);

            InsideHorizontalBorder insideHBorder = new InsideHorizontalBorder();

            insideHBorder.Val   = new EnumValue <BorderValues>(bvinsIdeHBorder);
            insideHBorder.Color = colorInsideHBorder;
            tblBorders.AppendChild(insideHBorder);

            InsideVerticalBorder insideVBorder = new InsideVerticalBorder();

            insideVBorder.Val   = new EnumValue <BorderValues>(bvInsideVBorder);
            insideVBorder.Color = colorInsideVBorder;
            tblBorders.AppendChild(insideVBorder);

            tblProperties.AppendChild(tblBorders);

            return(tblProperties);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Set the table properties
        /// </summary>
        /// <param name="borderValues"> Border style </param>
        /// <returns></returns>
        private static TableProperties GetTableProperties(string rgbColor, BorderValues borderValues)
        {
            TableProperties tblProperties = new TableProperties();
            TableBorders    tblBorders    = new TableBorders();

            TopBorder topBorder = new TopBorder();

            topBorder.Val   = new EnumValue <BorderValues>(borderValues);
            topBorder.Color = rgbColor;
            tblBorders.AppendChild(topBorder);

            BottomBorder bottomBorder = new BottomBorder();

            bottomBorder.Val   = new EnumValue <BorderValues>(borderValues);
            bottomBorder.Color = rgbColor;
            tblBorders.AppendChild(bottomBorder);

            RightBorder rightBorder = new RightBorder();

            rightBorder.Val   = new EnumValue <BorderValues>(borderValues);
            rightBorder.Color = rgbColor;
            tblBorders.AppendChild(rightBorder);

            LeftBorder leftBorder = new LeftBorder();

            leftBorder.Val   = new EnumValue <BorderValues>(borderValues);
            leftBorder.Color = rgbColor;
            tblBorders.AppendChild(leftBorder);

            InsideHorizontalBorder insideHBorder = new InsideHorizontalBorder();

            insideHBorder.Val   = new EnumValue <BorderValues>(borderValues);
            insideHBorder.Color = rgbColor;
            tblBorders.AppendChild(insideHBorder);

            InsideVerticalBorder insideVBorder = new InsideVerticalBorder();

            insideVBorder.Val   = new EnumValue <BorderValues>(borderValues);
            insideVBorder.Color = rgbColor;
            tblBorders.AppendChild(insideVBorder);

            tblProperties.AppendChild(tblBorders);

            return(tblProperties);
        }
        private TableProperties getTableProperties()
        {
            TableProperties tblProperties = new TableProperties();
            TableBorders    tblBorders    = new TableBorders();

            TopBorder topBorder = new TopBorder();

            topBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            topBorder.Color = "CC0000";
            tblBorders.AppendChild(topBorder);

            BottomBorder bottomBorder = new BottomBorder();

            bottomBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            bottomBorder.Color = "CC0000";
            tblBorders.AppendChild(bottomBorder);

            RightBorder rightBorder = new RightBorder();

            rightBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            rightBorder.Color = "CC0000";
            tblBorders.AppendChild(rightBorder);

            LeftBorder leftBorder = new LeftBorder();

            leftBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            leftBorder.Color = "CC0000";
            tblBorders.AppendChild(leftBorder);

            InsideHorizontalBorder insideHBorder = new InsideHorizontalBorder();

            insideHBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            insideHBorder.Color = "CC0000";
            tblBorders.AppendChild(insideHBorder);

            InsideVerticalBorder insideVBorder = new InsideVerticalBorder();

            insideVBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            insideVBorder.Color = "CC0000";
            tblBorders.AppendChild(insideVBorder);

            tblProperties.AppendChild(tblBorders);

            return(tblProperties);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create new Table object and add header row into table with columns.
        /// </summary>
        /// <param name="columns">The list of column names.</param>
        /// <returns>The DocumentFormat.OpenXml.Wordprocessing.Table object.</returns>
        public virtual Table NewTable(string[] columns, string[] widths = null)
        {
            //create table object
            Table table = new Table();

            // Create the table properties
            TableProperties tblProperties = new TableProperties();

            // Create Table Borders
            TableBorders tblBorders = new TableBorders();

            TopBorder topBorder = new TopBorder();

            topBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            topBorder.Color = "000000";
            tblBorders.AppendChild(topBorder);

            BottomBorder bottomBorder = new BottomBorder();

            bottomBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            bottomBorder.Color = "000000";
            tblBorders.AppendChild(bottomBorder);

            RightBorder rightBorder = new RightBorder();

            rightBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            rightBorder.Color = "000000";
            tblBorders.AppendChild(rightBorder);

            LeftBorder leftBorder = new LeftBorder();

            leftBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            leftBorder.Color = "000000";
            tblBorders.AppendChild(leftBorder);

            InsideHorizontalBorder insideHBorder = new InsideHorizontalBorder();

            insideHBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            insideHBorder.Color = "000000";
            tblBorders.AppendChild(insideHBorder);

            InsideVerticalBorder insideVBorder = new InsideVerticalBorder();

            insideVBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            insideVBorder.Color = "000000";
            tblBorders.AppendChild(insideVBorder);

            // Add the table borders to the properties
            tblProperties.AppendChild(tblBorders);

            // Create Table Width
            TableWidth tableWidth = new TableWidth()
            {
                Width = "100%", Type = TableWidthUnitValues.Pct
            };

            // Add the table width to the properties
            tblProperties.AppendChild(tableWidth);

            // Create Table height
            TableRowHeight tableRowHeight = new TableRowHeight()
            {
                HeightType = HeightRuleValues.Auto
            };

            // Add the table height to the properties
            tblProperties.AppendChild(tableRowHeight);

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

            tblProperties.AppendChild(tableStyle);

            TableLook tableLook = new TableLook()
            {
                Val = "04A0"
            };

            tblProperties.AppendChild(tableLook);

            // Add the table properties to the table
            table.AppendChild(tblProperties);

            //// aaa
            //TableGrid tableGrid = new TableGrid();
            //for (int i = 0; i < columns.Count(); i++)
            //{
            //    //GridColumn gridcol = new GridColumn() { Width = i == 0 ? "800" : "1500" };
            //    GridColumn gridcol = new GridColumn() { Width = "800"};
            //    tableGrid.Append(gridcol);
            //}
            //table.Append(tableGrid);
            //// aaa

            TableRow rowHeader = NewTableRowHeader(columns, widths);

            table.Append(rowHeader);

            return(table);
        }
Ejemplo n.º 8
0
        private static Table CreateTable(NegotiationPrintModel item, double Totalcost)
        {
            //prepare ITEMs
            List <string>         headers = new List <string>();
            List <List <string> > items   = new List <List <string> >();

            headers.Add("STT");
            headers.Add("Tên và mô tả thiết bị");
            headers.Add("Đơn vị tính");
            headers.Add("Số lượng");

            headers.Add("Đơn giá(VNĐ)");
            headers.Add("Thành tiền (VNĐ)");

            int[] widths = { 1000, 4200, 1800, 1500, 2100, 2100 };


            int index = 1;

            foreach (ItemInfo record in item.Items)
            {
                List <string> row = new List <string>();
                row.Add(index.ToString());
                row.Add(record.ItemName);
                row.Add(record.ItemUnit);
                row.Add(record.Amount.ToString());
                row.Add(string.Format("{0:0,0}", record.ItemPrice).Replace(",", "."));
                row.Add(string.Format("{0:0,0}", record.ItemPrice * record.Amount).Replace(",", "."));
                items.Add(row);
                index++;
            }



            //// Create a new table
            Table tbl = new Table();

            //// Create the table properties
            TableProperties    tblProperties = new TableProperties();
            TableJustification just          = new TableJustification();

            just.Val = TableRowAlignmentValues.Center;
            //// Create Table Borders
            TableBorders tblBorders = new TableBorders();
            TopBorder    topBorder  = new TopBorder();

            topBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            topBorder.Color = "000000";
            tblBorders.AppendChild(topBorder);
            BottomBorder bottomBorder = new BottomBorder();

            bottomBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            bottomBorder.Color = "000000";
            tblBorders.AppendChild(bottomBorder);
            RightBorder rightBorder = new RightBorder();

            rightBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            rightBorder.Color = "000000";
            tblBorders.AppendChild(rightBorder);
            LeftBorder leftBorder = new LeftBorder();

            leftBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            leftBorder.Color = "000000";
            tblBorders.AppendChild(leftBorder);
            InsideHorizontalBorder insideHBorder = new InsideHorizontalBorder();

            insideHBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            insideHBorder.Color = "000000";
            tblBorders.AppendChild(insideHBorder);
            InsideVerticalBorder insideVBorder = new InsideVerticalBorder();

            insideVBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            insideVBorder.Color = "000000";
            tblBorders.AppendChild(insideVBorder);
            //// Add the table borders to the properties
            tblProperties.AppendChild(tblBorders);
            tblProperties.AppendChild(just);
            //// Add the table properties to the table
            tbl.AppendChild(tblProperties);
            //// Add a cell to each column in the row
            ///
            List <TableCell> headerCells = new List <TableCell>();
            TableCell        tcName1;

            foreach (string itemHeaders in headers)
            {
                tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                {
                    Val = JustificationValues.Center
                }), new Run(FontTable(), new Text(itemHeaders))));
                tcName1.Append(new TableCellProperties(
                                   new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "3000"
                }));
                headerCells.Add(tcName1);
            }
            //// Create a new row
            TableRow tr = new TableRow();

            tr.Append(headerCells.ToArray());
            tbl.AppendChild(tr);
            List <TableCell> dataCells = new List <TableCell>();


            foreach (List <string> rowItems in items)
            {
                int i = 0;
                dataCells = new List <TableCell>();
                foreach (string data in rowItems)
                {
                    if (i == rowItems.Count - 1)
                    {
                        tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                        {
                            Val = JustificationValues.Right
                        }), new Run(FontTable(), new Text(data))));
                    }
                    else
                    {
                        tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                        {
                            Val = JustificationValues.Center
                        }), new Run(FontTable(), new Text(data))));
                    }
                    tcName1.Append(new TableCellProperties(
                                       new TableCellWidth()
                    {
                        Type = TableWidthUnitValues.Dxa, Width = "3000"
                    }));
                    dataCells.Add(tcName1);

                    i++;
                }
                TableRow tr1 = new TableRow();
                tr1.Append(dataCells.ToArray());
                tbl.AppendChild(tr1);
            }
            TableCellProperties cellOneProperties = new TableCellProperties();

            //if VAT
            if (item.IsVAT)
            {
                // total row
                tr        = new TableRow();
                dataCells = new List <TableCell>();
                tcName1   = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                {
                    Val = JustificationValues.Right
                }), new Run(FontTable(), new Text("Tổng công (chưa bao gồm VAT)"))));
                tcName1.Append(new TableCellProperties(
                                   new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "1000"
                }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Restart
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);

                for (int loopindex = 1; loopindex < widths.Length - 1; loopindex++)
                {
                    tcName1 = new TableCell(new Paragraph());
                    tcName1.Append(new TableCellProperties(
                                       new TableCellWidth()
                    {
                        Type = TableWidthUnitValues.Dxa, Width = widths[loopindex].ToString()
                    }));
                    cellOneProperties = new TableCellProperties();
                    cellOneProperties.Append(new HorizontalMerge()
                    {
                        Val = MergedCellValues.Continue
                    });
                    tcName1.Append(cellOneProperties);
                    dataCells.Add(tcName1);
                }
                double totalCostWithoutVAT = 0;
                totalCostWithoutVAT = Totalcost;
                Totalcost           = Totalcost * (100 + item.VATNumber) / 100;
                var totalCostWithoutVATstr = string.Format("{0:0,0}", totalCostWithoutVAT).Replace(",", ".");
                tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                {
                    Val = JustificationValues.Right
                }), new Run(FontTable(), new Text(totalCostWithoutVATstr))));
                tcName1.Append(new TableCellProperties(
                                   new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "1900"
                }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Restart
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);
                tr.Append(dataCells.ToArray());
                tbl.AppendChild(tr);



                // total row
                tr        = new TableRow();
                dataCells = new List <TableCell>();
                tcName1   = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                {
                    Val = JustificationValues.Right
                }), new Run(FontTable(), new Text("Thuế VAT " + item.VATNumber.ToString() + "%"))));
                tcName1.Append(new TableCellProperties(
                                   new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "200"
                }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Restart
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);

                for (int loopindex = 1; loopindex < widths.Length - 1; loopindex++)
                {
                    tcName1 = new TableCell(new Paragraph());
                    tcName1.Append(new TableCellProperties(
                                       new TableCellWidth()
                    {
                        Type = TableWidthUnitValues.Dxa, Width = widths[loopindex].ToString()
                    }));
                    cellOneProperties = new TableCellProperties();
                    cellOneProperties.Append(new HorizontalMerge()
                    {
                        Val = MergedCellValues.Continue
                    });
                    tcName1.Append(cellOneProperties);
                    dataCells.Add(tcName1);
                }
                double vatCost = 0;
                vatCost = (Totalcost * item.VATNumber) / 100;
                var vatCoststr = string.Format("{0:0,0}", vatCost).Replace(",", ".");
                tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                {
                    Val = JustificationValues.Right
                }), new Run(FontTable(), new Text(vatCoststr))));
                tcName1.Append(new TableCellProperties(
                                   new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "1900"
                }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Restart
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);

                tr.Append(dataCells.ToArray());
                tbl.AppendChild(tr);

                // total row
                tr        = new TableRow();
                dataCells = new List <TableCell>();
                tcName1   = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                {
                    Val = JustificationValues.Right
                }), new Run(FontTable(), new Text("TỔNG CỘNG (đã bao gồm VAT)"))));
                tcName1.Append(new TableCellProperties(
                                   new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "200"
                }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Restart
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);

                for (int loopindex = 1; loopindex < widths.Length - 1; loopindex++)
                {
                    tcName1 = new TableCell(new Paragraph());
                    tcName1.Append(new TableCellProperties(
                                       new TableCellWidth()
                    {
                        Type = TableWidthUnitValues.Dxa, Width = widths[loopindex].ToString()
                    }));
                    cellOneProperties = new TableCellProperties();
                    cellOneProperties.Append(new HorizontalMerge()
                    {
                        Val = MergedCellValues.Continue
                    });
                    tcName1.Append(cellOneProperties);
                    dataCells.Add(tcName1);
                }

                var TotalCostfm = string.Format("{0:0,0}", Totalcost).Replace(",", ".");
                tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                {
                    Val = JustificationValues.Right
                }), new Run(FontTable(), new Text(TotalCostfm))));
                tcName1.Append(new TableCellProperties(
                                   new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "1900"
                }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Restart
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);

                tr.Append(dataCells.ToArray());
                tbl.AppendChild(tr);
            }
            else
            {
                // total row
                tr        = new TableRow();
                dataCells = new List <TableCell>();
                tcName1   = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                {
                    Val = JustificationValues.Right
                }), new Run(FontTable(), new Text("TỔNG CỘNG "))));
                tcName1.Append(new TableCellProperties(
                                   new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "200"
                }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Restart
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);

                for (int loopindex = 1; loopindex < widths.Length - 1; loopindex++)
                {
                    tcName1 = new TableCell(new Paragraph());
                    tcName1.Append(new TableCellProperties(
                                       new TableCellWidth()
                    {
                        Type = TableWidthUnitValues.Dxa, Width = widths[loopindex].ToString()
                    }));
                    cellOneProperties = new TableCellProperties();
                    cellOneProperties.Append(new HorizontalMerge()
                    {
                        Val = MergedCellValues.Continue
                    });
                    tcName1.Append(cellOneProperties);
                    dataCells.Add(tcName1);
                }

                var TotalCostfm = string.Format("{0:0,0}", Totalcost).Replace(",", ".");
                tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                {
                    Val = JustificationValues.Right
                }), new Run(FontTable(), new Text(TotalCostfm))));
                tcName1.Append(new TableCellProperties(
                                   new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "1900"
                }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Restart
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);

                tr.Append(dataCells.ToArray());
                tbl.AppendChild(tr);
            }
            return(tbl);
        }
Ejemplo n.º 9
0
        private static Table GenerateEquipmentTable(IEnumerable <HetEquipment> equipmentList)
        {
            try
            {
                // create an empty table
                Table table = new Table();

                TableProperties tableProperties1 = new TableProperties();
                TableStyle      tableStyle1      = new TableStyle()
                {
                    Val = "TableGrid"
                };
                TableWidth tableWidth1 = new TableWidth()
                {
                    Width = "0", Type = TableWidthUnitValues.Auto
                };

                TableLook 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);

                table.AppendChild(tableProperties1);

                // setup headers
                TableRow tableRow1 = new TableRow();

                TableRowProperties rowProperties = new TableRowProperties();

                rowProperties.AppendChild(new TableRowHeight()
                {
                    Val = 200, HeightType = HeightRuleValues.AtLeast
                });
                rowProperties.AppendChild(new TableHeader()
                {
                    Val = OnOffOnlyValues.On
                });

                tableRow1.AppendChild(rowProperties);

                // add columns
                tableRow1.AppendChild(SetupHeaderCell("Still own/ Re-register?", "1200", true));
                tableRow1.AppendChild(SetupHeaderCell("Local Area", "1000", true));
                tableRow1.AppendChild(SetupHeaderCell("Equipment Id", "1200", true));
                tableRow1.AppendChild(SetupHeaderCell("Equipment Type", "1600"));
                tableRow1.AppendChild(SetupHeaderCell("Year/Make/Model/Serial Number/Size", "2400"));
                tableRow1.AppendChild(SetupHeaderCell("Attachments", "1200"));
                tableRow1.AppendChild(SetupHeaderCell("Owner Comments (sold, retired, etc.)", "2600", true));

                table.AppendChild(tableRow1);

                // add rows for each equipment record
                foreach (HetEquipment equipment in equipmentList)
                {
                    TableRow tableRowEquipment = new TableRow();

                    TableRowProperties equipmentRowProperties = new TableRowProperties();
                    equipmentRowProperties.AppendChild(new TableRowHeight()
                    {
                        Val = 200, HeightType = HeightRuleValues.AtLeast
                    });
                    tableRowEquipment.AppendChild(equipmentRowProperties);

                    // add equipment data
                    tableRowEquipment.AppendChild(SetupCell("Yes   No", true));
                    tableRowEquipment.AppendChild(SetupCell(equipment.LocalArea.Name, true));
                    tableRowEquipment.AppendChild(SetupCell(equipment.EquipmentCode, true));
                    tableRowEquipment.AppendChild(SetupCell(equipment.DistrictEquipmentType.DistrictEquipmentName));

                    string temp = $"{equipment.Year}/{equipment.Make}/{equipment.Model}/{equipment.SerialNumber}/{equipment.Size}";
                    tableRowEquipment.AppendChild(SetupCell(temp));

                    // attachments list
                    temp = "";
                    int row = 1;

                    foreach (HetEquipmentAttachment attachment in equipment.HetEquipmentAttachment)
                    {
                        temp = row == 1 ?
                               $"{attachment.Description}" :
                               $"{temp} / {attachment.Description}";

                        row++;
                    }
                    tableRowEquipment.AppendChild(SetupCell(temp));

                    // last column (blank)
                    tableRowEquipment.AppendChild(SetupCell(""));

                    table.AppendChild(tableRowEquipment);
                }

                return(table);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Ejemplo n.º 10
0
        private static Table CreateBidplan1(List <string> headers, List <List <string> > items, string Cost)
        {
            //// Create a new table
            Table tbl = new Table();

            //// Create the table properties
            TableProperties    tblProperties = new TableProperties();
            TableJustification just          = new TableJustification();

            just.Val = TableRowAlignmentValues.Center;
            //// Create Table Borders
            TableBorders tblBorders = new TableBorders();
            TopBorder    topBorder  = new TopBorder();

            topBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            topBorder.Color = "000000";
            tblBorders.AppendChild(topBorder);
            BottomBorder bottomBorder = new BottomBorder();

            bottomBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            bottomBorder.Color = "000000";
            tblBorders.AppendChild(bottomBorder);
            RightBorder rightBorder = new RightBorder();

            rightBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            rightBorder.Color = "000000";
            tblBorders.AppendChild(rightBorder);
            LeftBorder leftBorder = new LeftBorder();

            leftBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            leftBorder.Color = "000000";
            tblBorders.AppendChild(leftBorder);
            InsideHorizontalBorder insideHBorder = new InsideHorizontalBorder();

            insideHBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            insideHBorder.Color = "000000";
            tblBorders.AppendChild(insideHBorder);
            InsideVerticalBorder insideVBorder = new InsideVerticalBorder();

            insideVBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            insideVBorder.Color = "000000";
            tblBorders.AppendChild(insideVBorder);
            //// Add the table borders to the properties
            tblProperties.AppendChild(tblBorders);
            tblProperties.AppendChild(just);
            //// Add the table properties to the table
            tbl.AppendChild(tblProperties);
            //// Add a cell to each column in the row
            TableCellProperties cellOneProperties = new TableCellProperties();
            List <TableCell>    headerCells       = new List <TableCell>();
            int index = 0;

            int[] widths = { 1400, 1800, 1600, 1300, 1300, 1300, 1300, 1300 };
            foreach (string itemHeaders in headers)
            {
                TableCell tcName12 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                {
                    Val = JustificationValues.Center
                }), new Run(Bold(), new Text(itemHeaders))));
                tcName12.Append(new TableCellProperties(
                                    new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = widths[index].ToString()
                }));
                headerCells.Add(tcName12);
                index++;
            }
            //// Create a new row
            TableRow tr = new TableRow();

            tr.Append(headerCells.ToArray());
            tbl.AppendChild(tr);
            List <TableCell> dataCells = new List <TableCell>();
            TableCell        tcName1;

            foreach (List <string> rowItems in items)
            {
                index     = 0;
                dataCells = new List <TableCell>();
                foreach (string data in rowItems)
                {
                    tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                    {
                        Val = JustificationValues.Center
                    }), new Run(Bold(), new Text(data))));
                    tcName1.Append(new TableCellProperties(
                                       new TableCellWidth()
                    {
                        Type = TableWidthUnitValues.Dxa, Width = widths[index].ToString()
                    }));
                    dataCells.Add(tcName1);
                    index++;
                }
                tr = new TableRow();
                tr.Append(dataCells.ToArray());
                tbl.AppendChild(tr);
            }

            // total row
            tr        = new TableRow();
            dataCells = new List <TableCell>();

            tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
            {
                Val = JustificationValues.Center
            }), new Run(Bold(), new Text("Tổng Giá"))));
            tcName1.Append(new TableCellProperties(
                               new TableCellWidth()
            {
                Type = TableWidthUnitValues.Dxa, Width = "1400"
            }));
            cellOneProperties = new TableCellProperties();
            cellOneProperties.Append(new HorizontalMerge()
            {
                Val = MergedCellValues.Restart
            });
            tcName1.Append(cellOneProperties);
            dataCells.Add(tcName1);

            tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
            {
                Val = JustificationValues.Center
            }), new Run(Bold(), new Text())));
            tcName1.Append(new TableCellProperties(
                               new TableCellWidth()
            {
                Type = TableWidthUnitValues.Dxa, Width = "2200"
            }));
            cellOneProperties = new TableCellProperties();
            cellOneProperties.Append(new HorizontalMerge()
            {
                Val = MergedCellValues.Continue
            });
            tcName1.Append(cellOneProperties);
            dataCells.Add(tcName1);


            tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
            {
                Val = JustificationValues.Center
            }), new Run(Bold(), new Text(Cost))));
            tcName1.Append(new TableCellProperties(
                               new TableCellWidth()
            {
                Type = TableWidthUnitValues.Dxa, Width = "1800"
            }));
            cellOneProperties = new TableCellProperties();
            cellOneProperties.Append(new HorizontalMerge()
            {
                Val = MergedCellValues.Restart
            });
            tcName1.Append(cellOneProperties);
            dataCells.Add(tcName1);


            for (int loopindex = 3; loopindex < widths.Length; loopindex++)
            {
                tcName1 = new TableCell(new Paragraph(new Run(new Text(Cost))));
                tcName1.Append(new TableCellProperties(
                                   new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = widths[loopindex].ToString()
                }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Continue
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);
            }
            tr.Append(dataCells.ToArray());
            tbl.AppendChild(tr);

            return(tbl);
        }
Ejemplo n.º 11
0
        public static TableProperties GetTableProperties(
            string borderColor = "#0000000",
            BorderValues b     = BorderValues.None,
            string tableWidth  = "2500"
            )
        {
            TableProperties tblProperties = new TableProperties();
            TableBorders    tblBorders    = new TableBorders();

            TableCellVerticalAlignment tcVA = new TableCellVerticalAlignment
            {
                Val = TableVerticalAlignmentValues.Center
            };

            tblBorders.AppendChild(tcVA);


            TopBorder topBorder = new TopBorder
            {
                Val   = new EnumValue <BorderValues>(b),
                Color = borderColor
            };

            tblBorders.AppendChild(topBorder);

            BottomBorder bottomBorder = new BottomBorder
            {
                Val   = new EnumValue <BorderValues>(b),
                Color = borderColor
            };

            tblBorders.AppendChild(bottomBorder);

            RightBorder rightBorder = new RightBorder
            {
                Val   = new EnumValue <BorderValues>(b),
                Color = borderColor
            };

            tblBorders.AppendChild(rightBorder);

            LeftBorder leftBorder = new LeftBorder
            {
                Val   = new EnumValue <BorderValues>(b),
                Color = borderColor
            };

            tblBorders.AppendChild(leftBorder);

            InsideHorizontalBorder insideHBorder = new InsideHorizontalBorder
            {
                Val   = new EnumValue <BorderValues>(b),
                Color = borderColor
            };

            tblBorders.AppendChild(insideHBorder);

            InsideVerticalBorder insideVBorder = new InsideVerticalBorder
            {
                Val   = new EnumValue <BorderValues>(b),
                Color = borderColor
            };

            tblBorders.AppendChild(insideVBorder);

            tblProperties.AppendChild(tblBorders);
            TableWidth width = new TableWidth
            {
                Width = tableWidth,
                Type  = TableWidthUnitValues.Pct
            };

            tblProperties.AppendChild(width);
            return(tblProperties);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Convert a DataTable to a word processing Table to insert into a document.
        /// </summary>
        /// <param name="dataTable"></param>
        /// <returns>The Table</returns>
        public static Table ConvertDataTableToWordTable(DataTable dataTable)
        {
            //// Create a new table
            Table table = new Table();

            //// Create the table properties
            TableProperties tblProperties = new TableProperties();

            TableWidth tableWidth = new TableWidth()
            {
                Width = "5000", Type = TableWidthUnitValues.Pct
            };
            TableStyle tableStyle = new TableStyle()
            {
                Val = "TableGrid"
            };

            tblProperties.Append(tableStyle, tableWidth);

            //// Create Table Borders
            TableBorders tblBorders = new TableBorders();

            TopBorder topBorder = new TopBorder();

            topBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            topBorder.Color = "000000";
            tblBorders.AppendChild(topBorder);

            BottomBorder bottomBorder = new BottomBorder();

            bottomBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            bottomBorder.Color = "000000";
            tblBorders.AppendChild(bottomBorder);

            RightBorder rightBorder = new RightBorder();

            rightBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            rightBorder.Color = "000000";
            tblBorders.AppendChild(rightBorder);

            LeftBorder leftBorder = new LeftBorder();

            leftBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            leftBorder.Color = "000000";
            tblBorders.AppendChild(leftBorder);

            InsideHorizontalBorder insideHBorder = new InsideHorizontalBorder();

            insideHBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            insideHBorder.Color = "000000";
            tblBorders.AppendChild(insideHBorder);

            InsideVerticalBorder insideVBorder = new InsideVerticalBorder();

            insideVBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            insideVBorder.Color = "000000";
            tblBorders.AppendChild(insideVBorder);

            //// Add the table borders to the properties
            tblProperties.AppendChild(tblBorders);

            //// Add the table properties to the table
            table.AppendChild(tblProperties);

            //// Get the number of columns and rows in the DataTable
            int iColCount = dataTable.Columns.Count;
            int iRowCount = dataTable.Rows.Count;

            //// If there are rows....
            if (iRowCount > 0)
            {
                //// Create a new Table row
                TableRow trColumns = new TableRow();

                for (int i = 0; i < iColCount; i++)
                {
                    //// Add a cell for each column
                    TableCell tc = new TableCell(new Paragraph(new Run(new Text(dataTable.Columns[i].ToString()))));

                    //// Add the cells to the row
                    trColumns.Append(tc);
                }

                //// Add the row to the table
                table.AppendChild(trColumns);

                foreach (DataRow dr in dataTable.Rows)
                {
                    //// Create a new Table row
                    TableRow trDataRow = new TableRow();

                    for (int i = 0; i < iColCount; i++)
                    {
                        if (!Convert.IsDBNull(dr[i]))
                        {
                            //// Add a cell for each column in the row
                            TableCell tc = new TableCell(new Paragraph(new Run(new Text(dr[i].ToString()))));

                            //// Add the cells to the row
                            trDataRow.Append(tc);
                        }
                        else
                        {
                            //// Add an empty cell for each column in the row
                            TableCell tc = new TableCell(new Paragraph(new Run(new Text(""))));

                            //// Add the cells to the row
                            trDataRow.Append(tc);
                        }
                    }

                    //// Add the rows to the table
                    table.AppendChild(trDataRow);
                }
            }

            //// Return the Table
            return(table);
        }
Ejemplo n.º 13
0
        private static Table CreateTable2(AuditDetailInfo item)
        {
            int    index     = 1;
            bool   IsVAT     = false;
            double VATNumber = 0;

            foreach (QuoteAuditInfo Quoteinfo in item.Quotes)
            {
                IsVAT     = Quoteinfo.IsVAT;
                VATNumber = Quoteinfo.VATNumber;
            }
            //prepare ITEMs
            List <string>         headers = new List <string>();
            List <List <string> > items   = new List <List <string> >();

            headers.Add("STT");
            headers.Add("Mặt hàng & dịch vụ");
            headers.Add("ĐVT");
            headers.Add("SL");
            headers.Add("Đơn giá");
            headers.Add("Thuế VAT " + VATNumber + "%");
            headers.Add("Đơn giá (Đã bao gồm thuế " + VATNumber + "% VAT )(VNĐ)");
            headers.Add("Thành tiền (VNĐ)");

            int[] widths = { 1000, 2700, 1300, 1300, 1300, 1300, 1300, 1300 };

            foreach (QuoteAuditInfo Quoteinfo in item.Quotes)
            {
                foreach (ItemInfo record in Quoteinfo.Items)
                {
                    double        VATcost = (record.ItemPrice * VATNumber) / 100;
                    List <string> row     = new List <string>();
                    row.Add(index.ToString());
                    row.Add(record.ItemName);
                    row.Add(record.ItemUnit);
                    row.Add(record.Amount.ToString());
                    row.Add(string.Format("{0:0,0}", record.ItemPrice).Replace(",", "."));
                    row.Add(string.Format("{0:0,0}", VATcost).Replace(",", "."));
                    row.Add(string.Format("{0:0,0}", (record.ItemPrice + VATcost)).Replace(",", "."));
                    row.Add(string.Format("{0:0,0}", ((record.ItemPrice + VATcost) * record.Amount)).Replace(",", "."));
                    items.Add(row);
                    index++;
                }
            }


            //// Create a new table
            Table tbl = new Table();

            //// Create the table properties
            TableProperties    tblProperties = new TableProperties();
            TableJustification just          = new TableJustification();

            just.Val = TableRowAlignmentValues.Center;
            //// Create Table Borders
            TableBorders tblBorders = new TableBorders();
            TopBorder    topBorder  = new TopBorder();

            topBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            topBorder.Color = "000000";
            tblBorders.AppendChild(topBorder);
            BottomBorder bottomBorder = new BottomBorder();

            bottomBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            bottomBorder.Color = "000000";
            tblBorders.AppendChild(bottomBorder);
            RightBorder rightBorder = new RightBorder();

            rightBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            rightBorder.Color = "000000";
            tblBorders.AppendChild(rightBorder);
            LeftBorder leftBorder = new LeftBorder();

            leftBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            leftBorder.Color = "000000";
            tblBorders.AppendChild(leftBorder);
            InsideHorizontalBorder insideHBorder = new InsideHorizontalBorder();

            insideHBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            insideHBorder.Color = "000000";
            tblBorders.AppendChild(insideHBorder);
            InsideVerticalBorder insideVBorder = new InsideVerticalBorder();

            insideVBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            insideVBorder.Color = "000000";
            tblBorders.AppendChild(insideVBorder);
            //// Add the table borders to the properties
            tblProperties.AppendChild(tblBorders);
            tblProperties.AppendChild(just);
            //// Add the table properties to the table
            tbl.AppendChild(tblProperties);
            //// Add a cell to each column in the row
            ///
            List <TableCell> headerCells = new List <TableCell>();
            TableCell        tcName1;

            foreach (string itemHeaders in headers)
            {
                tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                {
                    Val = JustificationValues.Right
                }), new Run(Bold(), new Text(itemHeaders))));
                tcName1.Append(new TableCellProperties(
                                   new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "3000"
                }));
                headerCells.Add(tcName1);
            }
            //// Create a new row
            TableRow tr = new TableRow();

            tr.Append(headerCells.ToArray());
            tbl.AppendChild(tr);
            List <TableCell> dataCells = new List <TableCell>();

            foreach (List <string> rowItems in items)
            {
                dataCells = new List <TableCell>();
                foreach (string data in rowItems)
                {
                    tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                    {
                        Val = JustificationValues.Right
                    }), new Run(Bold(), new Text(data))));
                    tcName1.Append(new TableCellProperties(
                                       new TableCellWidth()
                    {
                        Type = TableWidthUnitValues.Dxa, Width = "3000"
                    }));
                    dataCells.Add(tcName1);
                }
                TableRow tr1 = new TableRow();
                tr1.Append(dataCells.ToArray());
                tbl.AppendChild(tr1);
            }
            TableCellProperties cellOneProperties = new TableCellProperties();

            return(tbl);
        }
Ejemplo n.º 14
0
        private static Table GenerateSeniorityTable(IEnumerable <SeniorityViewModel> seniorityList, SeniorityListRecord seniorityRecord)
        {
            try
            {
                // create an empty table
                Table table = new Table();

                TableProperties tableProperties1 = new TableProperties();
                TableStyle      tableStyle1      = new TableStyle()
                {
                    Val = "TableGrid"
                };
                TableWidth tableWidth1 = new TableWidth()
                {
                    Width = "0", Type = TableWidthUnitValues.Auto
                };

                TableLook 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);

                table.AppendChild(tableProperties1);

                // setup headers
                TableRow tableRow1 = new TableRow();

                TableRowProperties rowProperties = new TableRowProperties();

                rowProperties.AppendChild(new TableRowHeight()
                {
                    Val = 200, HeightType = HeightRuleValues.AtLeast
                });
                rowProperties.AppendChild(new TableHeader()
                {
                    Val = OnOffOnlyValues.On
                });

                tableRow1.AppendChild(rowProperties);

                // add columns
                tableRow1.AppendChild(SetupHeaderCell("Block", "800", true));
                tableRow1.AppendChild(SetupHeaderCell("Equip ID", "1000"));
                tableRow1.AppendChild(SetupHeaderCell("Working Now", "850", true));
                tableRow1.AppendChild(SetupHeaderCell("Last Called", "850", true));
                tableRow1.AppendChild(SetupHeaderCell("Company Name", "3000"));
                tableRow1.AppendChild(SetupHeaderCell("Year/Make/Model/Size", "3000"));
                tableRow1.AppendChild(SetupHeaderCell(seniorityRecord.YearMinus1, "1000", true));
                tableRow1.AppendChild(SetupHeaderCell(seniorityRecord.YearMinus2, "1000", true));
                tableRow1.AppendChild(SetupHeaderCell(seniorityRecord.YearMinus3, "1000", true));
                tableRow1.AppendChild(SetupHeaderCell("YTD", "1000", true));
                tableRow1.AppendChild(SetupHeaderCell("Seniority", "1000", true));
                tableRow1.AppendChild(SetupHeaderCell("Yrs Reg", "1000", true));

                table.AppendChild(tableRow1);

                // add rows for each record
                foreach (SeniorityViewModel seniority in seniorityList)
                {
                    TableRow tableRowEquipment = new TableRow();

                    TableRowProperties equipmentRowProperties = new TableRowProperties();
                    equipmentRowProperties.AppendChild(new TableRowHeight()
                    {
                        Val = 200, HeightType = HeightRuleValues.AtLeast
                    });
                    tableRowEquipment.AppendChild(equipmentRowProperties);

                    // add equipment data
                    tableRowEquipment.AppendChild(SetupCell(seniority.Block, true));
                    tableRowEquipment.AppendChild(SetupCell(seniority.EquipmentCode));
                    tableRowEquipment.AppendChild(SetupCell(seniority.IsHired, true));
                    tableRowEquipment.AppendChild(SetupCell(seniority.LastCalled, true));
                    tableRowEquipment.AppendChild(SetupCell(seniority.OwnerName));
                    tableRowEquipment.AppendChild(SetupCell(seniority.YearMakeModelSize));
                    tableRowEquipment.AppendChild(SetupCell(seniority.HoursYearMinus1, true));
                    tableRowEquipment.AppendChild(SetupCell(seniority.HoursYearMinus2, true));
                    tableRowEquipment.AppendChild(SetupCell(seniority.HoursYearMinus3, true));
                    tableRowEquipment.AppendChild(SetupCell(seniority.YtdHours, true));
                    tableRowEquipment.AppendChild(SetupCell(seniority.Seniority, true));
                    tableRowEquipment.AppendChild(SetupCell(seniority.YearsRegistered, true));

                    table.AppendChild(tableRowEquipment);
                }

                return(table);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Ejemplo n.º 15
0
        internal static Tuple <Table, TableLook> CreateTable(Models.Document document, Models.Table table, ContextModel context, OpenXmlPart documentPart, IFormatProvider formatProvider)
        {
            Table wordTable = new Table();

            TableProperties wordTableProperties = new TableProperties();
            var             tableLook           = new TableLook()
            {
                FirstRow         = OnOffValue.FromBoolean(false),
                LastRow          = OnOffValue.FromBoolean(false),
                FirstColumn      = OnOffValue.FromBoolean(false),
                LastColumn       = OnOffValue.FromBoolean(false),
                NoHorizontalBand = OnOffValue.FromBoolean(false),
                NoVerticalBand   = OnOffValue.FromBoolean(false)
            };

            wordTableProperties.AppendChild(tableLook);
            //The type must be Dxa, if the value is set to Pct : the open xml engine will ignored it !
            wordTableProperties.TableIndentation = new TableIndentation()
            {
                Width = table.TableIndentation.Width, Type = TableWidthUnitValues.Dxa
            };
            wordTable.AppendChild(wordTableProperties);

            if (table.Borders != null)
            {
                TableBorders borders = table.Borders.Render();

                wordTableProperties.AppendChild(borders);
            }

            // add column width definitions
            if (table.ColsWidth != null)
            {
                wordTable.AppendChild(new TableLayout()
                {
                    Type = TableLayoutValues.Fixed
                });

                TableGrid tableGrid = new TableGrid();
                foreach (int width in table.ColsWidth)
                {
                    tableGrid.AppendChild(new GridColumn()
                    {
                        Width = width.ToString(CultureInfo.InvariantCulture)
                    });
                }
                wordTable.AppendChild(tableGrid);
            }

            if (table.TableWidth != null)
            {
                wordTable.AppendChild(new TableWidth()
                {
                    Width = table.TableWidth.Width, Type = table.TableWidth.Type.ToOOxml()
                });
            }

            // add header row
            if (table.HeaderRow != null)
            {
                wordTable.AppendChild(table.HeaderRow.Render(document, wordTable, context, documentPart, true, false, formatProvider));

                tableLook.FirstRow = OnOffValue.FromBoolean(true);
            }

            return(new Tuple <Table, TableLook>(wordTable, tableLook));
        }
Ejemplo n.º 16
0
        private static Table genTable(List <CalcCore.CalcValueBase> calcVals, MainDocumentPart mainPart)
        {
            Table tableOfInputs = new Table();
            var   tableGrid     = new TableGrid();

            tableGrid.AppendChild(new GridColumn());
            tableGrid.AppendChild(new GridColumn());
            tableGrid.AppendChild(new GridColumn());
            tableOfInputs.AppendChild(tableGrid);
            var tableProps = new TableProperties();

            tableProps.AppendChild(new TableLayout()
            {
                Type = TableLayoutValues.Fixed
            });
            tableProps.AppendChild(new TableWidth()
            {
                Width = "9000", Type = TableWidthUnitValues.Dxa
            });
            tableProps.AppendChild(new TableBorders()
            {
                InsideHorizontalBorder = new InsideHorizontalBorder()
                {
                    Color = "c0c0c0", Size = 4, Val = BorderValues.Single
                }
            });
            tableProps.AppendChild(new TableBorders()
            {
                BottomBorder = new BottomBorder()
                {
                    Color = "c0c0c0", Size = 4, Val = BorderValues.Single
                }
            });
            tableProps.AppendChild(new TableBorders()
            {
                TopBorder = new TopBorder()
                {
                    Color = "c0c0c0", Size = 4, Val = BorderValues.Single
                }
            });
            //tableProps.AppendChild(new TableBorders() { LeftBorder = new LeftBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } });
            //tableProps.AppendChild(new TableBorders() { InsideVerticalBorder = new InsideVerticalBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } });
            //tableProps.AppendChild(new TableBorders() { RightBorder = new RightBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } });

            tableOfInputs.AppendChild(tableProps);

            foreach (var item in calcVals)
            {
                TableRow  row   = new TableRow();
                var       para1 = new Paragraph();
                TableCell cell1 = new TableCell();

                // insert symbol as image
                var parser = new TexFormulaParser();
                if (item.Symbol != "")
                {
                    TexFormula formulaToParse = new TexFormula();
                    try
                    {
                        parser         = new TexFormulaParser();
                        formulaToParse = parser.Parse(item.Symbol);
                    }
                    catch (Exception)
                    {
                        parser         = new TexFormulaParser();
                        formulaToParse = parser.Parse("Error in LaTeX string...");
                    }
                    var       formulaImage = formulaToParse.RenderToPng(100, 0, 0, "Franklin Gothic Book");
                    ImagePart imagePart    = mainPart.AddImagePart(ImagePartType.Png);
                    using (var stream = new MemoryStream(formulaImage))
                    {
                        imagePart.FeedData(stream);
                        var img = new BitmapImage();
                        img.BeginInit();
                        img.StreamSource = stream;
                        img.CacheOption  = BitmapCacheOption.OnLoad;
                        img.EndInit();
                        img.Freeze();
                        var paraImage = AddImageToBody(mainPart.GetIdOfPart(imagePart), img.Width * 2.54 / 600, img.Height * 2.54 / 600);
                        para1.AppendChild(new Run(paraImage));
                    }
                }
                else
                {
                    para1.AppendChild(new Run(new Text(" ")));
                }


                //var myMath = new M.OfficeMath(new M.Run(new M.Text(item.Symbol) { Space = SpaceProcessingModeValues.Preserve }));
                //para1.AppendChild(myMath);
                //para1.AppendChild(new Run(new Text(" ") { Space = SpaceProcessingModeValues.Preserve }));

                cell1.Append(para1);
                cell1.Append(new TableCellProperties(new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "1200"
                }));
                var       para2 = new Paragraph(new Run(new Text(item.Name)));
                TableCell cell2 = new TableCell();
                cell2.AppendChild(para2);
                cell2.Append(new TableCellProperties(new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "6100"
                }));
                var para3 = new Paragraph();
                if (item.Type == CalcValueType.DOUBLE)
                {
                    // insert symbol as image
                    parser = new TexFormulaParser();
                    string toRender = item.ValueAsString + item.Unit;
                    if (toRender != "")
                    {
                        TexFormula formulaToParse = new TexFormula();
                        try
                        {
                            parser         = new TexFormulaParser();
                            formulaToParse = parser.Parse(toRender);
                        }
                        catch (Exception)
                        {
                            parser         = new TexFormulaParser();
                            formulaToParse = parser.Parse("Error in LaTeX string...");
                        }
                        var       formulaImage = formulaToParse.RenderToPng(100, 0, 0, "Franklin Gothic Book");
                        ImagePart imagePart    = mainPart.AddImagePart(ImagePartType.Png);
                        using (var stream = new MemoryStream(formulaImage))
                        {
                            imagePart.FeedData(stream);
                            var img = new BitmapImage();
                            img.BeginInit();
                            img.StreamSource = stream;
                            img.CacheOption  = BitmapCacheOption.OnLoad;
                            img.EndInit();
                            img.Freeze();
                            var paraImage = AddImageToBody(mainPart.GetIdOfPart(imagePart), img.Width * 2.54 / 600, img.Height * 2.54 / 600);
                            para3.AppendChild(new Run(paraImage));
                        }
                    }
                    else
                    {
                        para3.AppendChild(new Run(new Text(" ")));
                    }
                    //myMath = new DocumentFormat.OpenXml.Math.OfficeMath(new M.Run(new M.Text(item.ValueAsString + item.Unit) { Space = SpaceProcessingModeValues.Preserve }));
                    //para3.AppendChild(myMath);
                    //para3.AppendChild(new Run(new Text(" ") { Space = SpaceProcessingModeValues.Preserve }));
                }
                else if (item.Type == CalcValueType.SELECTIONLIST)
                {
                    para3.AppendChild(new Run(new Text(item.ValueAsString)));
                }
                else
                {
                    cell2.AppendChild(new Paragraph(new Run(new Text(item.ValueAsString))));
                }
                TableCell cell3 = new TableCell();
                cell3.Append(para3);
                cell3.Append(new TableCellProperties(new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "1700"
                }));
                row.Append(cell1, cell2, cell3);
                tableOfInputs.AppendChild(row);
            }
            return(tableOfInputs);
        }
Ejemplo n.º 17
0
        private static Table genFormulaeTable(List <Formula> formulae, MainDocumentPart mainPart)
        {
            Table tableOfInputs = new Table();
            var   tableGrid     = new TableGrid();

            tableGrid.AppendChild(new GridColumn());
            tableGrid.AppendChild(new GridColumn());
            tableGrid.AppendChild(new GridColumn());
            tableOfInputs.AppendChild(tableGrid);
            var tableProps = new TableProperties();

            tableProps.AppendChild(new TableLayout()
            {
                Type = TableLayoutValues.Fixed
            });
            tableProps.AppendChild(new TableWidth()
            {
                Width = "9000", Type = TableWidthUnitValues.Dxa
            });
            tableProps.AppendChild(new TableBorders()
            {
                InsideHorizontalBorder = new InsideHorizontalBorder()
                {
                    Color = "c0c0c0", Size = 4, Val = BorderValues.Single
                }
            });
            tableProps.AppendChild(new TableBorders()
            {
                BottomBorder = new BottomBorder()
                {
                    Color = "c0c0c0", Size = 4, Val = BorderValues.Single
                }
            });
            tableProps.AppendChild(new TableBorders()
            {
                TopBorder = new TopBorder()
                {
                    Color = "c0c0c0", Size = 4, Val = BorderValues.Single
                }
            });
            //tableProps.AppendChild(new TableBorders() { LeftBorder = new LeftBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } });
            //tableProps.AppendChild(new TableBorders() { InsideVerticalBorder = new InsideVerticalBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } });
            //tableProps.AppendChild(new TableBorders() { RightBorder = new RightBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } });
            tableOfInputs.AppendChild(tableProps);

            foreach (var item in formulae)
            {
                TableRow row  = new TableRow();
                var      para = new Paragraph();
                para.AppendChild((new Run(new Text(item.Ref))));
                TableCell cell1 = new TableCell();
                cell1.Append(para);
                cell1.Append(new TableCellProperties(new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "1200"
                }));
                TableCell cell2 = new TableCell();
                cell2.Append(new TableCellProperties(new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "6100"
                }));
                cell2.AppendChild(new Paragraph(new Run(new Text(item.Narrative))));
                //foreach (var formula in item.Expression)
                //{
                //    var mathPara = new Paragraph();
                //    var myMath = new M.OfficeMath(new M.Run(new M.Text(formula + Environment.NewLine) { Space = SpaceProcessingModeValues.Preserve }));
                //    mathPara.AppendChild(myMath);
                //    mathPara.AppendChild(new Run(new Text(" ") { Space = SpaceProcessingModeValues.Preserve }));
                //    cell2.AppendChild(mathPara);
                //}
                foreach (var formula in item.Expression)
                {
                    if (formula != "")
                    {
                        TexFormula formulaToParse = new TexFormula();
                        try
                        {
                            var parser = new TexFormulaParser();
                            formulaToParse = parser.Parse(formula);
                        }
                        catch (Exception)
                        {
                            var parser = new TexFormulaParser();
                            formulaToParse = parser.Parse("Error in LaTeX string...");
                        }
                        var test = formulaToParse.GetRenderer(TexStyle.Script, 100, "Franklin Gothic Book");
                        if (test.RenderSize.Width > 0 && test.RenderSize.Height > 0)
                        {
                            var       formulaImage = formulaToParse.RenderToPng(100, 0, 0, "Franklin Gothic Book");
                            ImagePart imagePart    = mainPart.AddImagePart(ImagePartType.Png);
                            using (var stream = new MemoryStream(formulaImage))
                            {
                                imagePart.FeedData(stream);
                                var img = new BitmapImage();
                                img.BeginInit();
                                img.StreamSource = stream;
                                img.CacheOption  = BitmapCacheOption.OnLoad;
                                img.EndInit();
                                img.Freeze();
                                var paraImage = AddImageToBody(mainPart.GetIdOfPart(imagePart), img.Width * 2.54 / 600, img.Height * 2.54 / 600);
                                cell2.AppendChild(new Paragraph(new Run(paraImage)));
                            }
                        }

                        GC.WaitForPendingFinalizers();
                    }
                    //var myMath = new M.OfficeMath(new M.Run(new M.Text(formula + Environment.NewLine) { Space = SpaceProcessingModeValues.Preserve }));
                    //mathPara.AppendChild(myMath);
                    //mathPara.AppendChild(new Run(new Text(" ") { Space = SpaceProcessingModeValues.Preserve }));
                    //cell2.AppendChild(mathPara);
                }

                if (item.Image != null)
                {
                    ImagePart        imagePart = mainPart.AddImagePart(ImagePartType.Png);
                    var              tempFile  = Path.GetTempFileName();
                    PngBitmapEncoder png       = new PngBitmapEncoder();
                    //CHANGEBITMAP
                    //png.Frames.Add(BitmapFrame.Create(item.Image));
                    var width  = Math.Min(10d, item.Image.Width * 2.54 / 96);
                    var height = ((double)item.Image.Height / (double)item.Image.Width) * width;
                    using (SkiaSharp.SKWStream stm = new SkiaSharp.SKFileWStream(tempFile))
                    {
                        item.Image.Encode(stm, SkiaSharp.SKEncodedImageFormat.Png, 0);
                    }
                    using (FileStream stream = new FileStream(tempFile, FileMode.Open))
                    {
                        imagePart.FeedData(stream);
                    }
                    var paraImage = AddImageToBody(mainPart.GetIdOfPart(imagePart), width, height);
                    cell2.AppendChild(new Paragraph(new Run(paraImage)));
                }

                TableCell cell3 = new TableCell();
                cell3.Append(new Paragraph(new Run(new Text(item.Conclusion))));
                cell3.Append(new TableCellProperties(new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "1700"
                }));

                row.Append(cell1, cell2, cell3);
                tableOfInputs.AppendChild(row);
            }
            return(tableOfInputs);
        }
Ejemplo n.º 18
0
        public IActionResult AddTable()
        {
            using (var stream = new MemoryStream())
            {
                using (var wordDocument = WordprocessingDocument.Create(stream,
                                                                        WordprocessingDocumentType.Document, true))
                {
                    wordDocument.AddMainDocumentPart();

                    var document = new Document();
                    var body     = new Body();

                    var table = new Table();

                    var tableWidth = new TableWidth()
                    {
                        Width = "5000", Type = TableWidthUnitValues.Pct
                    };
                    var borderColor = "FF8000";

                    var tableProperties = new TableProperties();
                    var tableBorders    = new TableBorders();

                    var topBorder = new TopBorder();
                    topBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
                    topBorder.Color = borderColor;

                    var bottomBorder = new BottomBorder();
                    bottomBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
                    bottomBorder.Color = borderColor;

                    var rightBorder = new RightBorder();
                    rightBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
                    rightBorder.Color = borderColor;

                    var leftBorder = new LeftBorder();
                    leftBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
                    leftBorder.Color = borderColor;

                    var insideHorizontalBorder = new InsideHorizontalBorder();
                    insideHorizontalBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
                    insideHorizontalBorder.Color = borderColor;

                    var insideVerticalBorder = new InsideVerticalBorder();
                    insideVerticalBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
                    insideVerticalBorder.Color = borderColor;

                    tableBorders.AppendChild(topBorder);
                    tableBorders.AppendChild(bottomBorder);
                    tableBorders.AppendChild(rightBorder);
                    tableBorders.AppendChild(leftBorder);
                    tableBorders.AppendChild(insideHorizontalBorder);
                    tableBorders.AppendChild(insideVerticalBorder);

                    tableProperties.Append(tableWidth);
                    tableProperties.AppendChild(tableBorders);

                    table.AppendChild(tableProperties);

                    //////////

                    var row1        = new TableRow();
                    var cell11      = new TableCell();
                    var paragraph11 = new Paragraph(new Run(new Text("Luis")));

                    cell11.Append(paragraph11);
                    row1.Append(cell11);
                    /////

                    var cell12          = new TableCell();
                    var paragraph12     = new Paragraph();
                    var run12           = new Run();
                    var runProperties12 = new RunProperties();
                    runProperties12.Bold = new Bold();

                    run12.Append(runProperties12);
                    run12.Append(new Text("400"));
                    paragraph12.Append(run12);
                    cell12.Append(paragraph12);
                    row1.Append(cell12);
                    /////

                    table.Append(row1);

                    var random = new Random();

                    for (int i = 1; i < 5; i++)
                    {
                        var row = new TableRow();

                        var cell1     = new TableCell();
                        var paragraph = new Paragraph(new Run(new Text($"Employee {i}")));
                        cell1.Append(paragraph);

                        var cell2                = new TableCell();
                        var paragraph2           = new Paragraph();
                        var paragraphProperties2 = new ParagraphProperties();
                        paragraphProperties2.Justification = new Justification()
                        {
                            Val = JustificationValues.Center
                        };
                        paragraph2.Append(paragraphProperties2);
                        paragraph2.Append(new Run(new Text(random.Next(100, 500).ToString())));
                        cell2.Append(paragraph2);

                        row.Append(cell1);
                        row.Append(cell2);

                        table.Append(row);
                    }

                    body.Append(table);

                    document.Append(body);
                    wordDocument.MainDocumentPart.Document = document;
                    wordDocument.Close();
                }

                return(File(stream.ToArray(), docxMIMEType,
                            "Word Document Table Example.docx"));
            }
        }
Ejemplo n.º 19
0
        public void CreateReport(Stream stream, List <ReportingArticle> articles)
        {
            using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(stream, WordprocessingDocumentType.Document, true))
            {
                // Add a main document part.
                MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();

                // Create the document structure and add some text.
                mainPart.Document = new Document();
                var docBody = mainPart.Document.AppendChild(new Body());

                Table table = new Table();

                TableProperties tblProperties = new TableProperties();
                TableBorders    tblBorders    = new TableBorders();

                TopBorder topBorder = new TopBorder();
                topBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
                topBorder.Color = "CC0000";
                tblBorders.AppendChild(topBorder);

                BottomBorder bottomBorder = new BottomBorder();
                bottomBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
                bottomBorder.Color = "CC0000";
                tblBorders.AppendChild(bottomBorder);

                RightBorder rightBorder = new RightBorder();
                rightBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
                rightBorder.Color = "CC0000";
                tblBorders.AppendChild(rightBorder);

                LeftBorder leftBorder = new LeftBorder();
                leftBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
                leftBorder.Color = "CC0000";
                tblBorders.AppendChild(leftBorder);

                InsideHorizontalBorder insideHBorder = new InsideHorizontalBorder();
                insideHBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
                insideHBorder.Color = "CC0000";
                tblBorders.AppendChild(insideHBorder);

                InsideVerticalBorder insideVBorder = new InsideVerticalBorder();
                insideVBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
                insideVBorder.Color = "CC0000";
                tblBorders.AppendChild(insideVBorder);

                //// Add the table borders to the properties
                tblProperties.AppendChild(tblBorders);
                table.AppendChild(tblProperties);

                TableRow tr1 = new TableRow();

                TableCell     tc11 = new TableCell();
                Paragraph     p11  = new Paragraph();
                Run           r11  = new Run();
                RunProperties rp11 = new RunProperties();
                rp11.Bold = new Bold();
                r11.Append(rp11);
                r11.Append(new Text("Autor"));
                p11.Append(r11);

                tc11.Append(p11);
                tr1.Append(tc11);

                TableCell     tc13 = new TableCell();
                Paragraph     p13  = new Paragraph();
                Run           r13  = new Run();
                RunProperties rp13 = new RunProperties();
                rp13.Bold = new Bold();
                r13.Append(rp13);
                r13.Append(new Text("Tytuł publikacji"));
                p13.Append(r13);

                tc13.Append(p13);
                tr1.Append(tc13);

                TableCell tc12 = new TableCell();
                Paragraph p12  = new Paragraph();

                Run           r12  = new Run();
                RunProperties rp12 = new RunProperties();
                rp12.Bold = new Bold();
                r12.Append(rp12);
                r12.Append(new Text("Data"));
                p12.Append(r12);
                tc12.Append(p12);

                tr1.Append(tc12);
                table.Append(tr1);

                for (int i = 0; i < articles.Count; i++)
                {
                    TableRow  tr_i  = new TableRow();
                    TableCell tr_i1 = new TableCell();
                    Paragraph pi1   = new Paragraph(new Run(new Text(articles[i].Author)));
                    tr_i1.Append(pi1);
                    tr_i.Append(tr_i1);

                    TableCell tr_i3 = new TableCell();
                    Paragraph pi3   = new Paragraph(new Run(new Text(articles[i].Title)));
                    tr_i3.Append(pi3);
                    tr_i.Append(tr_i3);

                    TableCell tr_i2 = new TableCell();
                    Paragraph pi2   = new Paragraph(new Run(new Text(articles[i].Date.ToLocalTime().ToString("dd-MM-yyyy"))));
                    tr_i2.Append(pi2);
                    tr_i.Append(tr_i2);
                    table.Append(tr_i);
                }

                // Add your table to docx body
                docBody.Append(table);

                Paragraph           summaryPar = new Paragraph();
                ParagraphProperties pp22       = new ParagraphProperties();
                pp22.Justification = new Justification()
                {
                    Val = JustificationValues.Center
                };
                summaryPar.Append(pp22);
                summaryPar.Append(new Run(new Text("Razem artykułów: " + articles.Count.ToString())));
                docBody.Append(summaryPar);
                wordDocument.Save();
            }
        }
        public static byte[] HtmlToWordMethod(String html)
        {
            string       color    = "#000";
            string       width    = "5000";
            const string filename = "test.docx";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            using (MemoryStream generatedDocument = new MemoryStream())
            {
                using (WordprocessingDocument package = WordprocessingDocument.Create(
                           generatedDocument, WordprocessingDocumentType.Document))
                {
                    MainDocumentPart mainPart = package.MainDocumentPart;
                    if (mainPart == null)
                    {
                        mainPart = package.AddMainDocumentPart();
                        new Document(new Body()).Save(mainPart);
                    }

                    //HtmlConverter converter = new HtmlConverter(mainPart);
                    Body body = mainPart.Document.Body;

                    //var paragraphs = converter.Parse(html);
                    //for (int i = 0; i < paragraphs.Count; i++)
                    //{
                    //    body.Append(paragraphs[i]);
                    //}
                    Table table = new Table();
                    //// Create the table properties

                    TableProperties tblProperties = new TableProperties();



                    //// Create Table Borders

                    TableBorders tblBorders = new TableBorders();



                    TopBorder topBorder = new TopBorder();

                    topBorder.Val = new EnumValue <BorderValues>(BorderValues.Thick);

                    topBorder.Color = color;

                    tblBorders.AppendChild(topBorder);



                    BottomBorder bottomBorder = new BottomBorder();

                    bottomBorder.Val = new EnumValue <BorderValues>(BorderValues.Thick);

                    bottomBorder.Color = color;

                    tblBorders.AppendChild(bottomBorder);



                    RightBorder rightBorder = new RightBorder();

                    rightBorder.Val = new EnumValue <BorderValues>(BorderValues.Thick);

                    rightBorder.Color = color;

                    tblBorders.AppendChild(rightBorder);



                    LeftBorder leftBorder = new LeftBorder();

                    leftBorder.Val = new EnumValue <BorderValues>(BorderValues.Thick);

                    leftBorder.Color = color;

                    tblBorders.AppendChild(leftBorder);



                    InsideHorizontalBorder insideHBorder = new InsideHorizontalBorder();

                    insideHBorder.Val = new EnumValue <BorderValues>(BorderValues.Thick);

                    insideHBorder.Color = color;

                    tblBorders.AppendChild(insideHBorder);



                    InsideVerticalBorder insideVBorder = new InsideVerticalBorder();

                    insideVBorder.Val = new EnumValue <BorderValues>(BorderValues.Thick);

                    insideVBorder.Color = color;

                    tblBorders.AppendChild(insideVBorder);



                    //// Add the table borders to the properties

                    tblProperties.AppendChild(tblBorders);
                    TableWidth tableWidth = new TableWidth()
                    {
                        Width = width, Type = TableWidthUnitValues.Pct
                    };

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

                    tblProperties.AppendChild(tableStyle);
                    tblProperties.AppendChild(tableWidth);
                    //// Add the table properties to the table

                    table.AppendChild(tblProperties);

                    TableRow  tr1  = new TableRow();
                    TableCell tc11 = new TableCell();
                    Paragraph p11  = new Paragraph(new Run(new Text("ID")));
                    tc11.Append(p11);
                    tr1.Append(tc11);

                    TableCell     tc12 = new TableCell();
                    Paragraph     p12  = new Paragraph();
                    Run           r12  = new Run();
                    RunProperties rp12 = new RunProperties();
                    rp12.Bold = new Bold();
                    r12.Append(rp12);
                    r12.Append(new Text("Nice"));
                    p12.Append(r12);
                    tc12.Append(p12);

                    tr1.Append(tc12);
                    table.Append(tr1);

                    TableRow tr2 = new TableRow();


                    TableCell tc21 = new TableCell();
                    Paragraph p21  = new Paragraph(new Run(new Text("Name")));
                    tc21.Append(p21);
                    tr2.Append(tc21);

                    TableCell           tc22 = new TableCell();
                    Paragraph           p22  = new Paragraph();
                    ParagraphProperties pp22 = new ParagraphProperties();
                    pp22.Justification = new Justification()
                    {
                        Val = JustificationValues.Center
                    };
                    p22.Append(pp22);
                    p22.Append(new Run(new Text("Table")));
                    tc22.Append(p22);

                    tr2.Append(tc22);
                    table.Append(tr2);

                    // Add your table to docx body
                    body.Append(table);


                    //Save
                    mainPart.Document.Save();
                }

                return(generatedDocument.ToArray());
            }
        }
Ejemplo n.º 21
0
        private static Table CreateTablec34(List <string> headers, List <List <string> > items, double Totalcost)
        {
            int[] widths = { 900, 3600, 900, 900, 1200, 1200, 1500, 900 };



            //// Create a new table
            Table tbl = new Table();

            //// Create the table properties
            TableProperties    tblProperties = new TableProperties();
            TableJustification just          = new TableJustification();

            just.Val = TableRowAlignmentValues.Center;
            //// Create Table Borders
            TableBorders tblBorders = new TableBorders();
            TopBorder    topBorder  = new TopBorder();

            topBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            topBorder.Color = "000000";
            tblBorders.AppendChild(topBorder);
            BottomBorder bottomBorder = new BottomBorder();

            bottomBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            bottomBorder.Color = "000000";
            tblBorders.AppendChild(bottomBorder);
            RightBorder rightBorder = new RightBorder();

            rightBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            rightBorder.Color = "000000";
            tblBorders.AppendChild(rightBorder);
            LeftBorder leftBorder = new LeftBorder();

            leftBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            leftBorder.Color = "000000";
            tblBorders.AppendChild(leftBorder);
            InsideHorizontalBorder insideHBorder = new InsideHorizontalBorder();

            insideHBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            insideHBorder.Color = "000000";
            tblBorders.AppendChild(insideHBorder);
            InsideVerticalBorder insideVBorder = new InsideVerticalBorder();

            insideVBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            insideVBorder.Color = "000000";
            tblBorders.AppendChild(insideVBorder);
            //// Add the table borders to the properties
            tblProperties.AppendChild(tblBorders);
            tblProperties.AppendChild(just);
            //// Add the table properties to the table
            tbl.AppendChild(tblProperties);
            //// Add a cell to each column in the row
            ///
            List <TableCell> headerCells = new List <TableCell>();
            TableCell        tcName1;
            int i = 0;

            foreach (string itemHeaders in headers)
            {
                tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                {
                    Val = JustificationValues.Center
                }), new Run(FontTable(), new Text(itemHeaders))));
                tcName1.Append(new TableCellProperties(
                                   new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = widths[i].ToString()
                }));
                headerCells.Add(tcName1);
                i++;
            }
            //// Create a new row
            TableRow tr = new TableRow();

            tr.Append(headerCells.ToArray());
            tbl.AppendChild(tr);
            List <TableCell> dataCells = new List <TableCell>();

            i = 0;
            foreach (List <string> rowItems in items)
            {
                dataCells = new List <TableCell>();
                foreach (string data in rowItems)
                {
                    tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
                    {
                        Val = JustificationValues.Center
                    }), new Run(FontTable(), new Text(data))));
                    tcName1.Append(new TableCellProperties(
                                       new TableCellWidth()
                    {
                        Type = TableWidthUnitValues.Dxa, Width = widths[i].ToString()
                    }));
                    dataCells.Add(tcName1);
                }
                TableRow tr1 = new TableRow();
                tr1.Append(dataCells.ToArray());
                tbl.AppendChild(tr1);
                i++;
            }
            TableCellProperties cellOneProperties = new TableCellProperties();

            //if VAT
            tr        = new TableRow();
            dataCells = new List <TableCell>();
            tcName1   = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
            {
                Val = JustificationValues.Center
            }), new Run(FontTable(), new Text("TỔNG CỘNG "))));
            tcName1.Append(new TableCellProperties(
                               new TableCellWidth()
            {
                Type = TableWidthUnitValues.Dxa, Width = "800"
            }));
            cellOneProperties = new TableCellProperties();
            cellOneProperties.Append(new HorizontalMerge()
            {
                Val = MergedCellValues.Restart
            });
            tcName1.Append(cellOneProperties);
            dataCells.Add(tcName1);

            for (int loopindex = 1; loopindex < widths.Length - 2; loopindex++)
            {
                tcName1 = new TableCell(new Paragraph());
                tcName1.Append(new TableCellProperties(
                                   new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = widths[loopindex].ToString()
                }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Continue
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);
            }

            var TotalCostfm = string.Format("{0:0,0}", Totalcost).Replace(",", ".");

            tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
            {
                Val = JustificationValues.Left
            }), new Run(FontTable(), new Text(TotalCostfm))));
            tcName1.Append(new TableCellProperties(
                               new TableCellWidth()
            {
                Type = TableWidthUnitValues.Dxa, Width = "1500"
            }));
            cellOneProperties = new TableCellProperties();
            cellOneProperties.Append(new HorizontalMerge()
            {
                Val = MergedCellValues.Restart
            });
            tcName1.Append(cellOneProperties);
            dataCells.Add(tcName1);


            tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification()
            {
                Val = JustificationValues.Center
            }), new Run(FontTable(), new Text())));
            tcName1.Append(new TableCellProperties(
                               new TableCellWidth()
            {
                Type = TableWidthUnitValues.Dxa, Width = "900"
            }));
            cellOneProperties = new TableCellProperties();
            cellOneProperties.Append(new HorizontalMerge()
            {
                Val = MergedCellValues.Restart
            });
            tcName1.Append(cellOneProperties);
            dataCells.Add(tcName1);

            tr.Append(dataCells.ToArray());
            tbl.AppendChild(tr);

            return(tbl);
        }
Ejemplo n.º 22
0
        private static Table CreateTable(List <string> headers, List <List <string> > items)
        {
            //// Create a new table
            Table tbl = new Table();

            //// Create the table properties
            TableProperties    tblProperties = new TableProperties();
            TableJustification just          = new TableJustification();

            just.Val = TableRowAlignmentValues.Center;
            //// Create Table Borders
            TableBorders tblBorders = new TableBorders();
            TopBorder    topBorder  = new TopBorder();

            topBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            topBorder.Color = "000000";
            tblBorders.AppendChild(topBorder);
            BottomBorder bottomBorder = new BottomBorder();

            bottomBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            bottomBorder.Color = "000000";
            tblBorders.AppendChild(bottomBorder);
            RightBorder rightBorder = new RightBorder();

            rightBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            rightBorder.Color = "000000";
            tblBorders.AppendChild(rightBorder);
            LeftBorder leftBorder = new LeftBorder();

            leftBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            leftBorder.Color = "000000";
            tblBorders.AppendChild(leftBorder);
            InsideHorizontalBorder insideHBorder = new InsideHorizontalBorder();

            insideHBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            insideHBorder.Color = "000000";
            tblBorders.AppendChild(insideHBorder);
            InsideVerticalBorder insideVBorder = new InsideVerticalBorder();

            insideVBorder.Val   = new EnumValue <BorderValues>(BorderValues.Thick);
            insideVBorder.Color = "000000";
            tblBorders.AppendChild(insideVBorder);
            //// Add the table borders to the properties
            tblProperties.AppendChild(tblBorders);
            tblProperties.AppendChild(just);
            //// Add the table properties to the table
            tbl.AppendChild(tblProperties);
            //// Add a cell to each column in the row
            ///
            List <TableCell> headerCells = new List <TableCell>();

            foreach (string itemHeaders in headers)
            {
                TableCell tcName1 = new TableCell(new Paragraph(new Run(new Text(itemHeaders))));
                tcName1.Append(new TableCellProperties(
                                   new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "3000"
                }));
                headerCells.Add(tcName1);
            }
            //// Create a new row
            TableRow tr = new TableRow();

            tr.Append(headerCells.ToArray());
            tbl.AppendChild(tr);

            foreach (List <string> rowItems in items)
            {
                List <TableCell> dataCells = new List <TableCell>();
                foreach (string data in rowItems)
                {
                    TableCell tcName1 = new TableCell(new Paragraph(new Run(new Text(data))));
                    tcName1.Append(new TableCellProperties(
                                       new TableCellWidth()
                    {
                        Type = TableWidthUnitValues.Dxa, Width = "3000"
                    }));
                    dataCells.Add(tcName1);
                }
                TableRow tr1 = new TableRow();
                tr1.Append(dataCells.ToArray());
                tbl.AppendChild(tr1);
            }

            return(tbl);
        }
Ejemplo n.º 23
0
        private static Table genTable(List <CalcValueBase> calcVals)
        {
            Table tableOfInputs = new Table();
            var   tableGrid     = new TableGrid();

            tableGrid.AppendChild(new GridColumn());
            tableGrid.AppendChild(new GridColumn());
            tableGrid.AppendChild(new GridColumn());
            tableOfInputs.AppendChild(tableGrid);
            var tableProps = new TableProperties();

            tableProps.AppendChild(new TableLayout()
            {
                Type = TableLayoutValues.Fixed
            });
            tableProps.AppendChild(new TableWidth()
            {
                Width = "9000", Type = TableWidthUnitValues.Dxa
            });
            tableProps.AppendChild(new TableBorders()
            {
                InsideHorizontalBorder = new InsideHorizontalBorder()
                {
                    Color = "c0c0c0", Size = 4, Val = BorderValues.Single
                }
            });
            tableProps.AppendChild(new TableBorders()
            {
                BottomBorder = new BottomBorder()
                {
                    Color = "c0c0c0", Size = 4, Val = BorderValues.Single
                }
            });
            tableProps.AppendChild(new TableBorders()
            {
                TopBorder = new TopBorder()
                {
                    Color = "c0c0c0", Size = 4, Val = BorderValues.Single
                }
            });
            //tableProps.AppendChild(new TableBorders() { LeftBorder = new LeftBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } });
            //tableProps.AppendChild(new TableBorders() { InsideVerticalBorder = new InsideVerticalBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } });
            //tableProps.AppendChild(new TableBorders() { RightBorder = new RightBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } });

            tableOfInputs.AppendChild(tableProps);

            foreach (var item in calcVals)
            {
                TableRow row    = new TableRow();
                var      para1  = new Paragraph();
                var      myMath = new M.OfficeMath(new M.Run(new M.Text(item.Symbol)
                {
                    Space = SpaceProcessingModeValues.Preserve
                }));
                para1.AppendChild(myMath);
                para1.AppendChild(new Run(new Text(" ")
                {
                    Space = SpaceProcessingModeValues.Preserve
                }));
                TableCell cell1 = new TableCell();
                cell1.Append(para1);
                cell1.Append(new TableCellProperties(new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "1200"
                }));
                var       para2 = new Paragraph(new Run(new Text(item.Name)));
                TableCell cell2 = new TableCell();
                cell2.AppendChild(para2);
                cell2.Append(new TableCellProperties(new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "6100"
                }));
                var para3 = new Paragraph();
                if (item.Type == CalcValueType.DOUBLE)
                {
                    myMath = new M.OfficeMath(new M.Run(new M.Text(item.ValueAsString + item.Unit)
                    {
                        Space = SpaceProcessingModeValues.Preserve
                    }));
                    para3.AppendChild(myMath);
                    para3.AppendChild(new Run(new Text(" ")
                    {
                        Space = SpaceProcessingModeValues.Preserve
                    }));
                }
                else if (item.Type == CalcValueType.SELECTIONLIST)
                {
                    para3.AppendChild(new Run(new Text(item.ValueAsString)));
                }
                else
                {
                    cell2.AppendChild(new Paragraph(new Run(new Text(item.ValueAsString))));
                }
                TableCell cell3 = new TableCell();
                cell3.Append(para3);
                cell3.Append(new TableCellProperties(new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "1700"
                }));
                row.Append(cell1, cell2, cell3);
                tableOfInputs.AppendChild(row);
            }
            return(tableOfInputs);
        }
Ejemplo n.º 24
0
        OpenXmlElement GenerateContent(Body Body, DataType DataType, object Obj, TokenParameters TokenParams)
        {
            switch (DataType)
            {
            case DataType.None:
                return(null);

            case DataType.EmbeddedData: {
                EmbeddedData ObjData = (EmbeddedData)Obj;

                switch (ObjData.Type.MediaType)
                {
                case "image/jpeg":
                case "image/jpg":
                case "image/png": {
                    Image Img = ObjData.ParseImageData();
                    Utils.GetSizeInEMU(Img, out long W, out long H);

                    const string WidthName  = "width";
                    const string HeightName = "height";

                    if (TokenParams.Defined(WidthName) && TokenParams.Defined(HeightName))
                    {
                        W = Utils.MilimeterToEmu(TokenParams.Get <int>(WidthName));
                        H = Utils.MilimeterToEmu(TokenParams.Get <int>(HeightName));
                    }
                    else if (TokenParams.Defined(WidthName))
                    {
                        long NewW = Utils.MilimeterToEmu(TokenParams.Get <int>(WidthName));
                        Utils.Scale((float)NewW / W, ref W, ref H);
                    }
                    else if (TokenParams.Defined(HeightName))
                    {
                        long NewH = Utils.MilimeterToEmu(TokenParams.Get <int>(HeightName));
                        Utils.Scale((float)NewH / H, ref W, ref H);
                    }

                    GenerateImagePart(Img, out string ImageID);
                    return(new Run(new RunProperties(), GenerateDrawing(ImageID, W, H)));
                }

                case "text/csv": {
                    string   CSVData  = ObjData.ParseStringData();
                    string[] CSVLines = CSVData.Replace("\r", "").Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

                    // https://www.codeproject.com/Articles/1043875/Create-Word-table-using-OpenXML-and-Csharp-Without


                    Table Tab = new Table();
                    //TableProperties TblPr = new TableProperties();
                    //Tab.AppendChild(TblPr);

                    uint         TableBorder = 1;
                    BorderValues BorderType  = BorderValues.BasicThinLines;

                    TableProperties Props = new TableProperties();
                    Tab.AppendChild(Props);

                    PageDimensions Dim;
                    GetPageDimensions(Body, out Dim);

                    Props.AppendChild(new TableStyle()
                            {
                                Val = "0"
                            });
                    Props.AppendChild(new TableWidth()
                            {
                                Width = Dim.FillWidth.ToString(), Type = TableWidthUnitValues.Dxa
                            });
                    Props.AppendChild(new TableIndentation()
                            {
                                Width = 0, Type = TableWidthUnitValues.Dxa
                            });

                    TableBorders Borders = new TableBorders();
                    Borders.AppendChild(new TopBorder()
                            {
                                Val = new EnumValue <BorderValues>(BorderType), Size = TableBorder
                            });
                    Borders.AppendChild(new BottomBorder()
                            {
                                Val = new EnumValue <BorderValues>(BorderType), Size = TableBorder
                            });
                    Borders.AppendChild(new LeftBorder()
                            {
                                Val = new EnumValue <BorderValues>(BorderType), Size = TableBorder
                            });
                    Borders.AppendChild(new RightBorder()
                            {
                                Val = new EnumValue <BorderValues>(BorderType), Size = TableBorder
                            });
                    Borders.AppendChild(new InsideHorizontalBorder()
                            {
                                Val = new EnumValue <BorderValues>(BorderType), Size = TableBorder
                            });
                    Borders.AppendChild(new InsideVerticalBorder()
                            {
                                Val = new EnumValue <BorderValues>(BorderType), Size = TableBorder
                            });
                    Props.AppendChild(Borders);

                    Props.AppendChild(new TableLayout()
                            {
                                Type = TableLayoutValues.Fixed
                            });

                    foreach (var Line in CSVLines)
                    {
                        string[]    Columns = Line.Split(new[] { ';' });
                        TableCell[] Cells   = new TableCell[Columns.Length - 1];

                        for (int i = 0; i < Columns.Length - 1; i++)
                        {
                            string Column = Columns[i];

                            if (Column.StartsWith("\"") && Column.EndsWith("\""))
                            {
                                Column = Column.Substring(1, Column.Length - 2);
                            }

                            Cells[i] = GenerateCell(Column);
                        }

                        Tab.AppendChild(GenerateRow(Cells));
                    }

                    //Body.ReplaceChild(Tab, Root);
                    return(Tab);
                }

                case "text/plain":
                    return(GenerateTextRun(ObjData.ParseStringData()));

                default:
                    throw new NotImplementedException();
                }
            }

            case DataType.String: {
                WordTable.ColumnStyle TokenParamStyle = WordTable.ColumnStyle.NONE;

                if (TokenParams.Defined("bold"))
                {
                    TokenParamStyle |= WordTable.ColumnStyle.BOLD;
                }

                if (TokenParams.Defined("italic"))
                {
                    TokenParamStyle |= WordTable.ColumnStyle.ITALIC;
                }

                if (TokenParams.Defined("underline"))
                {
                    TokenParamStyle |= WordTable.ColumnStyle.UNDERLINE;
                }

                WordTable.ColumnStyle Style = WordTableContext.GetCurrent()?.GetCurrentColumn()?.ParseStyle() ?? TokenParamStyle;
                return(GenerateTextRun(Obj.ToString(), Style));
            }

            case DataType.PageBreak:
                return(new Run(new RunProperties(), new Break()
                {
                    Type = BreakValues.Page
                }));

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 25
0
        void GenerateTableFormDB()
        {
            using (WordprocessingDocument myDoc = WordprocessingDocument.Open(docName, true)) {
                MainDocumentPart mainPart = myDoc.MainDocumentPart;
                Document doc = mainPart.Document;
                //Create new table with predefined table style
                Table table = new Table();
                TableProperties tblPr = new TableProperties();
                TableStyle tblStyle = new TableStyle() { Val = "MyTableStyle" };
                tblPr.AppendChild(tblStyle);
                table.AppendChild(tblPr);
                string[] headerContent = new string[] { "Code", "Name", "Scientific Name" };
                //Create header row
                TableRow header = CreateRow(headerContent);
                table.AppendChild(header);

                //Connect to database
                BirdTrackDataContext db = new BirdTrackDataContext();
                var btoQuery =
                     from b in db.btos
                     select b;

                //For every product in my database create a new row in my table
                foreach (var item in btoQuery) {
                    //                            price += Math.Round(item.ListPrice, 2);

                    string[] content = new[] { item.bto_code,
                            item.species_name,
                            item.scientific_name};
                    TableRow tr = CreateRow(content);
                    table.AppendChild(tr);
                }

                doc.Body.AppendChild(table);
                doc.Save();
            }
        }