コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="row"></param>
        /// <param name="document"></param>
        /// <param name="parent"></param>
        /// <param name="context"></param>
        /// <param name="documentPart"></param>
        /// <param name="isHeader"></param>
        /// <param name="isAlternateRow">true for even lines</param>
        /// <param name="formatProvider"></param>
        /// <returns></returns>
        public static TableRow Render(this Row row, Models.Document document, OpenXmlElement parent, ContextModel context, OpenXmlPart documentPart, bool isHeader, bool isAlternateRow, IFormatProvider formatProvider)
        {
            if (!string.IsNullOrWhiteSpace(row.ShowKey) && context.ExistItem <BooleanModel>(row.ShowKey) && !context.GetItem <BooleanModel>(row.ShowKey).Value)
            {
                return(null);
            }

            context.ReplaceItem(row, formatProvider);

            TableRow wordRow = new TableRow();

            TableRowProperties wordRowProperties = new TableRowProperties();

            if (isHeader)
            {
                wordRowProperties.AppendChild(new TableHeader()
                {
                    Val = OnOffOnlyValues.On
                });
            }
            wordRow.AppendChild(wordRowProperties);

            if (row.RowHeight.HasValue)
            {
                wordRowProperties.AppendChild(new TableRowHeight()
                {
                    Val = UInt32Value.FromUInt32((uint)row.RowHeight.Value)
                });
            }

            if (row.CantSplit)
            {
                wordRowProperties.AppendChild(new CantSplit());
            }

            foreach (var cell in row.Cells)
            {
                cell.InheritFromParent(row);
                wordRow.AppendChild(cell.Render(document, wordRow, context, documentPart, isAlternateRow, formatProvider));
            }

            return(wordRow);
        }
コード例 #2
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;
            }
        }
コード例 #3
0
        public static TableRow Render(this Row row, Models.Document document, OpenXmlElement parent, ContextModel context, IList <ContextModel> cellsContext, Cell cellModel, OpenXmlPart documentPart, bool isHeader, bool isAlternateRow, IFormatProvider formatProvider)
        {
            context.ReplaceItem(row, formatProvider);

            TableRow wordRow = new TableRow();

            TableRowProperties wordRowProperties = new TableRowProperties();

            if (isHeader)
            {
                wordRowProperties.AppendChild(new TableHeader()
                {
                    Val = OnOffOnlyValues.On
                });
            }
            wordRow.AppendChild(wordRowProperties);

            if (row.RowHeight.HasValue)
            {
                wordRowProperties.AppendChild(new TableRowHeight()
                {
                    Val = UInt32Value.FromUInt32((uint)row.RowHeight.Value)
                });
            }

            if (row.CantSplit)
            {
                wordRowProperties.AppendChild(new CantSplit());
            }

            foreach (var cellContext in cellsContext)
            {
                var cell = cellModel.Clone();
                cell.InheritFromParent(row);
                wordRow.AppendChild(cell.Render(document, wordRow, cellContext, documentPart, isAlternateRow, formatProvider));
            }

            return(wordRow);
        }
コード例 #4
0
        /// <summary>
        /// The write table.
        /// </summary>
        /// <param name="t">The t.</param>
        public void WriteTable(Table t)
        {
            this.body.AppendChild(CreateParagraph(t.GetFullCaption(this.style), TableCaptionId));

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

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

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

            var tableGrid1 = new TableGrid();

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

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

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

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

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

                table.AppendChild(tr);
            }

            this.body.AppendChild(table);
        }
コード例 #5
0
        public void ExportWordDocument(string filepath)
        {
            using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(filepath, WordprocessingDocumentType.Document))
            {
                MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
                mainPart.Document = new Document();
                Body body = mainPart.Document.AppendChild(new Body());


                #region 标题文字(加粗居中)

                Paragraph para = body.AppendChild(new Paragraph());

                ParagraphProperties pPr = para.AppendChild(new ParagraphProperties());
                pPr.Append(new Justification()
                {
                    Val = JustificationValues.Center
                });


                Run           run = para.AppendChild(new Run());
                RunProperties rPr = new RunProperties(new RunFonts()
                {
                    Ascii = "宋体", ComplexScript = "宋体", EastAsia = "宋体", HighAnsi = "宋体"
                });
                rPr.Append(new FontSize()
                {
                    Val = "40"
                });
                rPr.Append(new Bold()
                {
                    Val = true
                });

                run.Append(rPr);
                run.Append(new Text("钢轨探伤仪探伤报告"));

                #endregion

                //rPr.FontSize.Val = "40";
                //rPr.Append(new RunFonts() { ComplexScript = "宋体" });
                //rPr.RunFonts.ComplexScript = "宋体";

                //Run r = wordDocument.MainDocumentPart.Document.Descendants<Run>().First();
                //r.PrependChild(rPr);

                #region 表格

                Table table = new Table();

                #region 表格样式

                // Create a TableProperties object and specify its border information.
                TableProperties tblProp = new TableProperties(
                    new TableBorders(
                        new TopBorder()
                {
                    Val  = new EnumValue <BorderValues>(BorderValues.Single),
                    Size = 1
                },
                        new BottomBorder()
                {
                    Val  = new EnumValue <BorderValues>(BorderValues.Single),
                    Size = 1
                },
                        new LeftBorder()
                {
                    Val  = new EnumValue <BorderValues>(BorderValues.Single),
                    Size = 1
                },
                        new RightBorder()
                {
                    Val  = new EnumValue <BorderValues>(BorderValues.Single),
                    Size = 1
                },
                        new InsideHorizontalBorder()
                {
                    Val  = new EnumValue <BorderValues>(BorderValues.Single),
                    Size = 1
                },
                        new InsideVerticalBorder()
                {
                    Val  = new EnumValue <BorderValues>(BorderValues.Single),
                    Size = 1
                }
                        )
                    );
                tblProp.TableWidth = new TableWidth()
                {
                    Width = "9639", Type = TableWidthUnitValues.Dxa
                };
                tblProp.TableLayout = new TableLayout()
                {
                    Type = TableLayoutValues.Fixed
                };                                                                            //固定列宽
                tblProp.TableLook = new TableLook()
                {
                    Val = "0000", FirstRow = false, LastRow = false, FirstColumn = false, LastColumn = false
                };

                table.Append(tblProp);

                #endregion

                #region 成员模板

                //Paragraph tblPara = new Paragraph();
                //ParagraphProperties tblpPr = tblPara.AppendChild(new ParagraphProperties());
                //tblpPr.AppendChild(new Justification() { Val = JustificationValues.Left });
                //tblpPr.AppendChild(
                //    new RunProperties(
                //        new RunFonts() { Ascii = "宋体", ComplexScript = @"宋体", EastAsia = "宋体", HighAnsi = "宋体" },
                //        new FontSize() { Val = "24" })
                //    );

                TableRow tr = new TableRow();
                tr.AppendChild(new TableRowProperties(new TableRowHeight()
                {
                    Val = 454
                }));

                TableCell tc = new TableCell();
                tc.AppendChild(new TableCellProperties(
                                   new TableCellVerticalAlignment()
                {
                    Val = TableVerticalAlignmentValues.Center
                }
                                   //,new Shading() { Val = ShadingPatternValues.Clear, Fill = "auto" }// 阴影
                                   ));
                tc.AppendChild(new TableCellMargin(
                                   new LeftMargin()
                {
                    Width = "100"
                }
                                   ));
                Run tblRun = new Run();
                tblRun.AppendChild(new RunProperties(
                                       new RunFonts()
                {
                    Ascii = "宋体", ComplexScript = @"宋体", EastAsia = "宋体", HighAnsi = "宋体"
                },
                                       new FontSize()
                {
                    Val = "24"
                },
                                       new Bold()
                {
                    Val = true
                }
                                       ));
                #endregion

                #region 例1
                {
                    // Create a row.
                    TableRow test1 = new TableRow(tr.OuterXml);
                    // Create a cell.
                    // Create a second table cell by copying the OuterXml value of the first table cell.
                    TableCell tc1 = new TableCell(tc.OuterXml);
                    TableCell tc2 = new TableCell(tc.OuterXml);
                    TableCell tc3 = new TableCell(tc.OuterXml);
                    TableCell tc4 = new TableCell(tc.OuterXml);
                    TableCell tc5 = new TableCell(tc.OuterXml);
                    TableCell tc6 = new TableCell(tc.OuterXml);
                    // Specify the table cell content.
                    Run run1 = new Run(tblRun.OuterXml);
                    Run run2 = new Run(tblRun.OuterXml);
                    Run run3 = new Run(tblRun.OuterXml);
                    Run run4 = new Run(tblRun.OuterXml);
                    Run run5 = new Run(tblRun.OuterXml);
                    Run run6 = new Run(tblRun.OuterXml);
                    run1.Append(new Text("some text 1"));
                    run2.Append(new Text("some text 2"));
                    run3.Append(new Text("some text 3"));
                    run4.Append(new Text("文字4:"));
                    run5.Append(new Text("some text 5"));
                    run6.Append(new Text("text 6"));
                    tc1.Append(new Paragraph(run1));
                    tc2.Append(new Paragraph(run2));
                    tc3.Append(new Paragraph(run3));
                    tc4.Append(new Paragraph(run4));
                    tc5.Append(new Paragraph(run5));
                    tc6.Append(new Paragraph(run6));

                    //Paragraph para1 = new Paragraph(tlbPara.OuterXml);
                    //Paragraph para2 = new Paragraph(tlbPara.OuterXml);
                    //Paragraph para3 = new Paragraph(tlbPara.OuterXml);
                    //Paragraph para4 = new Paragraph(tlbPara.OuterXml);
                    //Paragraph para5 = new Paragraph(tlbPara.OuterXml);
                    //Paragraph para6 = new Paragraph(tlbPara.OuterXml);
                    //para1.Append(new Run(new Text("some text 1")));
                    //para2.Append(new Run(new Text("some text 2")));
                    //para3.Append(new Run(new Text("some text 3")));
                    //para4.Append(new Run(new Text("some text 4")));
                    //para5.Append(new Run(new Text("some text 5")));
                    //para6.Append(new Run(new Text("some text 6")));
                    //tc1.Append(para1);
                    //tc2.Append(para2);
                    //tc3.Append(para3);
                    //tc4.Append(para4);
                    //tc5.Append(para5);
                    //tc6.Append(para6);
                    // Append the table cell to the table row.
                    test1.Append(tc1);
                    test1.Append(tc2);
                    test1.Append(tc3);
                    test1.Append(tc4);
                    test1.Append(tc5);
                    test1.Append(tc6);

                    // Append the table row to the table.
                    //table.Append(test1);
                }
                #endregion

                #region 第一行
                {
                    TableRow tr1 = new TableRow(tr.OuterXml);

                    TableCell tc1 = new TableCell(tc.OuterXml);
                    TableCell tc2 = new TableCell(tc.OuterXml);
                    TableCell tc3 = new TableCell(tc.OuterXml);
                    TableCell tc4 = new TableCell(tc.OuterXml);
                    TableCell tc5 = new TableCell(tc.OuterXml);
                    TableCell tc6 = new TableCell(tc.OuterXml);
                    // Specify the table cell content.
                    Run run1 = new Run(tblRun.OuterXml);
                    Run run2 = new Run(tblRun.OuterXml);
                    Run run3 = new Run(tblRun.OuterXml);
                    Run run4 = new Run(tblRun.OuterXml);
                    Run run5 = new Run(tblRun.OuterXml);
                    Run run6 = new Run(tblRun.OuterXml);
                    run1.Append(new Text("线名:"));
                    run2.Append(new Text("000"));
                    run3.Append(new Text("线别:"));
                    run4.Append(new Text("正线"));
                    run5.Append(new Text("股别:"));
                    run6.Append(new Text("右"));
                    tc1.Append(new Paragraph(run1));
                    tc2.Append(new Paragraph(run2));
                    tc3.Append(new Paragraph(run3));
                    tc4.Append(new Paragraph(run4));
                    tc5.Append(new Paragraph(run5));
                    tc6.Append(new Paragraph(run6));
                    // Append the table cell to the table row.
                    tr1.Append(tc1);
                    tr1.Append(tc2);
                    tr1.Append(tc3);
                    tr1.Append(tc4);
                    tr1.Append(tc5);
                    tr1.Append(tc6);
                    // Append the table row to the table.
                    table.Append(tr1);
                }
                #endregion

                #region 第二行
                {
                    TableRow tr2 = new TableRow(tr.OuterXml);

                    TableCell tc1 = new TableCell(tc.OuterXml);
                    TableCell tc2 = new TableCell(tc.OuterXml);
                    TableCell tc3 = new TableCell(tc.OuterXml);
                    TableCell tc4 = new TableCell(tc.OuterXml);
                    TableCell tc5 = new TableCell(tc.OuterXml);
                    TableCell tc6 = new TableCell(tc.OuterXml);
                    // Specify the table cell content.
                    Run run1 = new Run(tblRun.OuterXml);
                    Run run2 = new Run(tblRun.OuterXml);
                    Run run3 = new Run(tblRun.OuterXml);
                    Run run4 = new Run(tblRun.OuterXml);
                    Run run5 = new Run(tblRun.OuterXml);
                    Run run6 = new Run(tblRun.OuterXml);
                    run1.Append(new Text("轨型:"));
                    run2.Append(new Text("60"));
                    run3.Append(new Text("伤损类型:"));
                    run4.Append(new Text(""));
                    run5.Append(new Text("生产厂商:"));
                    run6.Append(new Text(""));
                    tc1.Append(new Paragraph(run1));
                    tc2.Append(new Paragraph(run2));
                    tc3.Append(new Paragraph(run3));
                    tc4.Append(new Paragraph(run4));
                    tc5.Append(new Paragraph(run5));
                    tc6.Append(new Paragraph(run6));
                    // Append the table cell to the table row.
                    tr2.Append(tc1);
                    tr2.Append(tc2);
                    tr2.Append(tc3);
                    tr2.Append(tc4);
                    tr2.Append(tc5);
                    tr2.Append(tc6);
                    // Append the table row to the table.
                    table.Append(tr2);
                }
                #endregion

                #region 第三行
                {
                    TableRow tr3 = new TableRow(tr.OuterXml);

                    TableCell tc1 = new TableCell(tc.OuterXml);
                    TableCell tc2 = new TableCell(tc.OuterXml);
                    TableCell tc3 = new TableCell(tc.OuterXml);
                    TableCell tc4 = new TableCell(tc.OuterXml);
                    TableCell tc5 = new TableCell(tc.OuterXml);
                    TableCell tc6 = new TableCell(tc.OuterXml);
                    // Specify the table cell content.
                    Run run1 = new Run(tblRun.OuterXml);
                    Run run2 = new Run(tblRun.OuterXml);
                    Run run3 = new Run(tblRun.OuterXml);
                    Run run4 = new Run(tblRun.OuterXml);
                    Run run5 = new Run(tblRun.OuterXml);
                    Run run6 = new Run(tblRun.OuterXml);
                    run1.Append(new Text("伤损编号:"));
                    run2.Append(new Text(""));
                    run3.Append(new Text("探伤时间:"));
                    run4.Append(new Text(DateTime.Now.ToString()));
                    run5.Append(new Text("探伤人员:"));
                    run6.Append(new Text(""));
                    tc1.Append(new Paragraph(run1));
                    tc2.Append(new Paragraph(run2));
                    tc3.Append(new Paragraph(run3));
                    tc4.Append(new Paragraph(run4));
                    tc5.Append(new Paragraph(run5));
                    tc6.Append(new Paragraph(run6));
                    // Append the table cell to the table row.
                    tr3.Append(tc1);
                    tr3.Append(tc2);
                    tr3.Append(tc3);
                    tr3.Append(tc4);
                    tr3.Append(tc5);
                    tr3.Append(tc6);
                    // Append the table row to the table.
                    table.Append(tr3);
                }
                #endregion

                #region 第四行
                {
                    TableRow tr4 = new TableRow(tr.OuterXml);

                    TableCell tc1 = new TableCell(tc.OuterXml);
                    TableCell tc2 = new TableCell(tc.OuterXml);

                    TableCellProperties tcPr = tc2.Descendants <TableCellProperties>().First();
                    tcPr.Append(new GridSpan()
                    {
                        Val = 5
                    });

                    // Specify the table cell content.
                    Run run1 = new Run(tblRun.OuterXml);
                    Run run2 = new Run(tblRun.OuterXml);
                    Run run3 = new Run(tblRun.OuterXml);
                    Run run4 = new Run(tblRun.OuterXml);
                    run1.Append(new Text("增益:"));
                    run2.Append(new Text("A:45.0dB  B:45.5dB  C:45.5dB"));
                    run3.Append(new Text("D:45.5dB  E:45.0dB  F:45.0dB"));
                    run4.Append(new Text("G:46.5dB  H:46.5dB  I:52.0dB"));
                    tc1.Append(new Paragraph(run1));
                    tc2.Append(new Paragraph(run2));
                    tc2.Append(new Paragraph(run3));
                    tc2.Append(new Paragraph(run4));
                    // Append the table cell to the table row.
                    tr4.Append(tc1);
                    tr4.Append(tc2);
                    // Append the table row to the table.
                    table.Append(tr4);
                }
                #endregion

                #region 第五行
                {
                    TableRow tr5 = new TableRow(tr.OuterXml);

                    TableCell tc1 = new TableCell(tc.OuterXml);

                    TableRowProperties tblPr4 = tr5.Descendants <TableRowProperties>().First();
                    tblPr4.AppendChild(new TableRowHeight()
                    {
                        Val = 9000
                    });

                    TableCellProperties tcPr = tc1.Descendants <TableCellProperties>().First();
                    tcPr.Append(
                        new TableCellVerticalAlignment()
                    {
                        Val = TableVerticalAlignmentValues.Top
                    },
                        new GridSpan()
                    {
                        Val = 6
                    }
                        );
                    tcPr.Append(new TableCellMargin(new TopMargin()
                    {
                        Width = "50"
                    }));

                    //new Shading() { Val = ShadingPatternValues.Clear, Fill = "auto" }
                    // Specify the table cell content.
                    Run run1 = new Run(tblRun.OuterXml);
                    Run run2 = new Run(tblRun.OuterXml);
                    Run run3 = new Run(tblRun.OuterXml);
                    Run run4 = new Run(tblRun.OuterXml);
                    //地段:0
                    //当前里程:0km039m

                    run1.Append(new Text("地段:"));
                    run2.Append(new Text("0"));
                    run3.Append(new Text("当前里程:"));
                    run4.Append(new Text("0km039m"));
                    tc1.Append(new Paragraph(run1, run2));
                    //tc1.Append(new Paragraph(run2));
                    tc1.Append(new Paragraph(run3, run4));
                    //tc1.Append(new Paragraph(run4));

                    ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);


                    //Bitmap bitmap = new Bitmap(500, 500);
                    //Graphics g = Graphics.FromImage(bitmap);
                    //g.Clear(System.Drawing.Color.Pink);
                    //using (MemoryStream stream = new MemoryStream())
                    //{
                    //    bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    //    imagePart.FeedData(stream);
                    //}

                    //////string fileName = @"?D:\Users\KETIZU2\Desktop\images\logo.jpg";
                    string fileName = @"D:\Users\KETIZU2\Desktop\images\logo.jpg";
                    using (FileStream stream = new FileStream(fileName, FileMode.Open))
                    {
                        imagePart.FeedData(stream);
                    }

                    // Define the reference of the image.
                    Paragraph paraImage = AddImageToParagraph(mainPart.GetIdOfPart(imagePart), 6120000L, 2160000L);

                    //wordDoc.MainDocumentPart.Document.Body.AppendChild(new Paragraph(new Run(element)));
                    tc1.AppendChild(paraImage);

                    // Append the table cell to the table row.
                    tr5.Append(tc1);
                    // Append the table row to the table.
                    table.Append(tr5);
                }
                #endregion

                #region 第六行
                {
                    TableRow tr6 = new TableRow(tr.OuterXml);

                    TableCell tc1 = new TableCell(tc.OuterXml);
                    TableCell tc2 = new TableCell(tc.OuterXml);

                    TableCellProperties tcPr = tc2.Descendants <TableCellProperties>().First();
                    tcPr.Append(new GridSpan()
                    {
                        Val = 5
                    });

                    // Specify the table cell content.
                    Run run1 = new Run(tblRun.OuterXml);
                    Run run2 = new Run(tblRun.OuterXml);

                    run1.Append(new Text("单位名称:"));
                    run2.Append(new Text(""));

                    tc1.Append(new Paragraph(run1));
                    tc2.Append(new Paragraph(run2));

                    // Append the table cell to the table row.
                    tr6.Append(tc1);
                    tr6.Append(tc2);
                    // Append the table row to the table.
                    table.Append(tr6);
                }
                #endregion

                #region 第七行
                {
                    TableRow tr7 = new TableRow(tr.OuterXml);

                    TableCell tc1 = new TableCell(tc.OuterXml);
                    TableCell tc2 = new TableCell(tc.OuterXml);
                    TableCell tc3 = new TableCell(tc.OuterXml);
                    TableCell tc4 = new TableCell(tc.OuterXml);

                    TableCellProperties tcPr = tc2.Descendants <TableCellProperties>().First();
                    tcPr.Append(new GridSpan()
                    {
                        Val = 3
                    });

                    // Specify the table cell content.
                    Run run1 = new Run(tblRun.OuterXml);
                    Run run2 = new Run(tblRun.OuterXml);
                    Run run3 = new Run(tblRun.OuterXml);
                    Run run4 = new Run(tblRun.OuterXml);

                    run1.Append(new Text("操作人员:"));
                    run2.Append(new Text(""));
                    run3.Append(new Text("日期:"));
                    run4.Append(new Text(DateTime.Now.ToString()));

                    tc1.Append(new Paragraph(run1));
                    tc2.Append(new Paragraph(run2));
                    tc3.Append(new Paragraph(run3));
                    tc4.Append(new Paragraph(run4));

                    // Append the table cell to the table row.
                    tr7.Append(tc1);
                    tr7.Append(tc2);
                    tr7.Append(tc3);
                    tr7.Append(tc4);
                    // Append the table row to the table.
                    table.Append(tr7);
                }
                #endregion

                body.Append(table);

                #endregion

                #region 文档格式

                SectionProperties sectPr = body.AppendChild(new SectionProperties());
                sectPr.AppendChild(new PageMargin()
                {
                    Top = 1134, Right = 1247, Bottom = 1134, Left = 1247, Header = 851, Footer = 992, Gutter = 0
                });

                #endregion
            }
        }
コード例 #6
0
ファイル: OwnerVerification.cs プロジェクト: plitton/hets
        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;
            }
        }
コード例 #7
0
ファイル: SeniorityList.cs プロジェクト: ychung-mot/hets
        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;
            }
        }
        private static void FillFirstTableRow(OpenXmlElement table, string relationshipId)
        {
            var tableRow = new TableRow
            {
                TextId               = HexBinaryValue.FromString("77777777"),
                ParagraphId          = HexBinaryValue.FromString("080C4265"),
                RsidTableRowAddition = HexBinaryValue.FromString("009B2C1D")
            };
            var rowProperties = new TableRowProperties();

            rowProperties.AppendChild(new GridAfter
            {
                Val = Int32Value.FromInt32(2)
            });
            rowProperties.AppendChild(new WidthAfterTableRow
            {
                Width = StringValue.FromString("6375"),
                Type  = new EnumValue <TableWidthUnitValues> {
                    Value = TableWidthUnitValues.Dxa
                }
            });
            tableRow.TableRowProperties = rowProperties;

            var tableCell = new TableCell
            {
                TableCellProperties = new TableCellProperties
                {
                    TableCellWidth = new TableCellWidth
                    {
                        Width = StringValue.FromString("800"),
                        Type  = new EnumValue <TableWidthUnitValues> {
                            Value = TableWidthUnitValues.Dxa
                        }
                    },
                    TableCellBorders = new TableCellBorders
                    {
                        TopBorder = new TopBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        LeftBorder = new LeftBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        BottomBorder = new BottomBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        RightBorder = new RightBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        }
                    }
                }
            };

            AddMainLogo(tableCell, relationshipId);

            tableRow.AppendChild(tableCell);

            table.AppendChild(tableRow);
        }
        private static void FillSecondTableRow(OpenXmlElement table)
        {
            var tableRow = new TableRow
            {
                TextId               = HexBinaryValue.FromString("77777777"),
                ParagraphId          = HexBinaryValue.FromString("3125C09D"),
                RsidTableRowAddition = HexBinaryValue.FromString("009B2C1D")
            };
            var rowProperties = new TableRowProperties();

            rowProperties.AppendChild(new GridAfter
            {
                Val = Int32Value.FromInt32(2)
            });
            rowProperties.AppendChild(new WidthAfterTableRow
            {
                Width = StringValue.FromString("6375"),
                Type  = new EnumValue <TableWidthUnitValues> {
                    Value = TableWidthUnitValues.Dxa
                }
            });
            tableRow.TableRowProperties = rowProperties;

            var tableCell = new TableCell
            {
                TableCellProperties = new TableCellProperties
                {
                    TableCellWidth = new TableCellWidth
                    {
                        Width = StringValue.FromString("800"),
                        Type  = new EnumValue <TableWidthUnitValues> {
                            Value = TableWidthUnitValues.Dxa
                        }
                    },
                    TableCellBorders = new TableCellBorders
                    {
                        TopBorder = new TopBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        LeftBorder = new LeftBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        BottomBorder = new BottomBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        RightBorder = new RightBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        }
                    }
                }
            };

            tableCell.AppendChild(new Paragraph
            {
                ParagraphId            = HexBinaryValue.FromString("595BC873"),
                TextId                 = HexBinaryValue.FromString("77777777"),
                RsidParagraphAddition  = HexBinaryValue.FromString("009B2C1D"),
                RsidRunAdditionDefault = HexBinaryValue.FromString("009B2C1D")
            });
            tableRow.AppendChild(tableCell);
            table.AppendChild(tableRow);
        }
コード例 #10
0
        /// <summary>
        /// The write table.
        /// </summary>
        /// <param name="t">The t.</param>
        public void WriteTable(Table t)
        {
            this.body.AppendChild(CreateParagraph(t.GetFullCaption(this.style), TableCaptionId));

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

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

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

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

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

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

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

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

                table.AppendChild(tr);
            }

            this.body.AppendChild(table);
        }