Package org.apache.poi.xssf.usermodel

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


     */
    public SXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize){
      setRandomAccessWindowSize(rowAccessWindowSize);
      if (workbook == null)
      {
        _wb=new XSSFWorkbook();
      }
      else
      {
        _wb=workbook;
            for ( int i = 0; i < _wb.getNumberOfSheets(); i++ )
View Full Code Here


        }
    }

    @Test
    public void existingWorkbook() {
      XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
      xssfWorkbook.createSheet("S1");
      SXSSFWorkbook wb = new SXSSFWorkbook(xssfWorkbook);
      xssfWorkbook = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb);
      assertTrue(wb.dispose());

        wb = new SXSSFWorkbook(xssfWorkbook);
View Full Code Here

        row.createCell(0).setCellValue("A");
        row.createCell(1).setCellValue("B");
        row.createCell(2).setCellValue("A");

        XSSFWorkbook xssfWorkbook = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb);
        sss = (SharedStringsTable)f.get(wb);
        assertEquals(2, sss.getUniqueCount());
        wb.dispose();

        Sheet sheet1 = xssfWorkbook.getSheetAt(0);
        assertEquals("S1", sheet1.getSheetName());
        assertEquals(1, sheet1.getPhysicalNumberOfRows());
        row = sheet1.getRow(0);
        assertNotNull(row);
        Cell cell = row.getCell(0);
View Full Code Here

        assertEquals("A", cell.getStringCellValue());
    }

    @Test
    public void addToExistingWorkbook() {
      XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
      xssfWorkbook.createSheet("S1");
      Sheet sheet = xssfWorkbook.createSheet("S2");
      Row row = sheet.createRow(1);
      Cell cell = row.createCell(1);
      cell.setCellValue("value 2_1_1");
      SXSSFWorkbook wb = new SXSSFWorkbook(xssfWorkbook);
      xssfWorkbook = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb);
        assertTrue(wb.dispose());

        wb = new SXSSFWorkbook(xssfWorkbook);

      // Add a row to the existing empty sheet
      Sheet sheet1 = wb.getSheetAt(0);
      Row row1_1 = sheet1.createRow(1);
      Cell cell1_1_1 = row1_1.createCell(1);
      cell1_1_1.setCellValue("value 1_1_1");

      // Add a row to the existing non-empty sheet
      Sheet sheet2 = wb.getSheetAt(1);
      Row row2_2 = sheet2.createRow(2);
      Cell cell2_2_1 = row2_2.createCell(1);
      cell2_2_1.setCellValue("value 2_2_1");

      // Add a sheet with one row
      Sheet sheet3 = wb.createSheet("S3");
      Row row3_1 = sheet3.createRow(1);
      Cell cell3_1_1 = row3_1.createCell(1);
      cell3_1_1.setCellValue("value 3_1_1");

      xssfWorkbook = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb);
      assertEquals(3, xssfWorkbook.getNumberOfSheets());
      // Verify sheet 1
      sheet1 = xssfWorkbook.getSheetAt(0);
      assertEquals("S1", sheet1.getSheetName());
      assertEquals(1, sheet1.getPhysicalNumberOfRows());
      row1_1 = sheet1.getRow(1);
      assertNotNull(row1_1);
      cell1_1_1 = row1_1.getCell(1);
      assertNotNull(cell1_1_1);
      assertEquals("value 1_1_1", cell1_1_1.getStringCellValue());
      // Verify sheet 2
      sheet2 = xssfWorkbook.getSheetAt(1);
      assertEquals("S2", sheet2.getSheetName());
      assertEquals(2, sheet2.getPhysicalNumberOfRows());
      Row row2_1 = sheet2.getRow(1);
      assertNotNull(row2_1);
      Cell cell2_1_1 = row2_1.getCell(1);
      assertNotNull(cell2_1_1);
      assertEquals("value 2_1_1", cell2_1_1.getStringCellValue());
      row2_2 = sheet2.getRow(2);
      assertNotNull(row2_2);
      cell2_2_1 = row2_2.getCell(1);
      assertNotNull(cell2_2_1);
      assertEquals("value 2_2_1", cell2_2_1.getStringCellValue());
      // Verify sheet 3
      sheet3 = xssfWorkbook.getSheetAt(2);
      assertEquals("S3", sheet3.getSheetName());
      assertEquals(1, sheet3.getPhysicalNumberOfRows());
      row3_1 = sheet3.getRow(1);
      assertNotNull(row3_1);
      cell3_1_1 = row3_1.getCell(1);
View Full Code Here

        assertTrue(wb.dispose());

        //Test escaping of Unicode control characters
        wb = new SXSSFWorkbook();
        wb.createSheet("S1").createRow(0).createCell(0).setCellValue("value\u0019");
        XSSFWorkbook xssfWorkbook = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb);
        Cell cell = xssfWorkbook.getSheet("S1").getRow(0).getCell(0);
        assertEquals("value?", cell.getStringCellValue());

        assertTrue(wb.dispose());

    }
View Full Code Here

                Cell cell3 = row.createCell(2);
                cell3.setCellValue(j);
            }
        }

        XSSFWorkbook xwb = (XSSFWorkbook)SXSSFITestDataProvider.instance.writeOutAndReadBack(wb);
        for(int i = 0; i < sheetNum; i++){
            Sheet sh = xwb.getSheetAt(i);
            assertEquals("sheet" + i, sh.getSheetName());
            for(int j = 0; j < rowNum; j++){
                Row row = sh.getRow(j);
                assertNotNull("row[" + j + "]", row);
                Cell cell1 = row.getCell(0);
View Full Code Here

    @Ignore
  public void bug53515() throws Exception {
    Workbook wb = new SXSSFWorkbook(10);
    populateWorkbook(wb);
    saveTwice(wb);
    wb = new XSSFWorkbook();
    populateWorkbook(wb);
    saveTwice(wb);
  }
View Full Code Here

        sheet.createRow(1);
    }

    @Test
    public void overrideRowsInTemplate() {
        XSSFWorkbook template = new XSSFWorkbook();
        template.createSheet().createRow(1);

        Workbook wb = new SXSSFWorkbook(template);
        Sheet sheet = wb.getSheetAt(0);

        try {
View Full Code Here

public class TestXSSFImportFromXML extends TestCase {
 
 
  public void  testImportFromXML() throws Exception{
   
     XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMappings.xlsx");
    
     String name = "name";
     String teacher = "teacher";
     String tutor = "tutor";
     String cdl = "cdl";
     String duration = "duration";
     String topic = "topic";
     String project = "project";
     String credits = "credits";
    
     String testXML = "<CORSO>"+
              "<NOME>"+name+"</NOME>"+
              "<DOCENTE>"+teacher+"</DOCENTE>"+
              "<TUTOR>"+tutor+"</TUTOR>"+
              "<CDL>"+cdl+"</CDL>"+
               "<DURATA>"+duration+"</DURATA>"+
               "<ARGOMENTO>"+topic+"</ARGOMENTO>"+
               "<PROGETTO>"+project+"</PROGETTO>"+
               "<CREDITI>"+credits+"</CREDITI>"+
               "</CORSO>\u0000";   
    
     XSSFMap map = wb.getMapInfo().getXSSFMapByName("CORSO_mapping");
     assertNotNull(map);
     XSSFImportFromXML importer = new XSSFImportFromXML(map);
    
     importer.importFromXML(testXML);
    
     XSSFSheet sheet=wb.getSheetAt(0);
    
     XSSFRow row = sheet.getRow(0);
     assertTrue(row.getCell(0).getStringCellValue().equals(name));
     assertTrue(row.getCell(1).getStringCellValue().equals(teacher));
     assertTrue(row.getCell(2).getStringCellValue().equals(tutor));
View Full Code Here

 
 
  public void testMultiTable() throws Exception{
   
   
    XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMappings-complex-type.xlsx");  
   
    String cellC6 = "c6";
    String cellC7 = "c7";
    String cellC8 = "c8";
    String cellC9 = "c9";
   
    String testXML = "<ns1:MapInfo xmlns:ns1=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" SelectionNamespaces=\"\">" +
             "<ns1:Schema ID=\""+cellC6+"\" SchemaRef=\"a\" />"+
             "<ns1:Schema ID=\""+cellC7+"\" SchemaRef=\"b\" />"+
             "<ns1:Schema ID=\""+cellC8+"\" SchemaRef=\"c\" />"+
             "<ns1:Schema ID=\""+cellC9+"\" SchemaRef=\"d\" />"+
             "<ns1:Map ID=\"1\" Name=\"\" RootElement=\"\" SchemaID=\"\" ShowImportExportValidationErrors=\"\" AutoFit=\"\" Append=\"\" PreserveSortAFLayout=\"\" PreserveFormat=\"\">"+
             "<ns1:DataBinding DataBindingLoadMode=\"\" />"+
             "</ns1:Map>"+
             "<ns1:Map ID=\"2\" Name=\"\" RootElement=\"\" SchemaID=\"\" ShowImportExportValidationErrors=\"\" AutoFit=\"\" Append=\"\" PreserveSortAFLayout=\"\" PreserveFormat=\"\">"+
             "<ns1:DataBinding DataBindingLoadMode=\"\" />"+
             "</ns1:Map>"+
             "<ns1:Map ID=\"3\" Name=\"\" RootElement=\"\" SchemaID=\"\" ShowImportExportValidationErrors=\"\" AutoFit=\"\" Append=\"\" PreserveSortAFLayout=\"\" PreserveFormat=\"\">"+
             "<ns1:DataBinding DataBindingLoadMode=\"\" />"+
             "</ns1:Map>"+
             "</ns1:MapInfo>\u0000";

    XSSFMap map = wb.getMapInfo().getXSSFMapByName("MapInfo_mapping");
    assertNotNull(map);
    XSSFImportFromXML importer = new XSSFImportFromXML(map);
    
    importer.importFromXML(testXML);
    
    //Check for Schema element
    XSSFSheet sheet=wb.getSheetAt(1);
    
    assertEquals(cellC6,sheet.getRow(5).getCell(2).getStringCellValue());
    assertEquals(cellC7,sheet.getRow(6).getCell(2).getStringCellValue());
    assertEquals(cellC8,sheet.getRow(7).getCell(2).getStringCellValue());
    assertEquals(cellC9,sheet.getRow(8).getCell(2).getStringCellValue());
View Full Code Here

TOP

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

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.