Esempio n. 1
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.NumberOfRows);
            Assert.IsNotNull(xtab.GetRow(2));

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

            //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());
        }
Esempio n. 2
0
 public XWPFHeader(XWPFDocument doc, CT_HdrFtr hdrFtr)
     : base(doc, hdrFtr)
 {
     /*
     XmlCursor cursor = headerFooter.NewCursor();
     cursor.SelectPath("./*");
     while (cursor.ToNextSelection()) {
         XmlObject o = cursor.Object;
         if (o is CTP) {
             XWPFParagraph p = new XWPFParagraph((CTP) o, this);
             paragraphs.Add(p);
         }
         if (o is CTTbl) {
             XWPFTable t = new XWPFTable((CTTbl) o, this);
             tables.Add(t);
         }
     }
     cursor.Dispose();*/
     foreach (object o in hdrFtr.Items)
     {
         if (o is CT_P)
         {
             XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
             paragraphs.Add(p);
         }
         if (o is CT_Tbl)
         {
             XWPFTable t = new XWPFTable((CT_Tbl)o, this);
             tables.Add(t);
         }
     }
 }
        private bool Row2Cell1Contains(XWPFTable table, string value)
        {
            try
            {
                System.Diagnostics.Debug.WriteLine(string.Format("Rows: {0}", table.Rows.Count));
                if (table.Rows.Count > 2)
                {
                    XWPFTableCell cel = table.Rows[2].GetCell(1);
                    {
                        string celtext = CellText.GetCellText(cel);
                        //System.Diagnostics.Debug.WriteLine(string.Format("Row: 2, Cell: 1 - {0} ", celtext));
                        if (celtext.StartsWith(value))
                            return true;
                    }
                }
                else
                {
                    return false;
                }
            }
            catch (System.NullReferenceException nullex)
            {
                string message = nullex.Message;
                return false;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }

            return false;
        }
Esempio 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();
            Assert.AreEqual(XWPFTableCell.XWPFVertAlign.BOTH, al);
        }
Esempio n. 5
0
 public XWPFSDTContent(CT_SdtContentBlock block, IBody part, IRunBody parent)
 {
     
     foreach (object o in block.Items)
     {
         if (o is CT_P)
         {
             XWPFParagraph p = new XWPFParagraph((CT_P)o, part);
             bodyElements.Add(p);
             paragraphs.Add(p);
         }
         else if (o is CT_Tbl)
         {
             XWPFTable t = new XWPFTable((CT_Tbl)o, part);
             bodyElements.Add(t);
             tables.Add(t);
         }
         else if (o is CT_SdtBlock)
         {
             XWPFSDT c = new XWPFSDT(((CT_SdtBlock)o), part);
             bodyElements.Add(c);
             contentControls.Add(c);
         }
         else if (o is CT_R)
         {
             XWPFRun run = new XWPFRun((CT_R)o, parent);
             runs.Add(run);
             bodyElements.Add(run);
         }
     }
 }
 private bool SecondRowFirstCellContainsInnoc(XWPFTable table)
 {
     XWPFTableCell cel = table.Rows[1].GetCell(0);
     {
         string celtext = CellText.GetCellText(cel);
         if (celtext.StartsWith("Inoc"))
             return true;
     }
     return false;
 }
 private bool FirstRowContainsGc(XWPFTable table)
 {
     List<XWPFTableCell> cells = table.Rows[0].GetTableCells();
     foreach (XWPFTableCell cel in cells)
     {
         string celtext = CellText.GetCellText(cel);
         if (celtext.StartsWith("GC"))
             return true;
     }
     return false;
 }
Esempio n. 8
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);
        }
Esempio n. 9
0
        /**
         * Reads the document
         * @throws IOException
         */

        internal override void OnDocumentRead()
        {
            base.OnDocumentRead();
            HdrDocument hdrDocument = null;
            Stream      is1;

            try
            {
                is1          = GetPackagePart().GetInputStream();
                hdrDocument  = HdrDocument.Parse(is1);
                headerFooter = hdrDocument.Hdr;
                foreach (object o in headerFooter.Items)
                {
                    if (o is CT_P)
                    {
                        XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
                        paragraphs.Add(p);
                        bodyElements.Add(p);
                    }
                    if (o is CT_Tbl)
                    {
                        XWPFTable t = new XWPFTable((CT_Tbl)o, this);
                        tables.Add(t);
                        bodyElements.Add(t);
                    }
                }
                // parse the document with cursor and add
                // the XmlObject to its lists

                /*XmlCursor cursor = headerFooter.NewCursor();
                 * cursor.SelectPath("./*");
                 * while (cursor.ToNextSelection()) {
                 *  XmlObject o = cursor.Object;
                 *  if (o is CTP) {
                 *      XWPFParagraph p = new XWPFParagraph((CTP)o, this);
                 *      paragraphs.Add(p);
                 *      bodyElements.Add(p);
                 *  }
                 *  if (o is CTTbl) {
                 *      XWPFTable t = new XWPFTable((CTTbl)o, this);
                 *      tables.Add(t);
                 *      bodyElements.Add(t);
                 *  }
                 * }
                 * cursor.Dispose();*/
            }
            catch (Exception e)
            {
                throw new POIXMLException(e);
            }
        }
Esempio n. 10
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);
        }
Esempio n. 11
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());
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        public void Bug57495_getParagraphArrayInTableCell()
        {
            XWPFDocument doc = new XWPFDocument();
            //let's create a table for the test
            XWPFTable table = doc.CreateTable(2, 2);

            Assert.IsNotNull(table);
            XWPFParagraph p = table.GetRow(0).GetCell(0).GetParagraphArray(0);

            Assert.IsNotNull(p);
            //let's check also that returns the correct paragraph
            XWPFParagraph same = table.GetRow(0).GetCell(0).Paragraphs[0];

            Assert.AreEqual(p, same);
        }
Esempio n. 14
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));
        }
Esempio n. 15
0
        public void TestCellVerticalAlign()
        {
            XWPFDocument      docx   = XWPFTestDataSamples.OpenSampleDocument("59030.docx");
            IList <XWPFTable> tables = docx.Tables;

            Assert.AreEqual(1, tables.Count);
            XWPFTable           table     = tables[0];
            List <XWPFTableRow> tableRows = table.Rows;

            Assert.AreEqual(2, tableRows.Count);
            Assert.AreEqual(XWPFVertAlign.TOP, tableRows[0].GetCell(0).GetVerticalAlignment());
            Assert.AreEqual(XWPFVertAlign.BOTTOM, tableRows[0].GetCell(1).GetVerticalAlignment());
            Assert.AreEqual(XWPFVertAlign.CENTER, tableRows[1].GetCell(0).GetVerticalAlignment());
            Assert.AreEqual(XWPFVertAlign.TOP, tableRows[1].GetCell(1).GetVerticalAlignment());
        }
Esempio n. 16
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);
        }
Esempio n. 17
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);
        }
Esempio n. 18
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);
        }
Esempio n. 19
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());
        }
Esempio n. 20
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);
        }
Esempio n. 21
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();
        }
Esempio n. 22
0
        /**
         * If a table cell does not include at least one block-level element, then this document shall be considered corrupt
         */
        public XWPFTableCell(CT_Tc cell, XWPFTableRow tableRow, IBody part)
        {
            this.ctTc     = cell;
            this.part     = part;
            this.tableRow = tableRow;
            // NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt.
            if (cell.GetPList().Count < 1)
            {
                cell.AddNewP();
            }
            bodyElements = new List <IBodyElement>();
            paragraphs   = new List <XWPFParagraph>();
            tables       = new List <XWPFTable>();
            foreach (object o in ctTc.Items)
            {
                if (o is CT_P)
                {
                    XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
                    paragraphs.Add(p);
                    bodyElements.Add(p);
                }
                if (o is CT_Tbl)
                {
                    XWPFTable t = new XWPFTable((CT_Tbl)o, this);
                    tables.Add(t);
                    bodyElements.Add(t);
                }
            }

            /*
             *  XmlCursor cursor = ctTc.NewCursor();
             *  cursor.SelectPath("./*");
             *  while (cursor.ToNextSelection()) {
             *      XmlObject o = cursor.Object;
             *      if (o is CTP) {
             *          XWPFParagraph p = new XWPFParagraph((CTP)o, this);
             *          paragraphs.Add(p);
             *          bodyElements.Add(p);
             *      }
             *      if (o is CTTbl) {
             *          XWPFTable t = new XWPFTable((CTTbl)o, this);
             *          tables.Add(t);
             *          bodyElements.Add(t);
             *      }
             *  }
             *  cursor.Dispose();*/
        }
Esempio n. 23
0
        public void Bug57495_getTableArrayInDoc()
        {
            XWPFDocument doc = new XWPFDocument();

            //let's create a few tables for the test
            for (int i = 0; i < 3; i++)
            {
                doc.CreateTable(2, 2);
            }
            XWPFTable table = doc.GetTableArray(0);

            Assert.IsNotNull(table);
            //let's check also that returns the correct table
            XWPFTable same = doc.Tables[0];

            Assert.AreEqual(table, same);
        }
Esempio n. 24
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.SetCantSplitRow(true);
            bool isCant = tr.IsCantSplitRow();

            //assert(isCant);
            Assert.IsTrue(isCant);
        }
Esempio n. 25
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();
        }
Esempio n. 26
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));
        }
Esempio n. 27
0
        /// <summary>
        /// Read the document
        /// </summary>
        internal override void OnDocumentRead()
        {
            base.OnDocumentRead();
            HdrDocument hdrDocument = null;
            Stream      is1         = null;

            try
            {
                is1 = GetPackagePart().GetInputStream();
                XmlDocument xmldoc = DocumentHelper.LoadDocument(is1);
                hdrDocument  = HdrDocument.Parse(xmldoc, NamespaceManager);
                headerFooter = hdrDocument.Hdr;
                foreach (object o in headerFooter.Items)
                {
                    if (o is CT_P)
                    {
                        XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
                        paragraphs.Add(p);
                        bodyElements.Add(p);
                    }
                    if (o is CT_Tbl)
                    {
                        XWPFTable t = new XWPFTable((CT_Tbl)o, this);
                        tables.Add(t);
                        bodyElements.Add(t);
                    }
                    if (o is CT_SdtBlock)
                    {
                        XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this);
                        bodyElements.Add(c);
                    }
                }
            }
            catch (Exception e)
            {
                throw new POIXMLException(e);
            }
            finally
            {
                if (is1 != null)
                {
                    is1.Close();
                }
            }
        }
Esempio n. 28
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);
        }
Esempio n. 29
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));
        }
Esempio n. 30
0
 /**
  * If a table cell does not include at least one block-level element, then this document shall be considered corrupt
  */
 public XWPFTableCell(CT_Tc cell, XWPFTableRow tableRow, IBody part)
 {
     this.ctTc = cell;
     this.part = part;
     this.tableRow = tableRow;
     // NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt.
     if(cell.GetPList().Count<1)
         cell.AddNewP();
     bodyElements = new List<IBodyElement>();
     paragraphs = new List<XWPFParagraph>();
     tables = new List<XWPFTable>();
     foreach (object o in ctTc.Items)
     {
         if (o is CT_P)
         {
             XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
             paragraphs.Add(p);
             bodyElements.Add(p);
         }
         if (o is CT_Tbl)
         {
             XWPFTable t = new XWPFTable((CT_Tbl)o, this);
             tables.Add(t);
             bodyElements.Add(t);
         }
     }
 /*
     XmlCursor cursor = ctTc.NewCursor();
     cursor.SelectPath("./*");
     while (cursor.ToNextSelection()) {
         XmlObject o = cursor.Object;
         if (o is CTP) {
             XWPFParagraph p = new XWPFParagraph((CTP)o, this);
             paragraphs.Add(p);
             bodyElements.Add(p);
         }
         if (o is CTTbl) {
             XWPFTable t = new XWPFTable((CTTbl)o, this);
             tables.Add(t);
             bodyElements.Add(t);
         }
     }
     cursor.Dispose();*/
 }
Esempio n. 31
0
        public void ReadHdrFtr()
        {
            bodyElements = new List <IBodyElement>();
            paragraphs   = new List <XWPFParagraph>();
            tables       = new List <XWPFTable>();
            // parse the document with cursor and add
            // the XmlObject to its lists
            foreach (object o in headerFooter.Items)
            {
                if (o is CT_P)
                {
                    XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
                    paragraphs.Add(p);
                    bodyElements.Add(p);
                }
                if (o is CT_Tbl)
                {
                    XWPFTable t = new XWPFTable((CT_Tbl)o, this);
                    tables.Add(t);
                    bodyElements.Add(t);
                }
            }

            /*XmlCursor cursor = headerFooter.NewCursor();
             * cursor.SelectPath("./*");
             * while (cursor.ToNextSelection())
             * {
             *  XmlObject o = cursor.Object;
             *  if (o is CTP)
             *  {
             *      XWPFParagraph p = new XWPFParagraph((CTP)o, this);
             *      paragraphs.Add(p);
             *      bodyElements.Add(p);
             *  }
             *  if (o is CTTbl)
             *  {
             *      XWPFTable t = new XWPFTable((CTTbl)o, this);
             *      tables.Add(t);
             *      bodyElements.Add(t);
             *  }
             * }
             * cursor.Dispose();*/
        }
        private void SetHeadings(ref XWPFDocument doc, XWPFTable table)
        {
            XWPFParagraph p1 = doc.CreateParagraph();
            XWPFRun r1 = p1.CreateRun();
            r1.SetBold(true);
            r1.SetText("Category");
            r1.SetBold(true);
            r1.SetFontFamily("Courier");
            table.GetRow(0).GetCell(0).SetParagraph(p1);

            XWPFParagraph p2 = doc.CreateParagraph();
            XWPFRun r2 = p2.CreateRun();
            r2.SetBold(true);
            r2.SetText("Category");
            r2.SetBold(true);
            r2.SetFontFamily("Courier");
            table.GetRow(0).GetCell(1).SetParagraph(p2);


        }
Esempio n. 33
0
        private List <AbstractXWPFSDT> ExtractSDTsFromTable(XWPFTable table)
        {
            List <AbstractXWPFSDT> sdts = new List <AbstractXWPFSDT>();

            foreach (XWPFTableRow r in table.Rows)
            {
                foreach (ICell c in r.GetTableICells())
                {
                    if (c is XWPFSDTCell)
                    {
                        sdts.Add((XWPFSDTCell)c);
                    }
                    else if (c is XWPFTableCell)
                    {
                        sdts.AddRange(ExtractSDTsFromBodyElements(((XWPFTableCell)c).BodyElements));
                    }
                }
            }
            return(sdts);
        }
        public static DataTable GetDataTable(XWPFTable table)
        {
            if (table != null)
            {
                System.Data.DataTable dataTable = StringDataTableFactory.CreateTable(table.Rows[0].GetTableCells());

                var rowcounter = 0;
                foreach (XWPFTableRow row in table.Rows)
                {
                    List<XWPFTableCell> cells = row.GetTableCells();
                    if (rowcounter > 0)
                    {
                        dataTable.Rows.Add(OfficeHandler.Word.Converters.WordCellsToObjectArray.CellsToArray(cells));
                    }
                    rowcounter++;
                }
                return dataTable;
            }
            return null;
        }
Esempio n. 35
0
 public void ReadHdrFtr()
 {
     this.bodyElements = new List <IBodyElement>();
     this.paragraphs   = new List <XWPFParagraph>();
     this.tables       = new List <XWPFTable>();
     foreach (object obj in this.headerFooter.Items)
     {
         if (obj is CT_P)
         {
             XWPFParagraph xwpfParagraph = new XWPFParagraph((CT_P)obj, (IBody)this);
             this.paragraphs.Add(xwpfParagraph);
             this.bodyElements.Add((IBodyElement)xwpfParagraph);
         }
         if (obj is CT_Tbl)
         {
             XWPFTable xwpfTable = new XWPFTable((CT_Tbl)obj, (IBody)this);
             this.tables.Add(xwpfTable);
             this.bodyElements.Add((IBodyElement)xwpfTable);
         }
     }
 }
Esempio n. 36
0
        private void AppendBodyElementText(StringBuilder text, IBodyElement e, bool isLast)
        {
            if (e is XWPFParagraph)
            {
                text.Append(((XWPFParagraph)e).Text);
                if (isLast == false)
                {
                    text.Append('\t');
                }
            }
            else if (e is XWPFTable)
            {
                XWPFTable eTable = (XWPFTable)e;
                foreach (XWPFTableRow row in eTable.Rows)
                {
                    foreach (XWPFTableCell cell in row.GetTableCells())
                    {
                        IList <IBodyElement> localBodyElements = cell.BodyElements;
                        for (int i = 0; i < localBodyElements.Count; i++)
                        {
                            bool localIsLast = (i == localBodyElements.Count - 1) ? true : false;
                            AppendBodyElementText(text, localBodyElements[i], localIsLast);
                        }
                    }
                }

                if (isLast == false)
                {
                    text.Append('\n');
                }
            }
            else if (e is XWPFSDT)
            {
                text.Append(((XWPFSDT)e).Content.Text);
                if (isLast == false)
                {
                    text.Append('\t');
                }
            }
        }
Esempio n. 37
0
 /**
  * If a table cell does not include at least one block-level element, then this document shall be considered corrupt
  */
 public XWPFTableCell(CT_Tc cell, XWPFTableRow tableRow, IBody part)
 {
     this.ctTc     = cell;
     this.part     = part;
     this.tableRow = tableRow;
     // NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt.
     if (cell.GetPList().Count < 1)
     {
         cell.AddNewP();
     }
     bodyElements = new List <IBodyElement>();
     paragraphs   = new List <XWPFParagraph>();
     tables       = new List <XWPFTable>();
     foreach (object o in ctTc.Items)
     {
         if (o is CT_P)
         {
             XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
             paragraphs.Add(p);
             bodyElements.Add(p);
         }
         if (o is CT_Tbl)
         {
             XWPFTable t = new XWPFTable((CT_Tbl)o, this);
             tables.Add(t);
             bodyElements.Add(t);
         }
         if (o is CT_SdtBlock)
         {
             XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this);
             bodyElements.Add(c);
         }
         if (o is CT_SdtRun)
         {
             XWPFSDT c = new XWPFSDT((CT_SdtRun)o, this);
             bodyElements.Add(c);
         }
     }
 }
        private bool Row1Cell1Contains(XWPFTable table, string value)
        {
            try
            {
                if (table.Rows.Count > 1)
                {
                    XWPFTableCell cel = table.Rows[1].GetCell(0);
                    {
                        string celtext = CellText.GetCellText(cel);
                        System.Diagnostics.Debug.WriteLine(string.Format("Row: 1, Cell: 0 - ", celtext));
                        if (celtext.StartsWith(value))
                            return true;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }

            return false;
        }
Esempio n. 39
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.GetInsideVBorderType();
            Assert.AreEqual(NPOI.XWPF.UserModel.XWPFTable.XWPFBorderType.DOUBLE, bt);
            int sz = table.GetInsideVBorderSize();

            Assert.AreEqual(4, sz);
            int sp = table.GetInsideVBorderSpace();

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

            Assert.AreEqual("00FF00", clr);
        }
Esempio n. 40
0
 /**
  * If a table cell does not include at least one block-level element, then this document shall be considered corrupt
  */
 public XWPFTableCell(CT_Tc cell, XWPFTableRow tableRow, IBody part)
 {
     this.ctTc = cell;
     this.part = part;
     this.tableRow = tableRow;
     // NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt.
     if(cell.GetPList().Count<1)
         cell.AddNewP();
     bodyElements = new List<IBodyElement>();
     paragraphs = new List<XWPFParagraph>();
     tables = new List<XWPFTable>();
     foreach (object o in ctTc.Items)
     {
         if (o is CT_P)
         {
             XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
             paragraphs.Add(p);
             bodyElements.Add(p);
         }
         if (o is CT_Tbl)
         {
             XWPFTable t = new XWPFTable((CT_Tbl)o, this);
             tables.Add(t);
             bodyElements.Add(t);
         }
         if (o is CT_SdtBlock)
         {
             XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this);
             bodyElements.Add(c);
         }
         if (o is CT_SdtRun)
         {
             XWPFSDT c = new XWPFSDT((CT_SdtRun)o, this);
             bodyElements.Add(c);
         }
     }
 }
Esempio n. 41
0
 public void SetTable(int pos, XWPFTable table)
 {
     this.tables[pos] = table;
     this.ctDocument.body.SetTblArray(pos, table.GetCTTbl());
 }
Esempio n. 42
0
 internal override void OnDocumentRead()
 {
     try
     {
         DocumentDocument documentDocument = DocumentDocument.Parse(this.GetPackagePart().GetInputStream());
         this.ctDocument = documentDocument.Document;
         this.InitFootnotes();
         foreach (object obj in this.ctDocument.body.Items)
         {
             if (obj is CT_P)
             {
                 XWPFParagraph xwpfParagraph = new XWPFParagraph((CT_P)obj, (IBody)this);
                 this.bodyElements.Add((IBodyElement)xwpfParagraph);
                 this.paragraphs.Add(xwpfParagraph);
             }
             else if (obj is CT_Tbl)
             {
                 XWPFTable xwpfTable = new XWPFTable((CT_Tbl)obj, (IBody)this);
                 this.bodyElements.Add((IBodyElement)xwpfTable);
                 this.tables.Add(xwpfTable);
             }
         }
         if (documentDocument.Document.body.sectPr != null)
         {
             this.headerFooterPolicy = new XWPFHeaderFooterPolicy(this);
         }
         foreach (POIXMLDocumentPart relation1 in this.GetRelations())
         {
             string relationshipType = relation1.GetPackageRelationship().RelationshipType;
             if (relationshipType.Equals(XWPFRelation.STYLES.Relation))
             {
                 this.styles = (XWPFStyles)relation1;
                 this.styles.OnDocumentRead();
             }
             else if (relationshipType.Equals(XWPFRelation.NUMBERING.Relation))
             {
                 this.numbering = (XWPFNumbering)relation1;
                 this.numbering.OnDocumentRead();
             }
             else if (relationshipType.Equals(XWPFRelation.FOOTER.Relation))
             {
                 XWPFFooter xwpfFooter = (XWPFFooter)relation1;
                 this.footers.Add(xwpfFooter);
                 xwpfFooter.OnDocumentRead();
             }
             else if (relationshipType.Equals(XWPFRelation.HEADER.Relation))
             {
                 XWPFHeader xwpfHeader = (XWPFHeader)relation1;
                 this.headers.Add(xwpfHeader);
                 xwpfHeader.OnDocumentRead();
             }
             else if (relationshipType.Equals(XWPFRelation.COMMENT.Relation))
             {
                 foreach (CT_Comment comment in CommentsDocument.Parse(relation1.GetPackagePart().GetInputStream()).Comments.comment)
                 {
                     this.comments.Add(new XWPFComment(comment, this));
                 }
             }
             else if (relationshipType.Equals(XWPFRelation.SETTINGS.Relation))
             {
                 this.Settings = (XWPFSettings)relation1;
                 this.Settings.OnDocumentRead();
             }
             else if (relationshipType.Equals(XWPFRelation.IMAGES.Relation))
             {
                 XWPFPictureData picData = (XWPFPictureData)relation1;
                 picData.OnDocumentRead();
                 this.RegisterPackagePictureData(picData);
                 this.pictures.Add(picData);
             }
             else if (relationshipType.Equals(XWPFRelation.GLOSSARY_DOCUMENT.Relation))
             {
                 foreach (POIXMLDocumentPart relation2 in relation1.GetRelations())
                 {
                     try
                     {
                         relation2.OnDocumentRead();
                     }
                     catch (Exception ex)
                     {
                         throw new POIXMLException(ex);
                     }
                 }
             }
         }
         this.InitHyperlinks();
     }
     catch (XmlException ex)
     {
         throw new POIXMLException((Exception)ex);
     }
 }
Esempio n. 43
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);
 }
Esempio n. 44
0
        /**
         * Reads the document
         * @throws IOException 
         */

        internal override void OnDocumentRead()
        {
            base.OnDocumentRead();
            HdrDocument hdrDocument = null;
            Stream is1;
            try
            {
                is1 = GetPackagePart().GetInputStream();
                hdrDocument = HdrDocument.Parse(is1);
                headerFooter = hdrDocument.Hdr;
                foreach (object o in headerFooter.Items)
                {
                    if (o is CT_P)
                    {
                        XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
                        paragraphs.Add(p);
                        bodyElements.Add(p);
                    }
                    if (o is CT_Tbl)
                    {
                        XWPFTable t = new XWPFTable((CT_Tbl)o, this);
                        tables.Add(t);
                        bodyElements.Add(t);
                    }
                }
                // parse the document with cursor and add
                // the XmlObject to its lists
                /*XmlCursor cursor = headerFooter.NewCursor();
                cursor.SelectPath("./*");
                while (cursor.ToNextSelection()) {
                    XmlObject o = cursor.Object;
                    if (o is CTP) {
                        XWPFParagraph p = new XWPFParagraph((CTP)o, this);
                        paragraphs.Add(p);
                        bodyElements.Add(p);
                    }
                    if (o is CTTbl) {
                        XWPFTable t = new XWPFTable((CTTbl)o, this);
                        tables.Add(t);
                        bodyElements.Add(t);
                    }
                }
                cursor.Dispose();*/
            }
            catch (Exception e)
            {
                throw new POIXMLException(e);
            }
        }
Esempio n. 45
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);
 }
Esempio n. 46
0
 public XWPFTableRow(CT_Row row, XWPFTable table)
 {
     this.table = table;
     this.ctRow = row;
     GetTableCells();
 }
Esempio n. 47
0
 public void SetBorderBottom(XWPFTable.XWPFBorderType type, int size, int space, String rgbColor)
 {
     CT_TcPr ctTcPr = null;
     if (!GetCTTc().IsSetTcPr())
     {
         ctTcPr = GetCTTc().AddNewTcPr();
     }
     CT_TcBorders borders = ctTcPr.AddNewTcBorders();
     borders.bottom = new CT_Border();
     CT_Border b = borders.bottom;
     b.val = XWPFTable.xwpfBorderTypeMap[type];
     b.sz = (ulong)size;
     b.space = (ulong)space;
     b.color = (rgbColor);
 }
Esempio n. 48
0
 internal override void OnDocumentRead()
 {
     base.OnDocumentRead();
     FtrDocument ftrDocument = null;
     try {
         XmlDocument xmldoc = ConvertStreamToXml(GetPackagePart().GetInputStream());
         ftrDocument = FtrDocument.Parse(xmldoc, NamespaceManager);
         headerFooter = ftrDocument.Ftr;
         // parse the document with cursor and add
         // the XmlObject to its lists
         foreach (object o in headerFooter.Items)
         {
             if (o is CT_P)
             {
                 XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
                 paragraphs.Add(p);
                 bodyElements.Add(p);
             }
             if (o is CT_Tbl)
             {
                 XWPFTable t = new XWPFTable((CT_Tbl)o, this);
                 tables.Add(t);
                 bodyElements.Add(t);
             }
         }
     } catch (Exception e) {
         throw new POIXMLException(e);
     }
 }
Esempio n. 49
0
 public void ReadHdrFtr()
 {
     bodyElements = new List<IBodyElement>();
     paragraphs = new List<XWPFParagraph>();
     tables = new List<XWPFTable>();
     // parse the document with cursor and add
     // the XmlObject to its lists
     foreach (object o in headerFooter.Items)
     {
         if (o is CT_P)
         {
             XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
             paragraphs.Add(p);
             bodyElements.Add(p);
         }
         if (o is CT_Tbl)
         {
             XWPFTable t = new XWPFTable((CT_Tbl)o, this);
             tables.Add(t);
             bodyElements.Add(t);
         }
     }
     /*XmlCursor cursor = headerFooter.NewCursor();
     cursor.SelectPath("./*");
     while (cursor.ToNextSelection())
     {
         XmlObject o = cursor.Object;
         if (o is CTP)
         {
             XWPFParagraph p = new XWPFParagraph((CTP)o, this);
             paragraphs.Add(p);
             bodyElements.Add(p);
         }
         if (o is CTTbl)
         {
             XWPFTable t = new XWPFTable((CTTbl)o, this);
             tables.Add(t);
             bodyElements.Add(t);
         }
     }
     cursor.Dispose();*/
 }
Esempio n. 50
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);
 }
Esempio n. 51
0
 public int GetPosOfTable(XWPFTable t)
 {
     return(this.GetPosOfBodyElement((IBodyElement)t));
 }
Esempio n. 52
0
 private List<XWPFSDT> extractSDTsFromTable(XWPFTable table)
 {
     List<XWPFSDT> sdts = new List<XWPFSDT>();
     foreach (XWPFTableRow r in table.Rows)
     {
         foreach (XWPFTableCell c in r.GetTableCells())
         {
             sdts.AddRange(ExtractSDTsFromBodyElements(c.BodyElements));
         }
     }
     return sdts;
 }
Esempio n. 53
0
 public XWPFTableRow(CT_Row row, XWPFTable table)
 {
     this.table = table;
     this.ctRow = row;
     GetTableCells();
 }
Esempio n. 54
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);
 }
Esempio n. 55
0
 /**
  * inserts an existing XWPFTable to the arrays bodyElements and tables
  * @see NPOI.XWPF.UserModel.IBody#insertTable(int, NPOI.XWPF.UserModel.XWPFTable)
  */
 public void InsertTable(int pos, XWPFTable table)
 {
     bodyElements.Insert(pos, table);
     int i;
     for (i = 0; i < ctTc.GetTblList().Count; i++) {
         CT_Tbl tbl = ctTc.GetTblArray(i);
         if(tbl == table.GetCTTbl()){
             break;
         }
     }
     tables.Insert(i, table);
 }
Esempio n. 56
0
 public string GetTblStyle(XWPFTable table)
 {
     return(table.GetStyleID());
 }