Package org.apache.poi.xssf.usermodel

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


    @Ignore
    @Test
    public void testImportInstructors()
    {
        System.out.println("importInstructors");
        XSSFSheet instructorSheet = null;
        List<Section> sections = null;
        Course course = null;
        ImportExcel2007 instance = new ImportExcel2007();
        List expResult = null;
        List result = instance.importInstructors(instructorSheet, sections, course);
View Full Code Here


    @Ignore
    @Test
    public void testImportStudents()
    {
        System.out.println("importStudents");
        XSSFSheet studentSheet = null;
        List<Section> sections = null;
        Course course = null;
        ImportExcel2007 instance = new ImportExcel2007();
        List expResult = null;
        List result = instance.importStudents(studentSheet, sections, course);
View Full Code Here

        try
        {
            pkg = OPCPackage.open(filename, PackageAccess.READ);
            XSSFWorkbook workbook = new XSSFWorkbook(pkg);
            LOGGER.debug("File opened.  Opening Student and Instructor worksheets");
            XSSFSheet courseSheet = workbook.getSheet("course");
            XSSFSheet sectionSheet = workbook.getSheet("sections");
            XSSFSheet studentSheet = workbook.getSheet("students");
            XSSFSheet instructorSheet = workbook.getSheet("instructors");
            if (courseSheet == null || studentSheet == null
                    || instructorSheet == null || sectionSheet == null)
            {
                LOGGER.error("Spreadsheet missing Course, Section, Instructor "
                        + "and/or Student worksheets");
View Full Code Here

        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

        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

    assertEquals(2, cc7.getColumn());
  }

  public void testWriteRead() {
    XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx");
    XSSFSheet sheet1 = workbook.getSheetAt(0);
    XSSFSheet sheet2 = workbook.getSheetAt(1);

    assertTrue( sheet1.hasComments() );
    assertFalse( 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 = 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

        sheet1.getRow(4).getCell(2).getCellComment().getString().getString());
  }

  public void testReadWriteMultipleAuthors() {
    XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx");
    XSSFSheet sheet1 = workbook.getSheetAt(0);
    XSSFSheet sheet2 = workbook.getSheetAt(1);

    assertTrue( sheet1.hasComments() );
    assertFalse( sheet2.hasComments() );

    assertEquals("Nick Burch",
        sheet1.getRow(4).getCell(2).getCellComment().getAuthor());
    assertEquals("Nick Burch",
        sheet1.getRow(6).getCell(2).getCellComment().getAuthor());
View Full Code Here

                    assertNotNull(xmlSchema);
                }
            }
        }

        XSSFSheet sheet1 = wb.getSheetAt(0);

        for (POIXMLDocumentPart p : sheet1.getRelations()) {

            if (p instanceof SingleXmlCells) {
                singleXMLCells = (SingleXmlCells) p;
            }
View Full Code Here

   */
  public String getText() {
    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 && 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 ").append(comment.getAuthor()).append(": ").append(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

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

TOP

Related Classes of org.apache.poi.xssf.usermodel.XSSFSheet

Copyright © 2018 www.massapicom. 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.