Examples of XSSFSheet


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

    }
  }

  private void extractContent(StringBuilder buffy, XSSFWorkbook document) {
    for (int i = 0; i < document.getNumberOfSheets(); i++) {
      XSSFSheet sheet = document.getSheetAt(i);
      buffy.append(document.getSheetName(i)).append(' ');

      // Header(s), if present
      extractHeaderFooter(buffy, sheet.getFirstHeader());
      extractHeaderFooter(buffy, sheet.getOddHeader());
      extractHeaderFooter(buffy, 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();

          if (cell.getCellType() == Cell.CELL_TYPE_FORMULA || cell.getCellType() == Cell.CELL_TYPE_STRING) {
            buffy.append(cell.getRichStringCellValue().getString()).append(' ');
          } else {
            XSSFCell xc = (XSSFCell) cell;
            String rawValue = xc.getRawValue();
            if (rawValue != null) {
              buffy.append(rawValue).append(' ');
            }

          }

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

      // Finally footer(s), if present
      extractHeaderFooter(buffy, sheet.getFirstFooter());
      extractHeaderFooter(buffy, sheet.getOddFooter());
      extractHeaderFooter(buffy, sheet.getEvenFooter());
    }
  }
View Full Code Here

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

    HashMap<SXSSFSheet,XSSFSheet> _sxFromXHash=new HashMap<SXSSFSheet,XSSFSheet>();
    HashMap<XSSFSheet,SXSSFSheet> _xFromSxHash=new HashMap<XSSFSheet,SXSSFSheet>();

    XSSFSheet getXSSFSheet(SXSSFSheet sheet)
    {
        XSSFSheet result=_sxFromXHash.get(sheet);
        assert result!=null;
        return result;
    }
View Full Code Here

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

        while (en.hasMoreElements())
        {
            ZipEntry ze = en.nextElement();
            zos.putNextEntry(new ZipEntry(ze.getName()));
            InputStream is = zip.getInputStream(ze);
            XSSFSheet xSheet=getSheetFromZipEntryName(ze.getName());
            if(xSheet!=null)
            {
                SXSSFSheet sxSheet=getSXSSFSheet(xSheet);
                copyStreamAndInjectWorksheet(is,zos,sxSheet.getWorksheetXMLInputStream());
            }
View Full Code Here

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

     *
     * @param index of the sheet to remove (0-based)
     */
    public void removeSheetAt(int index)
    {
        XSSFSheet xSheet=_wb.getSheetAt(index);
        _wb.removeSheetAt(index);
        deregisterSheetMapping(xSheet);
    }
View Full Code Here

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

  @Override
  public void processExport(OutputStream output) {

    try {
      XSSFWorkbook workbook = new XSSFWorkbook();
      XSSFSheet sheet = workbook.createSheet(exportConf.getFileName());
      Row row = null;
      Cell cell = null;
      int rowIndex = 0;
      int columnIndex;

      // Header
      if (exportConf.getIncludeHeader()) {

        for (HtmlRow htmlRow : table.getHeadRows()) {

          row = sheet.createRow(rowIndex++);
          columnIndex = 0;

          for (HtmlColumn column : htmlRow.getColumns(ReservedFormat.ALL, ReservedFormat.XLSX)) {
            cell = row.createCell(columnIndex++);
            cell.setCellValue(column.getContent().toString());
          }
        }
      }

      // Body
      for (HtmlRow htmlRow : table.getBodyRows()) {

        row = sheet.createRow(rowIndex++);
        columnIndex = 0;

        for (HtmlColumn column : htmlRow.getColumns(ReservedFormat.ALL, ReservedFormat.XLSX)) {
          cell = row.createCell(columnIndex++);
          cell.setCellValue(column.getContent().toString());
        }
      }

      // Column auto-sizing
      for (columnIndex = 0; columnIndex < table.getLastHeaderRow().getColumns(ReservedFormat.ALL, ReservedFormat.XLSX).size(); columnIndex++) {
        if (exportConf.getAutoSize()) {
          sheet.autoSizeColumn(columnIndex);
        }
      }

      workbook.write(output);
    } catch (IOException e) {
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

   */
  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
      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 && 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
      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

    );
    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

            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
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.