Exemplo n.º 1
1
        public void TestCreateRow()
        {
            XWPFDocument doc = new XWPFDocument();

            CT_Tbl table = new CT_Tbl();
            CT_Row r1 = table.AddNewTr();
            r1.AddNewTc().AddNewP();
            r1.AddNewTc().AddNewP();
            CT_Row r2 = table.AddNewTr();
            r2.AddNewTc().AddNewP();
            r2.AddNewTc().AddNewP();
            CT_Row r3 = table.AddNewTr();
            r3.AddNewTc().AddNewP();
            r3.AddNewTc().AddNewP();

            XWPFTable xtab = new XWPFTable(table, doc);
            Assert.AreEqual(3, xtab.GetNumberOfRows());
            Assert.IsNotNull(xtab.GetRow(2));

            //add a new row
            xtab.CreateRow();
            Assert.AreEqual(4, xtab.GetNumberOfRows());

            //check number of cols
            Assert.AreEqual(2, table.GetTrArray(0).SizeOfTcArray());

            //check creation of first row
            xtab = new XWPFTable(new CT_Tbl(), doc);
            Assert.AreEqual(1, xtab.GetCTTbl().GetTrArray(0).SizeOfTcArray());
        }
Exemplo n.º 2
0
        public void TestSetGetVertAlignment()
        {
            // instantiate the following classes so they'll Get picked up by
            // the XmlBean process and Added to the jar file. they are required
            // for the following XWPFTableCell methods.
            CT_Shd ctShd = new CT_Shd();
            Assert.IsNotNull(ctShd);
            CT_VerticalJc ctVjc = new CT_VerticalJc();
            Assert.IsNotNull(ctVjc);
            ST_Shd stShd = ST_Shd.nil;
            Assert.IsNotNull(stShd);
            ST_VerticalJc stVjc = ST_VerticalJc.top;
            Assert.IsNotNull(stVjc);

            // create a table
            XWPFDocument doc = new XWPFDocument();
            CT_Tbl ctTable = new CT_Tbl();
            XWPFTable table = new XWPFTable(ctTable, doc);
            // table has a single row by default; grab it
            XWPFTableRow tr = table.GetRow(0);
            Assert.IsNotNull(tr);
            // row has a single cell by default; grab it
            XWPFTableCell cell = tr.GetCell(0);

            cell.SetVerticalAlignment(XWPFTableCell.XWPFVertAlign.BOTH);
            XWPFTableCell.XWPFVertAlign al = cell.GetVerticalAlignment();
            Assert.AreEqual(XWPFTableCell.XWPFVertAlign.BOTH, al);
        }
Exemplo n.º 3
0
        /**
         * Get the TableCell which belongs to the TableCell
         */

        public XWPFTableCell GetTableCell(CT_Tc cell)
        {
            if (!(cell.Parent is CT_Row))
            {
                return(null);
            }
            CT_Row row = (CT_Row)cell.Parent;

            if (!(row.Parent is CT_Tbl))
            {
                return(null);
            }
            CT_Tbl    tbl   = (CT_Tbl)row.Parent;
            XWPFTable table = GetTable(tbl);

            if (table == null)
            {
                return(null);
            }
            XWPFTableRow tableRow = table.GetRow(row);

            if (tableRow == null)
            {
                return(null);
            }
            return(tableRow.GetTableCell(cell));
        }
Exemplo n.º 4
0
        public void TestSetGetVertAlignment()
        {
            // instantiate the following classes so they'll Get picked up by
            // the XmlBean process and Added to the jar file. they are required
            // for the following XWPFTableCell methods.
            CT_Shd ctShd = new CT_Shd();

            Assert.IsNotNull(ctShd);
            CT_VerticalJc ctVjc = new CT_VerticalJc();

            Assert.IsNotNull(ctVjc);
            ST_Shd stShd = ST_Shd.nil;

            Assert.IsNotNull(stShd);
            ST_VerticalJc stVjc = ST_VerticalJc.top;

            Assert.IsNotNull(stVjc);

            // create a table
            XWPFDocument doc     = new XWPFDocument();
            CT_Tbl       ctTable = new CT_Tbl();
            XWPFTable    table   = new XWPFTable(ctTable, doc);
            // table has a single row by default; grab it
            XWPFTableRow tr = table.GetRow(0);

            Assert.IsNotNull(tr);
            // row has a single cell by default; grab it
            XWPFTableCell cell = tr.GetCell(0);

            cell.SetVerticalAlignment(XWPFTableCell.XWPFVertAlign.BOTH);
            XWPFTableCell.XWPFVertAlign al = cell.GetVerticalAlignment().Value;
            Assert.AreEqual(XWPFTableCell.XWPFVertAlign.BOTH, al);
        }
Exemplo n.º 5
0
        public void TestCreateRow()
        {
            XWPFDocument doc = new XWPFDocument();

            CT_Tbl table = new CT_Tbl();
            CT_Row r1    = table.AddNewTr();

            r1.AddNewTc().AddNewP();
            r1.AddNewTc().AddNewP();
            CT_Row r2 = table.AddNewTr();

            r2.AddNewTc().AddNewP();
            r2.AddNewTc().AddNewP();
            CT_Row r3 = table.AddNewTr();

            r3.AddNewTc().AddNewP();
            r3.AddNewTc().AddNewP();

            XWPFTable xtab = new XWPFTable(table, doc);

            Assert.AreEqual(3, xtab.GetNumberOfRows());
            Assert.IsNotNull(xtab.GetRow(2));

            //add a new row
            xtab.CreateRow();
            Assert.AreEqual(4, xtab.GetNumberOfRows());

            //check number of cols
            Assert.AreEqual(2, table.GetTrArray(0).SizeOfTcArray());

            //check creation of first row
            xtab = new XWPFTable(new CT_Tbl(), doc);
            Assert.AreEqual(1, xtab.GetCTTbl().GetTrArray(0).SizeOfTcArray());
        }
Exemplo n.º 6
0
 public XWPFTable(CT_Tbl table, IBody part)
 {
     this.part      = part;
     this.ctTbl     = table;
     this.tableRows = new List <XWPFTableRow>();
     if (table.SizeOfTrArray() == 0)
     {
         this.CreateEmptyTable(table);
     }
     foreach (CT_Row tr in (IEnumerable <CT_Row>)table.GetTrList())
     {
         StringBuilder stringBuilder = new StringBuilder();
         tr.Table = table;
         this.tableRows.Add(new XWPFTableRow(tr, this));
         foreach (CT_Tc tc in (IEnumerable <CT_Tc>)tr.GetTcList())
         {
             tc.TableRow = tr;
             foreach (CT_P prgrph in (IEnumerable <CT_P>)tc.GetPList())
             {
                 XWPFParagraph xwpfParagraph = new XWPFParagraph(prgrph, part);
                 if (stringBuilder.Length > 0)
                 {
                     stringBuilder.Append('\t');
                 }
                 stringBuilder.Append(xwpfParagraph.GetText());
             }
         }
         if (stringBuilder.Length > 0)
         {
             this.text.Append((object)stringBuilder);
             this.text.Append('\n');
         }
     }
 }
Exemplo n.º 7
0
        public XWPFTable(CT_Tbl table, IBody part)
        {
            this.part = part;
            this.ctTbl = table;

            tableRows = new List<XWPFTableRow>();
            // is an empty table: I add one row and one column as default
            if (table.SizeOfTrArray() == 0)
                CreateEmptyTable(table);

            foreach (CT_Row row in table.GetTrList()) {
                StringBuilder rowText = new StringBuilder();
                row.Table = table;
                XWPFTableRow tabRow = new XWPFTableRow(row, this);
                tableRows.Add(tabRow);
                foreach (CT_Tc cell in row.GetTcList()) {
                    cell.TableRow = row;
                    foreach (CT_P ctp in cell.GetPList()) {
                        XWPFParagraph p = new XWPFParagraph(ctp, part);
                        if (rowText.Length > 0) {
                            rowText.Append('\t');
                        }
                        rowText.Append(p.GetText());
                    }
                }
                if (rowText.Length > 0) {
                    this.text.Append(rowText);
                    this.text.Append('\n');
                }
            }
        }
Exemplo n.º 8
0
        public void TestSetGetHBorders()
        {
            // instantiate the following classes so they'll Get picked up by
            // the XmlBean process and Added to the jar file. they are required
            // for the following XWPFTable methods.
            CT_TblBorders cttb = new CT_TblBorders();

            Assert.IsNotNull(cttb);
            ST_Border stb = new ST_Border();

            Assert.IsNotNull(stb);
            // create a table
            XWPFDocument doc     = new XWPFDocument();
            CT_Tbl       ctTable = new CT_Tbl();
            XWPFTable    table   = new XWPFTable(ctTable, doc);

            // Set inside horizontal border
            table.SetInsideHBorder(NPOI.XWPF.UserModel.XWPFTable.XWPFBorderType.SINGLE, 4, 0, "FF0000");
            // Get inside horizontal border components
            int s = table.GetInsideHBorderSize();

            Assert.AreEqual(4, s);
            int sp = table.GetInsideHBorderSpace();

            Assert.AreEqual(0, sp);
            String clr = table.GetInsideHBorderColor();

            Assert.AreEqual("FF0000", clr);
            NPOI.XWPF.UserModel.XWPFTable.XWPFBorderType bt = table.GetInsideHBorderType();
            Assert.AreEqual(NPOI.XWPF.UserModel.XWPFTable.XWPFBorderType.SINGLE, bt);
        }
Exemplo n.º 9
0
        public void TestSetGetMargins()
        {
            // instantiate the following class so it'll Get picked up by
            // the XmlBean process and Added to the jar file. it's required
            // for the following XWPFTable methods.
            CT_TblCellMar ctm = new CT_TblCellMar();

            Assert.IsNotNull(ctm);
            // create a table
            XWPFDocument doc     = new XWPFDocument();
            CT_Tbl       ctTable = new CT_Tbl();
            XWPFTable    table   = new XWPFTable(ctTable, doc);

            // Set margins
            table.SetCellMargins(50, 50, 250, 450);
            // Get margin components
            int t = table.GetCellMarginTop();

            Assert.AreEqual(50, t);
            int l = table.GetCellMarginLeft();

            Assert.AreEqual(50, l);
            int b = table.GetCellMarginBottom();

            Assert.AreEqual(250, b);
            int r = table.GetCellMarginRight();

            Assert.AreEqual(450, r);
        }
Exemplo n.º 10
0
        private void CreateEmptyTable(CT_Tbl table)
        {
            // MINIMUM ELEMENTS FOR A TABLE
            table.AddNewTr().AddNewTc().AddNewP();

            CT_TblPr tblpro = table.AddNewTblPr();

            if (!tblpro.IsSetTblW())
            {
                tblpro.AddNewTblW().w = "0";
            }
            tblpro.tblW.type = (ST_TblWidth.auto);

            // layout
            // tblpro.AddNewTblLayout().Type=(STTblLayoutType.AUTOFIT);

            // borders
            CT_TblBorders borders = tblpro.AddNewTblBorders();

            borders.AddNewBottom().val  = (ST_Border.single);
            borders.AddNewInsideH().val = (ST_Border.single);
            borders.AddNewInsideV().val = (ST_Border.single);
            borders.AddNewLeft().val    = (ST_Border.single);
            borders.AddNewRight().val   = (ST_Border.single);
            borders.AddNewTop().val     = (ST_Border.single);

            /*
             * CTTblGrid tblgrid=table.AddNewTblGrid();
             * tblgrid.AddNewGridCol().W=(new Bigint("2000"));
             */
            GetRows();
        }
Exemplo n.º 11
0
        private void CreateEmptyTable(CT_Tbl table)
        {
            // MINIMUM ELEMENTS FOR A TABLE
            table.AddNewTr().AddNewTc().AddNewP();

            CT_TblPr tblpro = table.AddNewTblPr();

            if (!tblpro.IsSetTblW())
            {
                tblpro.AddNewTblW().w = "0";
            }
            tblpro.tblW.type = (ST_TblWidth.auto);

            // layout
            tblpro.AddNewTblLayout().type = ST_TblLayoutType.autofit;

            // borders
            CT_TblBorders borders = tblpro.AddNewTblBorders();

            borders.AddNewBottom().val  = ST_Border.single;
            borders.AddNewInsideH().val = ST_Border.single;
            borders.AddNewInsideV().val = ST_Border.single;
            borders.AddNewLeft().val    = ST_Border.single;
            borders.AddNewRight().val   = ST_Border.single;
            borders.AddNewTop().val     = ST_Border.single;


            CT_TblGrid tblgrid = table.AddNewTblGrid();

            tblgrid.AddNewGridCol().w = (ulong)2000;
        }
Exemplo n.º 12
0
        /// <summary>
        /// 为XWPFDocument文档复制指定索引的表
        /// </summary>
        /// <param name="readDoc">模板文件</param>
        /// <param name="tableIndex">需要复制模板的table的索引</param>
        /// <param name="targetIndex">复制到目标位置的table索引(如果目标位置原来有表格,会被覆盖)</param>
        /// <param name="myDoc">新创建的文件</param>
        public static void CopyTable(XWPFDocument readDoc, int tableIndex, int targetIndex, XWPFDocument myDoc)
        {
            var    sourceTable = readDoc.Tables[tableIndex];
            CT_Tbl sourceCTTbl = readDoc.Document.body.GetTblArray(8);

            var targetTable = myDoc.CreateTable();

            myDoc.SetTable(targetIndex, targetTable);
            var targetCTTbl = myDoc.Document.body.GetTblArray()[myDoc.Document.body.GetTblArray().Length - 1];

            targetCTTbl.tblPr        = sourceCTTbl.tblPr;
            targetCTTbl.tblPr.jc.val = ST_Jc.left;//表格在页面水平位置
            //targetCTTbl.tblGrid = sourceCTTbl.tblGrid;

            for (int i = 0; i < sourceTable.Rows.Count; i++)
            {
                var tbRow     = targetTable.CreateRow();
                var targetRow = tbRow.GetCTRow();
                tbRow.RemoveCell(0);
                XWPFTableRow row = sourceTable.Rows[i];
                targetRow.trPr = row.GetCTRow().trPr;
                for (int c = 0; c < row.GetTableCells().Count; c++)
                {
                    var tbCell = tbRow.CreateCell();
                    tbCell.RemoveParagraph(0);
                    var targetCell = tbCell.GetCTTc();

                    XWPFTableCell cell = row.GetTableCells()[c];
                    targetCell.tcPr = cell.GetCTTc().tcPr;
                    for (int p = 0; p < cell.Paragraphs.Count; p++)
                    {
                        var           tbPhs     = tbCell.AddParagraph();
                        CT_P          targetPhs = tbPhs.GetCTP();
                        XWPFParagraph para      = cell.Paragraphs[p];
                        var           paraCTP   = para.GetCTP();
                        targetPhs.pPr          = paraCTP.pPr;
                        targetPhs.rsidR        = paraCTP.rsidR;
                        targetPhs.rsidRPr      = paraCTP.rsidRPr;
                        targetPhs.rsidRDefault = paraCTP.rsidRDefault;
                        targetPhs.rsidP        = paraCTP.rsidP;

                        for (int r = 0; r < para.Runs.Count; r++)
                        {
                            var  tbRun     = tbPhs.CreateRun();
                            CT_R targetRun = tbRun.GetCTR();

                            XWPFRun run    = para.Runs[r];
                            var     runCTR = run.GetCTR();
                            targetRun.rPr     = runCTR.rPr;
                            targetRun.rsidRPr = runCTR.rsidRPr;
                            targetRun.rsidR   = runCTR.rsidR;
                            CT_Text text = targetRun.AddNewT();
                            text.Value = run.Text;
                        }
                    }
                }
            }
            targetTable.RemoveRow(0);
        }
Exemplo n.º 13
0
        public XWPFTable AddNewTbl(CT_Tbl table)
        {
            CT_Tbl table1 = this.ctFtnEdn.AddNewTbl();

            table1.Set(table);
            XWPFTable xwpfTable = new XWPFTable(table1, (IBody)this);

            this.tables.Add(xwpfTable);
            return(xwpfTable);
        }
Exemplo n.º 14
0
        /**
         * add a new table to the end of the footnote
         * @param table
         * @return the Added XWPFTable
         */
        public XWPFTable AddNewTbl(CT_Tbl table)
        {
            CT_Tbl newTable = ctFtnEdn.AddNewTbl();

            newTable.Set(table);
            XWPFTable xTable = new XWPFTable(newTable, this);

            tables.Add(xTable);
            return(xTable);
        }
Exemplo n.º 15
0
        /// <summary>
        /// word 插入表格功能(13行2列)
        /// </summary>
        /// <param name="m_Docx">根文档</param>
        /// <param name="device_type">设备类型</param>
        /// <param name="kilometer_mark">公里标</param>
        /// <param name="side_direction">下行侧向</param>
        /// <param name="longitude">经度</param>
        /// <param name="latitude">纬度</param>
        private static void word_inster_table(XWPFDocument m_Docx, DbBean bean, int i = 1)
        {
            XWPFTable table  = m_Docx.CreateTable(12, 2);
            CT_Tbl    ctbl   = m_Docx.Document.body.GetTblArray()[i];
            CT_TblPr  ctblpr = ctbl.AddNewTblPr();

            ctblpr.jc     = new CT_Jc();
            ctblpr.jc.val = ST_Jc.center;

            table.Width = 3500;
            table.GetRow(0).GetCell(0).SetText("设备类型");
            table.GetRow(0).GetCell(1).SetText(bean.DeviceType);
            table.GetRow(1).GetCell(0).SetText("公里标");
            table.GetRow(1).GetCell(1).SetText(bean.KilometerMark);
            table.GetRow(2).GetCell(0).SetText("下行侧向");
            table.GetRow(2).GetCell(1).SetText(bean.SideDirection);
            table.GetRow(3).GetCell(0).SetText("距线路中心距离(m)");
            table.GetRow(4).GetCell(0).SetText("经度");
            table.GetRow(4).GetCell(1).SetText(bean.Longitude);
            table.GetRow(5).GetCell(0).SetText("纬度");
            table.GetRow(5).GetCell(1).SetText(bean.Latitude);
            table.GetRow(6).GetCell(0).SetText("杆塔类型");
            table.GetRow(6).GetCell(1).SetText(bean.TowerType);
            table.GetRow(7).GetCell(0).SetText("杆塔高度");
            table.GetRow(7).GetCell(1).SetText(bean.TowerHeight);
            table.GetRow(8).GetCell(0).SetText("天线1方向角");
            table.GetRow(8).GetCell(1).SetText(bean.AntennaDirection1);
            table.GetRow(9).GetCell(0).SetText("天线2方向角");
            table.GetRow(9).GetCell(1).SetText(bean.AntennaDirection2);
            table.GetRow(10).GetCell(0).SetText("天线3方向角");
            table.GetRow(10).GetCell(1).SetText(bean.AntennaDirection3);
            table.GetRow(11).GetCell(0).SetText("天线4方向角");
            table.GetRow(11).GetCell(1).SetText(bean.AntennaDirection4);
            CT_TcPr m_Pr = table.GetRow(2).GetCell(1).GetCTTc().AddNewTcPr();

            m_Pr.tcW      = new CT_TblWidth();
            m_Pr.tcW.w    = "3500";
            m_Pr.tcW.type = ST_TblWidth.dxa; //设置单元格宽度

            XWPFTableRow  m_Row = table.InsertNewTableRow(0);
            XWPFTableCell cell  = m_Row.CreateCell();
            CT_Tc         cttc  = cell.GetCTTc();
            CT_TcPr       ctPr  = cttc.AddNewTcPr();

            ctPr.gridSpan     = new CT_DecimalNumber();
            ctPr.gridSpan.val = "2";
            cttc.GetPList()[0].AddNewR().AddNewT().Value = "SITE 【序号】";

            word_insert_space(1, m_Docx, 100);
            word_insert_text(m_Docx, "宋体", 11, "SITE 【序号】勘站照片");
            word_insert_text(m_Docx, "宋体", 11, "(3-10张照片)");

            word_insert_space(1, m_Docx, 100);
        }
Exemplo n.º 16
0
 public XWPFTable GetTable(CT_Tbl ctTbl)
 {
     for (int index = 0; index < this.tables.Count; ++index)
     {
         if (this.tables[index].GetCTTbl() == ctTbl)
         {
             return(this.tables[index]);
         }
     }
     return((XWPFTable)null);
 }
Exemplo n.º 17
0
        public void TestSetGetColBandSize()
        {
            XWPFDocument doc     = new XWPFDocument();
            CT_Tbl       ctTable = new CT_Tbl();
            XWPFTable    table   = new XWPFTable(ctTable, doc);

            table.SetColBandSize(16);
            int sz = table.GetColBandSize();

            Assert.AreEqual(16, sz);
        }
Exemplo n.º 18
0
        public CT_Tbl AddNewTbl()
        {
            CT_Tbl tbl = new CT_Tbl();

            lock (this)
            {
                this.itemsField.Add(tbl);
                this.itemsElementNameField.Add(DocumentBodyItemChoiceType.tbl);
            }
            return(tbl);
        }
Exemplo n.º 19
0
        public void TestSetGetRowBandSize()
        {
            XWPFDocument doc     = new XWPFDocument();
            CT_Tbl       ctTable = new CT_Tbl();
            XWPFTable    table   = new XWPFTable(ctTable, doc);

            table.RowBandSize = 12;
            int sz = table.RowBandSize;

            Assert.AreEqual(12, sz);
        }
Exemplo n.º 20
0
        /**
         * Get a table by its CTTbl-Object
         * @see Npoi.Core.XWPF.UserModel.IBody#getTable(org.Openxmlformats.schemas.wordProcessingml.x2006.main.CTTbl)
         */

        public XWPFTable GetTable(CT_Tbl ctTable)
        {
            for (int i = 0; i < tables.Count; i++)
            {
                if (this.Tables[(i)].GetCTTbl() == ctTable)
                {
                    return(Tables[(i)]);
                }
            }
            return(null);
        }
Exemplo n.º 21
0
        public void TestSetGetHeight()
        {
            XWPFDocument doc = new XWPFDocument();

            CT_Tbl table = new CT_Tbl();

            XWPFTable    xtab = new XWPFTable(table, doc);
            XWPFTableRow row  = xtab.CreateRow();

            row.SetHeight(20);
            Assert.AreEqual(20, row.GetHeight());
        }
Exemplo n.º 22
0
        public void TestTblGrid()
        {
            XWPFDocument doc = new XWPFDocument();
            CT_Tbl ctTable = new CT_Tbl();
            CT_TblGrid cttblgrid = ctTable.AddNewTblGrid();
            cttblgrid.AddNewGridCol().w = 123;
            cttblgrid.AddNewGridCol().w = 321;

            XWPFTable xtab = new XWPFTable(ctTable, doc);
            Assert.AreEqual(123, xtab.GetCTTbl().tblGrid.gridCol[0].w);
            Assert.AreEqual(321, xtab.GetCTTbl().tblGrid.gridCol[1].w);
        }
Exemplo n.º 23
0
 public XWPFTable(CT_Tbl table, IBody part, int row, int col)
     : this(table, part)
 {
     for (int i = 0; i < row; i++)
     {
         XWPFTableRow tabRow = (GetRow(i) == null) ? CreateRow() : GetRow(i);
         for (int k = 0; k < col; k++)
         {
             XWPFTableCell tabCell = (tabRow.GetCell(k) == null) ? tabRow
                                     .CreateCell() : null;
         }
     }
 }
Exemplo n.º 24
0
        public void TestGetText()
        {
            XWPFDocument doc = new XWPFDocument();
            CT_Tbl table = new CT_Tbl();
            CT_Row row = table.AddNewTr();
            CT_Tc cell = row.AddNewTc();
            CT_P paragraph = cell.AddNewP();
            CT_R run = paragraph.AddNewR();
            CT_Text text = run.AddNewT();
            text.Value = ("finally I can Write!");

            XWPFTable xtab = new XWPFTable(table, doc);
            Assert.AreEqual("finally I can Write!\n", xtab.Text);
        }
Exemplo n.º 25
0
        public void TestTblGrid()
        {
            XWPFDocument doc       = new XWPFDocument();
            CT_Tbl       ctTable   = new CT_Tbl();
            CT_TblGrid   cttblgrid = ctTable.AddNewTblGrid();

            cttblgrid.AddNewGridCol().w = 123;
            cttblgrid.AddNewGridCol().w = 321;

            XWPFTable xtab = new XWPFTable(ctTable, doc);

            Assert.AreEqual(123, xtab.GetCTTbl().tblGrid.gridCol[0].w);
            Assert.AreEqual(321, xtab.GetCTTbl().tblGrid.gridCol[1].w);
        }
Exemplo n.º 26
0
        public XWPFTable(CT_Tbl table, IBody part, int row, int col)
            : this(table, part)
        {

            for (int i = 0; i < row; i++)
            {
                XWPFTableRow tabRow = (GetRow(i) == null) ? CreateRow() : GetRow(i);
                for (int k = 0; k < col; k++)
                {
                    XWPFTableCell tabCell = (tabRow.GetCell(k) == null) ? tabRow
                            .CreateCell() : null;
                }
            }
        }
Exemplo n.º 27
0
        private static void word_init(XWPFDocument m_Docx, String prjName)
        {
            //设置页面 将页面设置为A4 纵向
            //参考网站  http://www.aiuxian.com/article/p-1970779.html
            CT_SectPr m_SectPr = new CT_SectPr();

            m_SectPr.pgSz.w             = (ulong)11906;
            m_SectPr.pgSz.h             = (ulong)16838;
            m_Docx.Document.body.sectPr = m_SectPr;

            //第一页 封面
            word_insert_space(5, m_Docx);
            word_insert_text(m_Docx, "宋体", 22, prjName);
            word_insert_text(m_Docx, "宋体", 22, "GSM-R 通信系统");
            word_insert_text(m_Docx, "宋体", 22, "现场勘查报告");
            word_insert_space(7, m_Docx);
            word_insert_text(m_Docx, "宋体", 22, DateTime.Now.ToString("yyyy年MM月dd日"));
            word_insert_space(7, m_Docx);


            //创建表并获取该表
            XWPFTable table = m_Docx.CreateTable(4, 2);
            CT_Tbl    ctbl  = m_Docx.Document.body.GetTblArray()[0];

            //表居中
            ctbl.AddNewTblPr().jc = new CT_Jc();
            ctbl.AddNewTblPr().jc.val = ST_Jc.center;
            //表宽度为8000
            ctbl.AddNewTblPr().AddNewTblW().w    = "8000";
            ctbl.AddNewTblPr().AddNewTblW().type = ST_TblWidth.dxa;

            //列宽设置
            CT_TcPr m_Pr = table.GetRow(0).GetCell(1).GetCTTc().AddNewTcPr();

            m_Pr.tcW      = new CT_TblWidth();
            m_Pr.tcW.w    = "3000";
            m_Pr.tcW.type = ST_TblWidth.dxa;

            //行高设置


            //设置表中文本
            table.GetRow(0).GetCell(0).SetText("项目");
            table.GetRow(1).GetCell(0).SetText("勘察日期");
            table.GetRow(2).GetCell(0).SetText("现场勘查人员");
            table.GetRow(3).GetCell(0).SetText("报告修正人员");

            word_insert_space(4, m_Docx);
        }
Exemplo n.º 28
0
        public void TestSetGetRepeatHeader()
        {
            // create a table
            XWPFDocument doc = new XWPFDocument();
            CT_Tbl ctTable = new CT_Tbl();
            XWPFTable table = new XWPFTable(ctTable, doc);
            // table has a single row by default; grab it
            XWPFTableRow tr = table.GetRow(0);
            Assert.IsNotNull(tr);

            tr.SetRepeatHeader(true);
            bool isRpt = tr.IsRepeatHeader();
            //assert(isRpt);
            Assert.IsTrue(isRpt);
        }
Exemplo n.º 29
0
        /**
         * inserts an existing XWPFTable to the arrays bodyElements and tables
         * @param pos
         * @param table
         */
        public void InsertTable(int pos, XWPFTable table)
        {
            bodyElements.Insert(pos, table);
            int i;

            for (i = 0; i < headerFooter.GetTblList().Count; i++)
            {
                CT_Tbl tbl = headerFooter.GetTblArray(i);
                if (tbl == table.GetCTTbl())
                {
                    break;
                }
            }
            tables.Insert(i, table);
        }
Exemplo n.º 30
0
 public XWPFTable GetTable(CT_Tbl ctTable)
 {
     foreach (XWPFTable table in this.tables)
     {
         if (table == null)
         {
             return((XWPFTable)null);
         }
         if (table.GetCTTbl().Equals((object)ctTable))
         {
             return(table);
         }
     }
     return((XWPFTable)null);
 }
Exemplo n.º 31
0
        public void TestSetGetCantSplitRow()
        {
            // create a table
            XWPFDocument doc = new XWPFDocument();
            CT_Tbl ctTable = new CT_Tbl();
            XWPFTable table = new XWPFTable(ctTable, doc);
            // table has a single row by default; grab it
            XWPFTableRow tr = table.GetRow(0);
            Assert.IsNotNull(tr);

            tr.IsCantSplitRow = true;
            bool isCant = tr.IsCantSplitRow;
            //assert(isCant);
            Assert.IsTrue(isCant);
        }
Exemplo n.º 32
0
 /**
  * if there is a corresponding {@link XWPFTable} of the parameter ctTable in the tableList of this header
  * the method will return this table
  * if there is no corresponding {@link XWPFTable} the method will return null
  * @param ctTable
  */
 public XWPFTable GetTable(CT_Tbl ctTable)
 {
     foreach (XWPFTable table in tables)
     {
         if (table == null)
         {
             return(null);
         }
         if (table.GetCTTbl().Equals(ctTable))
         {
             return(table);
         }
     }
     return(null);
 }
Exemplo n.º 33
0
        public void TestSetGetWidth()
        {
            XWPFDocument doc = new XWPFDocument();

            CT_Tbl table = new CT_Tbl();

            table.AddNewTblPr().AddNewTblW().w = "1000";

            XWPFTable xtab = new XWPFTable(table, doc);

            Assert.AreEqual(1000, xtab.GetWidth());

            xtab.SetWidth(100);
            Assert.AreEqual(100, int.Parse(table.tblPr.tblW.w));
        }
Exemplo n.º 34
0
        public void Test54099()
        {
            XWPFDocument doc = new XWPFDocument();
            CT_Tbl ctTable = new CT_Tbl();
            XWPFTable table = new XWPFTable(ctTable, doc);
            XWPFTableRow tr = table.GetRow(0);
            XWPFTableCell cell = tr.GetCell(0);

            CT_Tc ctTc = cell.GetCTTc();
            CT_TcPr tcPr = ctTc.AddNewTcPr();
            CT_HMerge hMerge = tcPr.AddNewHMerge();
            hMerge.val = (ST_Merge.restart);

            CT_TcBorders tblBorders = tcPr.AddNewTcBorders();
            CT_VMerge vMerge = tcPr.AddNewVMerge();
        }
Exemplo n.º 35
0
        public void TestSetTableDescription()
        {
            // create a table
            XWPFDocument doc     = new XWPFDocument();
            CT_Tbl       ctTable = new CT_Tbl();
            XWPFTable    table   = new XWPFTable(ctTable, doc);

            //Set Description
            table.TableDescription = "%TABLEDESCRIPTION%";

            //Check
            CT_String tblDesc = table.GetCTTbl().tblPr.tblDescription;

            Assert.IsNotNull(tblDesc);
            Assert.AreEqual("%TABLEDESCRIPTION%", tblDesc.val);
        }
Exemplo n.º 36
0
        public XWPFTable(CT_Tbl table, IBody part, int row, int col)
            : this(table, part)
        {
            for (int pos1 = 0; pos1 < row; ++pos1)
            {
                XWPFTableRow xwpfTableRow = this.GetRow(pos1) == null?this.CreateRow() : this.GetRow(pos1);

                for (int pos2 = 0; pos2 < col; ++pos2)
                {
                    if (xwpfTableRow.GetCell(pos2) == null)
                    {
                        xwpfTableRow.CreateCell();
                    }
                }
            }
        }
Exemplo n.º 37
0
        public void TestSetGetColor()
        {
            // create a table
            XWPFDocument doc = new XWPFDocument();
            CT_Tbl ctTable = new CT_Tbl();
            XWPFTable table = new XWPFTable(ctTable, doc);
            // table has a single row by default; grab it
            XWPFTableRow tr = table.GetRow(0);
            Assert.IsNotNull(tr);
            // row has a single cell by default; grab it
            XWPFTableCell cell = tr.GetCell(0);

            cell.SetColor("F0000F");
            String clr = cell.GetColor();
            Assert.AreEqual("F0000F", clr);
        }
Exemplo n.º 38
0
        public void TestSetGetRepeatHeader()
        {
            // create a table
            XWPFDocument doc     = new XWPFDocument();
            CT_Tbl       ctTable = new CT_Tbl();
            XWPFTable    table   = new XWPFTable(ctTable, doc);
            // table has a single row by default; grab it
            XWPFTableRow tr = table.GetRow(0);

            Assert.IsNotNull(tr);

            tr.IsRepeatHeader = true;
            bool isRpt = tr.IsRepeatHeader;

            Assert.IsTrue(isRpt);
        }
Exemplo n.º 39
0
        public void TestGetText()
        {
            XWPFDocument doc       = new XWPFDocument();
            CT_Tbl       table     = new CT_Tbl();
            CT_Row       row       = table.AddNewTr();
            CT_Tc        cell      = row.AddNewTc();
            CT_P         paragraph = cell.AddNewP();
            CT_R         run       = paragraph.AddNewR();
            CT_Text      text      = run.AddNewT();

            text.Value = ("finally I can Write!");

            XWPFTable xtab = new XWPFTable(table, doc);

            Assert.AreEqual("finally I can Write!\n", xtab.GetText());
        }
Exemplo n.º 40
0
        /// <summary>
        /// 生成模板文件
        /// </summary>
        /// <param name="m_Docx">根文档</param>
        private static void word_init(XWPFDocument m_Docx)
        {
            //1‘=1440twip=25.4mm=72pt(磅point)=96px(像素pixel)
            //1px(像素pixel)=0.75pt(磅point)
            // A4:W=11906 twip=8.269''=210mm,h=16838twip=11.693''=297mm
            //A5:W=8390 twip=5.827''=148mm,h=11906 twip=8.269''=210mm
            //A6:W=5953 twip=4.134''=105mm,h=8390twip=5.827''=1148mm
            //16k195mmX270mm:
            //16k184mmX260mm:
            //16k197mmX273mm:
            CT_SectPr m_SectPr = new CT_SectPr();

            //页面设置A4纵向
            m_SectPr.pgSz.w             = (ulong)11906;
            m_SectPr.pgSz.h             = (ulong)16838;
            m_Docx.Document.body.sectPr = m_SectPr;
            //第一页
            word_insert_space(4, m_Docx);
            word_insert_text(m_Docx, "宋体", 22, "【项目名称】");
            word_insert_text(m_Docx, "宋体", 22, "GSM-R 通信系统");
            word_insert_text(m_Docx, "宋体", 22, "现场勘查报告");

            word_insert_space(8, m_Docx);
            word_insert_text(m_Docx, "宋体", 22, "【日期】");

            word_insert_space(7, m_Docx);
            //第二页
            //表1
            XWPFTable table  = m_Docx.CreateTable(4, 2);
            CT_Tbl    ctbl   = m_Docx.Document.body.GetTblArray()[0];
            CT_TblPr  ctblpr = ctbl.AddNewTblPr();

            ctblpr.jc     = new CT_Jc();
            ctblpr.jc.val = ST_Jc.center;
            table.Width   = 4000;
            table.GetRow(0).GetCell(0).SetText("项目");
            table.GetRow(1).GetCell(0).SetText("日期");
            table.GetRow(2).GetCell(0).SetText("现场勘查人员");
            table.GetRow(3).GetCell(0).SetText("报告编制人员");
            CT_TcPr m_Pr = table.GetRow(0).GetCell(1).GetCTTc().AddNewTcPr();

            m_Pr.tcW      = new CT_TblWidth();
            m_Pr.tcW.w    = "4000";
            m_Pr.tcW.type = ST_TblWidth.dxa; //设置单元格宽度
            word_insert_space(2, m_Docx);
            word_insert_text(m_Docx, "宋体", 12, "基站勘察表");
        }
Exemplo n.º 41
0
        public void TestConstructor()
        {
            XWPFDocument doc = new XWPFDocument();
            CT_Tbl ctTable = new CT_Tbl();
            XWPFTable xtab = new XWPFTable(ctTable, doc);
            Assert.IsNotNull(xtab);
            Assert.AreEqual(1, ctTable.SizeOfTrArray());
            Assert.AreEqual(1, ctTable.GetTrArray(0).SizeOfTcArray());
            Assert.IsNotNull(ctTable.GetTrArray(0).GetTcArray(0).GetPArray(0));

            ctTable = new CT_Tbl();
            xtab = new XWPFTable(ctTable, doc, 3, 2);
            Assert.IsNotNull(xtab);
            Assert.AreEqual(3, ctTable.SizeOfTrArray());
            Assert.AreEqual(2, ctTable.GetTrArray(0).SizeOfTcArray());
            Assert.IsNotNull(ctTable.GetTrArray(0).GetTcArray(0).GetPArray(0));
        }
Exemplo n.º 42
0
        public XWPFTable(CT_Tbl table, IBody part, int row, int col)
            : this(table, part)
        {

            CT_TblGrid ctTblGrid = table.AddNewTblGrid();
            for (int j = 0; j < col; j++)
            {
                CT_TblGridCol ctGridCol= ctTblGrid.AddNewGridCol();
                ctGridCol.w = 300;
            }
            for (int i = 0; i < row; i++)
            {
                XWPFTableRow tabRow = (GetRow(i) == null) ? CreateRow() : GetRow(i);
                for (int k = 0; k < col; k++)
                {
                    if (tabRow.GetCell(k) == null)
                    {
                        tabRow.CreateCell();
                    }
                }
            }
        }
Exemplo n.º 43
0
 public void TestSetGetColBandSize()
 {
     XWPFDocument doc = new XWPFDocument();
     CT_Tbl ctTable = new CT_Tbl();
     XWPFTable table = new XWPFTable(ctTable, doc);
     table.ColBandSize = 16;
     int sz = table.ColBandSize;
     Assert.AreEqual(16, sz);
 }
Exemplo n.º 44
0
 public void TestSetGetRowBandSize()
 {
     XWPFDocument doc = new XWPFDocument();
     CT_Tbl ctTable = new CT_Tbl();
     XWPFTable table = new XWPFTable(ctTable, doc);
     table.SetRowBandSize(12);
     int sz = table.GetRowBandSize();
     Assert.AreEqual(12, sz);
 }
Exemplo n.º 45
0
        private void CreateEmptyTable(CT_Tbl table)
        {
            // MINIMUM ELEMENTS FOR A TABLE
            table.AddNewTr().AddNewTc().AddNewP();

            CT_TblPr tblpro = table.AddNewTblPr();
            if (!tblpro.IsSetTblW())
                tblpro.AddNewTblW().w = "0";
            tblpro.tblW.type=(ST_TblWidth.auto);

            // layout
            // tblpro.AddNewTblLayout().Type=(STTblLayoutType.AUTOFIT);

            // borders
            CT_TblBorders borders = tblpro.AddNewTblBorders();
            borders.AddNewBottom().val=(ST_Border.single);
            borders.AddNewInsideH().val = (ST_Border.single);
            borders.AddNewInsideV().val = (ST_Border.single);
            borders.AddNewLeft().val = (ST_Border.single);
            borders.AddNewRight().val = (ST_Border.single);
            borders.AddNewTop().val = (ST_Border.single);

            /*
           * CTTblGrid tblgrid=table.AddNewTblGrid();
           * tblgrid.AddNewGridCol().W=(new Bigint("2000"));
           */
            GetRows();
        }
Exemplo n.º 46
0
        private void CreateEmptyTable(CT_Tbl table)
        {
            // MINIMUM ELEMENTS FOR A TABLE
            table.AddNewTr().AddNewTc().AddNewP();

            CT_TblPr tblpro = table.AddNewTblPr();
            if (!tblpro.IsSetTblW())
                tblpro.AddNewTblW().w = "0";
            tblpro.tblW.type=(ST_TblWidth.auto);

            // layout
             tblpro.AddNewTblLayout().type =  ST_TblLayoutType.autofit;

            // borders
            CT_TblBorders borders = tblpro.AddNewTblBorders();
            borders.AddNewBottom().val=ST_Border.single;
            borders.AddNewInsideH().val = ST_Border.single;
            borders.AddNewInsideV().val = ST_Border.single;
            borders.AddNewLeft().val = ST_Border.single;
            borders.AddNewRight().val = ST_Border.single;
            borders.AddNewTop().val = ST_Border.single;

            
            CT_TblGrid tblgrid=table.AddNewTblGrid();
            tblgrid.AddNewGridCol().w= (ulong)2000;
           
        }
Exemplo n.º 47
0
 /**
  * Get a table by its CTTbl-Object
  * @see NPOI.XWPF.UserModel.IBody#getTable(org.Openxmlformats.schemas.wordProcessingml.x2006.main.CTTbl)
  */
 public XWPFTable GetTable(CT_Tbl ctTable)
 {
     for(int i=0; i<tables.Count; i++){
         if(this.Tables[(i)].GetCTTbl() == ctTable) return Tables[(i)]; 
     }
     return null;
 }
Exemplo n.º 48
0
 /**
  * Get a table by its CTTbl-Object
  * @param ctTbl
  * @see NPOI.XWPF.UserModel.IBody#getTable(org.Openxmlformats.schemas.wordProcessingml.x2006.main.CTTbl)
  * @return a table by its CTTbl-Object or null
  */
 public XWPFTable GetTable(CT_Tbl ctTbl)
 {
     for (int i = 0; i < tables.Count; i++)
     {
         if (tables[i].GetCTTbl() == ctTbl)
         {
             return tables[i];
         }
     }
     return null;
 }
Exemplo n.º 49
0
        public void TestSetGetWidth()
        {
            XWPFDocument doc = new XWPFDocument();

            CT_Tbl table = new CT_Tbl();
            table.AddNewTblPr().AddNewTblW().w = "1000";

            XWPFTable xtab = new XWPFTable(table, doc);

            Assert.AreEqual(1000, xtab.Width);

            xtab.Width = 100;
            Assert.AreEqual(100, int.Parse(table.tblPr.tblW.w));
        }
Exemplo n.º 50
0
        public void TestSetGetHeight()
        {
            XWPFDocument doc = new XWPFDocument();

            CT_Tbl table = new CT_Tbl();

            XWPFTable xtab = new XWPFTable(table, doc);
            XWPFTableRow row = xtab.CreateRow();
            row.Height = (20);
            Assert.AreEqual(20, row.Height);
        }
Exemplo n.º 51
0
 public void TestSetGetMargins()
 {
     // instantiate the following class so it'll Get picked up by
     // the XmlBean process and Added to the jar file. it's required
     // for the following XWPFTable methods.
     CT_TblCellMar ctm = new CT_TblCellMar();
     Assert.IsNotNull(ctm);
     // create a table
     XWPFDocument doc = new XWPFDocument();
     CT_Tbl ctTable = new CT_Tbl();
     XWPFTable table = new XWPFTable(ctTable, doc);
     // Set margins
     table.SetCellMargins(50, 50, 250, 450);
     // Get margin components
     int t = table.CellMarginTop;
     Assert.AreEqual(50, t);
     int l = table.CellMarginLeft;
     Assert.AreEqual(50, l);
     int b = table.CellMarginBottom;
     Assert.AreEqual(250, b);
     int r = table.CellMarginRight;
     Assert.AreEqual(450, r);
 }
Exemplo n.º 52
0
 public void TestSetGetHBorders()
 {
     // instantiate the following classes so they'll Get picked up by
     // the XmlBean process and Added to the jar file. they are required
     // for the following XWPFTable methods.
     CT_TblBorders cttb = new CT_TblBorders();
     Assert.IsNotNull(cttb);
     ST_Border stb = new ST_Border();
     Assert.IsNotNull(stb);
     // create a table
     XWPFDocument doc = new XWPFDocument();
     CT_Tbl ctTable = new CT_Tbl();
     XWPFTable table = new XWPFTable(ctTable, doc);
     // Set inside horizontal border
     table.SetInsideHBorder(NPOI.XWPF.UserModel.XWPFTable.XWPFBorderType.SINGLE, 4, 0, "FF0000");
     // Get inside horizontal border components
     int s = table.InsideHBorderSize;
     Assert.AreEqual(4, s);
     int sp = table.InsideHBorderSpace;
     Assert.AreEqual(0, sp);
     String clr = table.InsideHBorderColor;
     Assert.AreEqual("FF0000", clr);
     NPOI.XWPF.UserModel.XWPFTable.XWPFBorderType bt = table.InsideHBorderType;
     Assert.AreEqual(NPOI.XWPF.UserModel.XWPFTable.XWPFBorderType.SINGLE, bt);
 }
Exemplo n.º 53
0
 public void TestSetGetVBorders()
 {
     // create a table
     XWPFDocument doc = new XWPFDocument();
     CT_Tbl ctTable = new CT_Tbl();
     XWPFTable table = new XWPFTable(ctTable, doc);
     // Set inside vertical border
     table.SetInsideVBorder(NPOI.XWPF.UserModel.XWPFTable.XWPFBorderType.DOUBLE, 4, 0, "00FF00");
     // Get inside vertical border components
     NPOI.XWPF.UserModel.XWPFTable.XWPFBorderType bt = table.InsideVBorderType;
     Assert.AreEqual(NPOI.XWPF.UserModel.XWPFTable.XWPFBorderType.DOUBLE, bt);
     int sz = table.InsideVBorderSize;
     Assert.AreEqual(4, sz);
     int sp = table.InsideVBorderSpace;
     Assert.AreEqual(0, sp);
     String clr = table.InsideVBorderColor;
     Assert.AreEqual("00FF00", clr);
 }
Exemplo n.º 54
0
 /**
  * if there is a corresponding {@link XWPFTable} of the parameter ctTable in the tableList of this header
  * the method will return this table
  * if there is no corresponding {@link XWPFTable} the method will return null 
  * @param ctTable
  */
 public XWPFTable GetTable(CT_Tbl ctTable)
 {
     foreach (XWPFTable table in tables)
     {
         if (table == null)
             return null;
         if (table.GetCTTbl().Equals(ctTable))
             return table;
     }
     return null;
 }