Package org.apache.poi.ss.usermodel

Examples of org.apache.poi.ss.usermodel.Workbook


        this.config = config;
    }

    public void addUserList(UserStoreManager userStore) throws UserAdminException {
        try {
            Workbook wb = this.createWorkbook();
            Sheet sheet = wb.getSheet(wb.getSheetName(0));
            String password = config.getDefaultPassword();
          
            if (sheet == null || sheet.getLastRowNum() == -1) {
                throw new UserAdminException("The first sheet is empty");
            }
View Full Code Here


    }

    public Workbook createWorkbook() throws Throwable {
        String filename = config.getFileName();
        InputStream ins = config.getInStream();
        Workbook wb = null;
        try {
            if (filename.endsWith(".xlsx")) {
                wb = new XSSFWorkbook(ins);
            } else {
                POIFSFileSystem fs = new POIFSFileSystem(ins);
View Full Code Here

 
  private String[] getHeader() throws Exception {
      if (!this.isHasHeader()) {
        return null;
      }
      Workbook wb = this.getConfig().createWorkbook();
    Sheet sheet = wb.getSheet(this.getWorkbookName());
      String[] header = this.extractRowData(sheet.getRow(0));
      return header;
    }
View Full Code Here

  public PrefetchDataInfo runQuery(XMLStreamWriter xmlWriter, InternalParamCollection params,
      int queryLevel, boolean prefetchData, PrefetchDataInfo prefetchedData)
      throws DataServiceFault {
    PrefetchDataInfo retPFData = null;
    Workbook wb = null;
    if (prefetchedData != null) {
      wb = (Workbook) prefetchedData.getObject(DBConstants.PrefetchProperties.EXCEL_WORKBOOK);
    }
    try {
      if (wb == null) {
          wb = this.getConfig().createWorkbook();
          if (prefetchData) {
            retPFData = new PrefetchDataInfo();
            retPFData.addObject(DBConstants.PrefetchProperties.EXCEL_WORKBOOK, wb);
            return retPFData;
          }
      }
      Sheet sheet = wb.getSheet(this.getWorkbookName());     
      int maxCount = this.getMaxRowCount();
        int i = this.getStartingRow() - 1;
        int count = 0;
        DataEntry dataEntry;
        String[] record;
View Full Code Here

    return excelDataSourcePath;
  }
 
  public Workbook createWorkbook() throws IOException, InvalidFormatException, DataServiceFault {
    InputStream ins = DBUtils.getInputStreamFromPath(this.getExcelDataSourcePath());
    Workbook wb = WorkbookFactory.create(ins);
    return wb;
  }
View Full Code Here

  }
 
  @Override
  public boolean isActive() {
    try {
      Workbook wb = this.createWorkbook();
      return wb != null;
    } catch (Exception e) {
      log.error("Error in checking Excel config availability", e);
      return false;
    }
View Full Code Here

    }
    log( versionBffr.toString(), Project.MSG_INFO ) ;
   
    log( "Using input file: " + excelFileName, Project.MSG_INFO ) ;
   
    Workbook targetWorkbook = loadWorkbook() ;
    if( targetWorkbook == null ) {
      log( "Unable to load " + excelFileName +
                      ".  Verify the file exists and can be read.",
                      Project.MSG_ERR ) ;
      return ;
View Full Code Here

             new HSSFWorkbook(),
             new XSSFWorkbook()
       };
       int[] initialFonts = new int[] { 4, 1 };
       for(int i=0; i<wbs.length; i++) {
          Workbook wb = wbs[i];
          int startingFonts = initialFonts[i];
         
          assertEquals(startingFonts, wb.getNumberOfFonts());
         
          // Get a font, and slightly change it
          Font a = wb.createFont();
          assertEquals(startingFonts+1, wb.getNumberOfFonts());
          a.setFontHeightInPoints((short)23);
          assertEquals(startingFonts+1, wb.getNumberOfFonts());
         
          // Get two more, unchanged
          /*Font b =*/ wb.createFont();
          assertEquals(startingFonts+2, wb.getNumberOfFonts());
          /*Font c =*/ wb.createFont();
          assertEquals(startingFonts+3, wb.getNumberOfFonts());
       }
    }
View Full Code Here

    }

    @Test
    public void bug49783() throws Exception {
        Workbook wb =  XSSFTestDataSamples.openSampleWorkbook("49783.xlsx");
        Sheet sheet = wb.getSheetAt(0);
        FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
        Cell cell;

        cell = sheet.getRow(0).getCell(0);
        assertEquals("#REF!*#REF!", cell.getCellFormula());
        assertEquals(Cell.CELL_TYPE_ERROR, evaluator.evaluateInCell(cell).getCellType());
        assertEquals("#REF!", FormulaError.forInt(cell.getErrorCellValue()).getString());

        Name nm1 = wb.getName("sale_1");
        assertNotNull("name sale_1 should be present", nm1);
        assertEquals("Sheet1!#REF!", nm1.getRefersToFormula());
        Name nm2 = wb.getName("sale_2");
        assertNotNull("name sale_2 should be present", nm2);
        assertEquals("Sheet1!#REF!", nm2.getRefersToFormula());

        cell = sheet.getRow(1).getCell(0);
        assertEquals("sale_1*sale_2", cell.getCellFormula());
View Full Code Here

    public void bug49966() throws Exception {
        XSSFWorkbook wb = XSSFTestDataSamples
                .openSampleWorkbook("shared_formulas.xlsx");
        XSSFSheet sheet = wb.getSheetAt(0);

        Workbook wbRead = XSSFTestDataSamples.writeOutAndReadBack(wb);

        // CalcChain has lots of entries
        CalculationChain cc = wb.getCalculationChain();
        assertEquals("A2", cc.getCTCalcChain().getCArray(0).getR());
        assertEquals("A3", cc.getCTCalcChain().getCArray(1).getR());
        assertEquals("A4", cc.getCTCalcChain().getCArray(2).getR());
        assertEquals("A5", cc.getCTCalcChain().getCArray(3).getR());
        assertEquals("A6", cc.getCTCalcChain().getCArray(4).getR());
        assertEquals("A7", cc.getCTCalcChain().getCArray(5).getR());
        assertEquals("A8", cc.getCTCalcChain().getCArray(6).getR());
        assertEquals(40, cc.getCTCalcChain().sizeOfCArray());
        wbRead.close();
       
        wbRead = XSSFTestDataSamples.writeOutAndReadBack(wb);

        // Try various ways of changing the formulas
        // If it stays a formula, chain entry should remain
        // Otherwise should go
        sheet.getRow(1).getCell(0).setCellFormula("A1"); // stay
        sheet.getRow(2).getCell(0).setCellFormula(null); // go
        sheet.getRow(3).getCell(0).setCellType(Cell.CELL_TYPE_FORMULA); // stay
        wbRead.close();
        wbRead = XSSFTestDataSamples.writeOutAndReadBack(wb);
        sheet.getRow(4).getCell(0).setCellType(Cell.CELL_TYPE_STRING); // go
        wbRead.close();
        wbRead = XSSFTestDataSamples.writeOutAndReadBack(wb);

        validateCells(sheet);
        sheet.getRow(5).removeCell(sheet.getRow(5).getCell(0)); // go
        validateCells(sheet);
        wbRead.close();
        wbRead = XSSFTestDataSamples.writeOutAndReadBack(wb);
       
        sheet.getRow(6).getCell(0).setCellType(Cell.CELL_TYPE_BLANK); // go
        wbRead.close();
        wbRead = XSSFTestDataSamples.writeOutAndReadBack(wb);
        sheet.getRow(7).getCell(0).setCellValue((String) null); // go
        wbRead.close();

        wbRead = XSSFTestDataSamples.writeOutAndReadBack(wb);

        // Save and check
        wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
        assertEquals(35, cc.getCTCalcChain().sizeOfCArray());

        cc = wb.getCalculationChain();
        assertEquals("A2", cc.getCTCalcChain().getCArray(0).getR());
        assertEquals("A4", cc.getCTCalcChain().getCArray(1).getR());
        assertEquals("A9", cc.getCTCalcChain().getCArray(2).getR());
        wbRead.close();
    }
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.usermodel.Workbook

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.