Examples of XSSFSheet


Examples of org.apache.poi.xssf.usermodel.XSSFSheet

            formatter = new DataFormatter(locale);
        }

        StringBuffer text = new StringBuffer();
        for(int i=0; i<workbook.getNumberOfSheets(); i++) {
            XSSFSheet sheet = workbook.getSheetAt(i);
            if(includeSheetNames) {
                text.append(workbook.getSheetName(i)).append("\n");
            }

            // Header(s), if present
            if(includeHeadersFooters) {
                text.append(
                        extractHeaderFooter(sheet.getFirstHeader())
                        );
                text.append(
                        extractHeaderFooter(sheet.getOddHeader())
                        );
                text.append(
                        extractHeaderFooter(sheet.getEvenHeader())
                        );
            }

            // Rows and cells
            for (Object rawR : sheet) {
                Row row = (Row)rawR;
                for(Iterator<Cell> ri = row.cellIterator(); ri.hasNext();) {
                    Cell cell = ri.next();

                    // Is it a formula one?
                    if(cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
                        if (formulasNotResults) {
                            text.append(cell.getCellFormula());
                        } else {
                            if (cell.getCachedFormulaResultType() == Cell.CELL_TYPE_STRING) {
                                handleStringCell(text, cell);
                            } else {
                                handleNonStringCell(text, cell, formatter);
                            }
                        }
                    } else if(cell.getCellType() == Cell.CELL_TYPE_STRING) {
                        handleStringCell(text, cell);
                    } else {
                        handleNonStringCell(text, cell, formatter);
                    }

                    // Output the comment, if requested and exists
                    Comment comment = cell.getCellComment();
                    if(includeCellComments && comment != null) {
                        // Replace any newlines with spaces, otherwise it
                        //  breaks the output
                        String commentText = comment.getString().getString().replace('\n', ' ');
                        text.append(" Comment by ").append(comment.getAuthor()).append(": ").append(commentText);
                    }

                    if(ri.hasNext())
                        text.append("\t");
                }
                text.append("\n");
            }
           
            // add textboxes
            if (includeTextBoxes){
                XSSFDrawing drawing = sheet.createDrawingPatriarch();
                for (XSSFShape shape : drawing.getShapes()){
                    if (shape instanceof XSSFSimpleShape){
                        String boxText = ((XSSFSimpleShape)shape).getText();
                        if (boxText.length() > 0){
                            text.append(boxText);
                            text.append('\n');
                        }
                    }
                }
            }
            // Finally footer(s), if present
            if(includeHeadersFooters) {
                text.append(
                        extractHeaderFooter(sheet.getFirstFooter())
                        );
                text.append(
                        extractHeaderFooter(sheet.getOddFooter())
                        );
                text.append(
                        extractHeaderFooter(sheet.getEvenFooter())
                        );
            }
        }

        return text.toString();
View Full Code Here

Examples of org.apache.poi.xssf.usermodel.XSSFSheet

                // Exports elements and attributes mapped with tables
                if (table!=null) {

                    List<XSSFXmlColumnPr> tableColumns = table.getXmlColumnPrs();

                    XSSFSheet sheet = table.getXSSFSheet();

                    int startRow = table.getStartCellReference().getRow();
                    // In mappings created with Microsoft Excel the first row contains the table header and must be skipped
                    startRow +=1;

                    int endRow = table.getEndCellReference().getRow();

                    for(int i = startRow; i<= endRow; i++) {
                        XSSFRow row = sheet.getRow(i);

                        Node tableRootNode = getNodeByXPath(table.getCommonXpath(),doc.getFirstChild(),doc,true);

                        short startColumnIndex = table.getStartCellReference().getCol();
                        for(int j = startColumnIndex; j<= table.getEndCellReference().getCol();j++) {
View Full Code Here

Examples of org.apache.poi.xssf.usermodel.XSSFSheet

            XmlException, IOException {
        XSSFWorkbook document = (XSSFWorkbook) extractor.getDocument();

        for (int i = 0; i < document.getNumberOfSheets(); i++) {
            xhtml.startElement("div");
            XSSFSheet sheet = (XSSFSheet) document.getSheetAt(i);
            xhtml.element("h1", document.getSheetName(i));

            // Header(s), if present
            extractHeaderFooter(sheet.getFirstHeader(), xhtml);
            extractHeaderFooter(sheet.getOddHeader(), xhtml);
            extractHeaderFooter(sheet.getEvenHeader(), xhtml);

            xhtml.startElement("table");
            xhtml.startElement("tbody");

            // Rows and cells
            for (Object rawR : sheet) {
                xhtml.startElement("tr");
                Row row = (Row) rawR;
                for (Iterator<Cell> ri = row.cellIterator(); ri.hasNext();) {
                    xhtml.startElement("td");
                    Cell cell = ri.next();

                    int type = cell.getCellType();
                    if (type == Cell.CELL_TYPE_FORMULA) {
                        type = cell.getCachedFormulaResultType();
                    }
                    if (type == Cell.CELL_TYPE_STRING) {
                        xhtml.characters(cell.getRichStringCellValue()
                                .getString());
                    } else if (type == Cell.CELL_TYPE_NUMERIC) {
                        CellStyle style = cell.getCellStyle();
                        xhtml.characters(
                            formatter.formatRawCellContents(cell.getNumericCellValue(),
                                                            style.getDataFormat(),
                                                            style.getDataFormatString()));
                    } else {
                        XSSFCell xc = (XSSFCell) cell;
                        String rawValue = xc.getRawValue();
                        if (rawValue != null) {
                            xhtml.characters(rawValue);
                        }

                    }

                    // Output the comment in the same cell as the content
                    Comment comment = cell.getCellComment();
                    if (comment != null) {
                        xhtml.characters(comment.getString().getString());
                    }

                    xhtml.endElement("td");
                }
                xhtml.endElement("tr");
            }

            xhtml.endElement("tbody");
            xhtml.endElement("table");

            // Finally footer(s), if present
            extractHeaderFooter(sheet.getFirstFooter(), xhtml);
            extractHeaderFooter(sheet.getOddFooter(), xhtml);
            extractHeaderFooter(sheet.getEvenFooter(), xhtml);

            xhtml.endElement("div");
        }
    }
View Full Code Here

Examples of org.apache.poi.xssf.usermodel.XSSFSheet

                metadata.set(TikaMetadataKeys.PROTECTED, "false");

                XSSFWorkbook document = (XSSFWorkbook) extractor.getDocument();

                for (int i = 0; i < document.getNumberOfSheets(); i++) {
                    XSSFSheet sheet = document.getSheetAt(i);

                    if (sheet.getProtect()) {
                        metadata.set(TikaMetadataKeys.PROTECTED, "true");
                    }
                }
            }
        };
View Full Code Here

Examples of org.apache.poi.xssf.usermodel.XSSFSheet

   */
  public String getText() {
    StringBuffer text = new StringBuffer();
   
    for(int i=0; i<workbook.getNumberOfSheets(); i++) {
      XSSFSheet sheet = (XSSFSheet)workbook.getSheetAt(i);
      if(includeSheetNames) {
        text.append(workbook.getSheetName(i) + "\n");
      }
     
      // Header(s), if present
      text.append(
          extractHeaderFooter(sheet.getFirstHeader())
      );
      text.append(
          extractHeaderFooter(sheet.getOddHeader())
      );
      text.append(
          extractHeaderFooter(sheet.getEvenHeader())
      );

      // Rows and cells
      for (Object rawR : sheet) {
        Row row = (Row)rawR;
        for(Iterator<Cell> ri = row.cellIterator(); ri.hasNext();) {
          Cell cell = ri.next();
         
          // Is it a formula one?
          if(cell.getCellType() == Cell.CELL_TYPE_FORMULA && formulasNotResults) {
            text.append(cell.getCellFormula());
          } else if(cell.getCellType() == Cell.CELL_TYPE_STRING) {
            text.append(cell.getRichStringCellValue().getString());
          } else {
            XSSFCell xc = (XSSFCell)cell;
            text.append(xc.getRawValue());
          }
         
          // Output the comment, if requested and exists
            Comment comment = cell.getCellComment();
          if(includeCellComments && comment != null) {
              // Replace any newlines with spaces, otherwise it
              //  breaks the output
              String commentText = comment.getString().getString().replace('\n', ' ');
              text.append(" Comment by "+comment.getAuthor()+": "+commentText);
          }
         
          if(ri.hasNext())
            text.append("\t");
        }
        text.append("\n");
      }
     
      // Finally footer(s), if present
      text.append(
          extractHeaderFooter(sheet.getFirstFooter())
      );
      text.append(
          extractHeaderFooter(sheet.getOddFooter())
      );
      text.append(
          extractHeaderFooter(sheet.getEvenFooter())
      );
    }
   
    return text.toString();
  }
View Full Code Here

Examples of org.apache.poi.xssf.usermodel.XSSFSheet

    );
    assertTrue(xml.exists());
     
    XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
    Sheet sheet1 = workbook.getSheetAt(0);
    XSSFSheet sheet2 = (XSSFSheet)workbook.getSheetAt(1);
   
    assertTrue( ((XSSFSheet)sheet1).hasComments() );
    assertFalse( ((XSSFSheet)sheet2).hasComments() );
   
    // Change on comment on sheet 1, and add another into
    //  sheet 2
    Row r5 = sheet1.getRow(4);
    Comment cc5 = r5.getCell(2).getCellComment();
    cc5.setAuthor("Apache POI");
    cc5.setString(new XSSFRichTextString("Hello!"));
   
    Row r2s2 = sheet2.createRow(2);
    Cell c1r2s2 = r2s2.createCell(1);
    assertNull(c1r2s2.getCellComment());
   
    Comment cc2 = sheet2.createComment();
    cc2.setAuthor("Also POI");
    cc2.setString(new XSSFRichTextString("A new comment"));
    c1r2s2.setCellComment(cc2);
   
   
    // Save, and re-load the file
        workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);

    // Check we still have comments where we should do
    sheet1 = workbook.getSheetAt(0);
    sheet2 = (XSSFSheet)workbook.getSheetAt(1);
    assertNotNull(sheet1.getRow(4).getCell(2).getCellComment());
    assertNotNull(sheet1.getRow(6).getCell(2).getCellComment());
    assertNotNull(sheet2.getRow(2).getCell(1).getCellComment());
   
    // And check they still have the contents they should do
    assertEquals("Apache POI",
        sheet1.getRow(4).getCell(2).getCellComment().getAuthor());
    assertEquals("Nick Burch",
        sheet1.getRow(6).getCell(2).getCellComment().getAuthor());
    assertEquals("Also POI",
        sheet2.getRow(2).getCell(1).getCellComment().getAuthor());
   
    assertEquals("Nick Burch:\nThis is a comment",
        sheet1.getRow(4).getCell(2).getCellComment().getString().getString());
  }
View Full Code Here

Examples of org.apache.poi.xssf.usermodel.XSSFSheet

    );
    assertTrue(xml.exists());
     
    XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
    Sheet sheet1 = workbook.getSheetAt(0);
    XSSFSheet sheet2 = (XSSFSheet)workbook.getSheetAt(1);
   
    assertTrue( ((XSSFSheet)sheet1).hasComments() );
    assertFalse( ((XSSFSheet)sheet2).hasComments() );
   
    assertEquals("Nick Burch",
View Full Code Here

Examples of org.apache.poi.xssf.usermodel.XSSFSheet

        assertTrue(newCol.getHidden());
    }

    public void testGetOrCreateColumn() {
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet("Sheet 1");
        ColumnHelper columnHelper = sheet.getColumnHelper();
       
        // Check POI 0 based, OOXML 1 based
        CTCol col = columnHelper.getOrCreateColumn1Based(3, false);
        assertNotNull(col);
        assertNull(columnHelper.getColumn(1, false));
View Full Code Here

Examples of org.apache.poi.xssf.usermodel.XSSFSheet

        assertNull(columnHelper.getColumn(30, false));
    }
   
    public void testGetSetColDefaultStyle() {
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet();
        CTWorksheet ctWorksheet = sheet.getCTWorksheet();
        ColumnHelper columnHelper = sheet.getColumnHelper();
       
        // POI column 3, OOXML column 4
        CTCol col = columnHelper.getOrCreateColumn1Based(4, false);
       
        assertNotNull(col);
View Full Code Here

Examples of org.apache.poi.xssf.usermodel.XSSFSheet

    @Ignore
    @Test
    public void testImportSections()
    {
        System.out.println("importSections");
        XSSFSheet sectionSheet = null;
        Course course = null;
        ImportExcel2007 instance = new ImportExcel2007();
        List expResult = null;
        List result = instance.importSections(sectionSheet, course);
        assertEquals(expResult, result);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.