Exemplo n.º 1
0
        public void Test56170()
        {
            IWorkbook wb    = XSSFTestDataSamples.OpenSampleWorkbook("56170.xlsx");
            XSSFSheet sheet = (XSSFSheet)wb.GetSheetAt(0);

            IWorkbook wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);
            ICell     cell;

            // add some contents to table so that the table will need expansion
            IRow row = sheet.GetRow(0);

            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);
            cell   = row.CreateCell(0);
            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);
            cell.SetCellValue("demo1");
            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);
            cell   = row.CreateCell(1);
            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);
            cell.SetCellValue("demo2");
            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);
            cell   = row.CreateCell(2);
            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);
            cell.SetCellValue("demo3");

            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);

            row  = sheet.GetRow(1);
            cell = row.CreateCell(0);
            cell.SetCellValue("demo1");
            cell = row.CreateCell(1);
            cell.SetCellValue("demo2");
            cell = row.CreateCell(2);
            cell.SetCellValue("demo3");

            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);

            // expand table
            XSSFTable     table    = sheet.GetTables()[0];
            CellReference startRef = table.GetStartCellReference();
            CellReference endRef   = table.GetEndCellReference();

            table.GetCTTable().@ref = (new CellRangeAddress(startRef.Row, 1, startRef.Col, endRef.Col).FormatAsString());

            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);
            Assert.IsNotNull(wbRead);

            /*FileOutputStream stream = new FileOutputStream("c:\\temp\\output.xlsx");
             * workbook.Write(stream);
             * stream.Close();*/
        }
Exemplo n.º 2
0
        /**
         * @return the list of all Tables that provide a map rule to this mapping
         */
        public List <XSSFTable> GetRelatedTables()
        {
            List <XSSFTable> tables = new List <XSSFTable>();
            int sheetNumber         = mapInfo.Workbook.NumberOfSheets;

            for (int i = 0; i < sheetNumber; i++)
            {
                XSSFSheet sheet = (XSSFSheet)mapInfo.Workbook.GetSheetAt(i);
                foreach (POIXMLDocumentPart p in sheet.GetRelations())
                {
                    if (p.GetPackageRelationship().RelationshipType.Equals(XSSFRelation.TABLE.Relation))
                    {
                        XSSFTable table = (XSSFTable)p;
                        if (table.MapsTo(ctMap.ID))
                        {
                            tables.Add(table);
                        }
                    }
                }
            }

            return(tables);
        }