Example usage for org.apache.poi.ss.usermodel Workbook getSheetName

List of usage examples for org.apache.poi.ss.usermodel Workbook getSheetName

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Workbook getSheetName.

Prototype

String getSheetName(int sheet);

Source Link

Document

Get the sheet name

Usage

From source file:org.pentaho.reporting.engine.classic.core.bugs.Prd5268IT.java

License:Open Source License

@Test
public void testSheetNames() throws Exception {
    MasterReport report = createReport();
    Assert.assertFalse(new ReportStructureValidator().isValidForFastProcessing(report));

    ByteArrayOutputStream boutFast = new ByteArrayOutputStream();
    FastExcelReportUtil.processXlsx(report, boutFast);

    Workbook workbook = WorkbookFactory.create(new ByteArrayInputStream(boutFast.toByteArray()));
    Assert.assertEquals(3, workbook.getNumberOfSheets());
    Assert.assertEquals("FIRST REPORT", workbook.getSheetName(0));
    Assert.assertEquals("SECOND REPORT", workbook.getSheetName(1));
    Assert.assertEquals("SECOND REPORT 2", workbook.getSheetName(2));
}

From source file:org.pentaho.reporting.engine.classic.core.bugs.Prd5268Test.java

License:Open Source License

@Test
public void testSheetNamesInFastMode() throws Exception {
    MasterReport report = createReport();
    Assert.assertTrue(new ReportStructureValidator().isValidForFastProcessing(report));

    ByteArrayOutputStream boutFast = new ByteArrayOutputStream();
    FastExcelReportUtil.processXlsx(report, boutFast);

    Workbook workbook = WorkbookFactory.create(new ByteArrayInputStream(boutFast.toByteArray()));
    Assert.assertEquals(3, workbook.getNumberOfSheets());
    Assert.assertEquals("FIRST REPORT", workbook.getSheetName(0));
    Assert.assertEquals("SECOND REPORT", workbook.getSheetName(1));
    Assert.assertEquals("SECOND REPORT 2", workbook.getSheetName(2));
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.xls.helper.ExcelPrinterBase.java

License:Open Source License

protected Workbook createWorkbook() {
    // Not opened yet. Lets do this now.
    if (templateInputStream != null) {
        // do some preprocessing ..
        try {//from w w w. java 2  s . co m
            final Workbook workbook = WorkbookFactory.create(templateInputStream);

            // OK, we have a workbook, but we can't stop here..
            final int sheetCount = workbook.getNumberOfSheets();
            for (int i = 0; i < sheetCount; i++) {
                final String sheetName = workbook.getSheetName(i);
                // make sure that that name is marked as used ..
                makeUnique(sheetName);
            }

            return workbook;
        } catch (IOException e) {
            logger.warn("Unable to read predefined xls-data.", e);
        } catch (InvalidFormatException e) {
            logger.warn("Unable to read predefined xls-data.", e);
        }
    }
    if (isUseXlsxFormat()) {
        return new XSSFWorkbook();
    } else {
        return new HSSFWorkbook();
    }
}

From source file:org.powertools.engine.sources.ExcelTestSource.java

License:Open Source License

protected ExcelTestSource(String fileName, String sheetName, Scope scope, TestRunResultPublisher publisher) {
    super(scope, publisher);
    mFileName = fileName;//  ww w  .jav  a 2  s . c  o m
    Workbook workbook = createWorkbook(fileName);
    mSheetName = sheetName.isEmpty() ? workbook.getSheetName(0) : sheetName;
    Sheet sheet = workbook.getSheet(mSheetName);
    if (sheet == null) {
        throw new ExecutionException("sheet '" + mSheetName + "' does not exist");
    }
    mRowIter = sheet.rowIterator();
}

From source file:org.soulwing.jawb.poi.ApachePoiCellReference.java

License:Apache License

/**
 * {@inheritDoc}//from w w  w .  j a v a 2 s.  c  o m
 */
@Override
public BoundCellReference applyBias(int sheetOffset, int rowOffset, int columnOffset, BoundWorkbook workbook) {

    Workbook wb = ((ApachePoiWorkbook) workbook).getDelegate();

    int sheetIndex = delegate.getSheetName() != null ? wb.getSheetIndex(delegate.getSheetName()) : 0;
    sheetIndex += sheetOffset;
    String sheetName = wb.getSheetName(sheetIndex);

    int rowIndex = delegate.getRow();
    if (!delegate.isRowAbsolute()) {
        rowIndex += rowOffset;
    }

    short columnIndex = delegate.getCol();
    if (!delegate.isColAbsolute()) {
        columnIndex += columnOffset;
    }

    return new ApachePoiCellReference(new CellReference(sheetName, rowIndex, columnIndex,
            delegate.isRowAbsolute(), delegate.isColAbsolute()));
}

From source file:org.springframework.web.servlet.view.document.XlsViewTests.java

License:Apache License

@Test
public void testXls() throws Exception {
    View excelView = new AbstractXlsView() {
        @Override/*w  ww  .  ja  v  a  2s . com*/
        protected void buildExcelDocument(Map<String, Object> model, Workbook workbook,
                HttpServletRequest request, HttpServletResponse response) throws Exception {
            Sheet sheet = workbook.createSheet("Test Sheet");
            Row row = sheet.createRow(0);
            Cell cell = row.createCell(0);
            cell.setCellValue("Test Value");
        }
    };

    excelView.render(new HashMap<String, Object>(), request, response);

    Workbook wb = new HSSFWorkbook(new ByteArrayInputStream(response.getContentAsByteArray()));
    assertEquals("Test Sheet", wb.getSheetName(0));
    Sheet sheet = wb.getSheet("Test Sheet");
    Row row = sheet.getRow(0);
    Cell cell = row.getCell(0);
    assertEquals("Test Value", cell.getStringCellValue());
}

From source file:org.springframework.web.servlet.view.document.XlsViewTests.java

License:Apache License

@Test
public void testXlsxView() throws Exception {
    View excelView = new AbstractXlsxView() {
        @Override/* w w w  .  j  ava2 s . co m*/
        protected void buildExcelDocument(Map<String, Object> model, Workbook workbook,
                HttpServletRequest request, HttpServletResponse response) throws Exception {
            Sheet sheet = workbook.createSheet("Test Sheet");
            Row row = sheet.createRow(0);
            Cell cell = row.createCell(0);
            cell.setCellValue("Test Value");
        }
    };

    excelView.render(new HashMap<String, Object>(), request, response);

    Workbook wb = new XSSFWorkbook(new ByteArrayInputStream(response.getContentAsByteArray()));
    assertEquals("Test Sheet", wb.getSheetName(0));
    Sheet sheet = wb.getSheet("Test Sheet");
    Row row = sheet.getRow(0);
    Cell cell = row.getCell(0);
    assertEquals("Test Value", cell.getStringCellValue());
}

From source file:org.springframework.web.servlet.view.document.XlsViewTests.java

License:Apache License

@Test
public void testXlsxStreamingView() throws Exception {
    View excelView = new AbstractXlsxStreamingView() {
        @Override/* w  ww . j  a  v a 2 s. c  om*/
        protected void buildExcelDocument(Map<String, Object> model, Workbook workbook,
                HttpServletRequest request, HttpServletResponse response) throws Exception {
            Sheet sheet = workbook.createSheet("Test Sheet");
            Row row = sheet.createRow(0);
            Cell cell = row.createCell(0);
            cell.setCellValue("Test Value");
        }
    };

    excelView.render(new HashMap<String, Object>(), request, response);

    Workbook wb = new XSSFWorkbook(new ByteArrayInputStream(response.getContentAsByteArray()));
    assertEquals("Test Sheet", wb.getSheetName(0));
    Sheet sheet = wb.getSheet("Test Sheet");
    Row row = sheet.getRow(0);
    Cell cell = row.getCell(0);
    assertEquals("Test Value", cell.getStringCellValue());
}

From source file:org.wso2.carbon.registry.samples.populator.Main.java

License:Open Source License

private static void addReports(ConfigurationContext configContext) throws Exception {
    File reportsDirectory = new File(CommandHandler.getReportsLocation());
    if (reportsDirectory.exists()) {
        ReportGeneratorServiceClient client = new ReportGeneratorServiceClient(cookie,
                CommandHandler.getServiceURL(), configContext);
        Workbook[] workbooks = PopulatorUtil.getWorkbooks(reportsDirectory, "list");
        for (Workbook workbook : workbooks) {
            Sheet sheet = workbook.getSheet(workbook.getSheetName(0));
            if (sheet == null || sheet.getLastRowNum() == -1) {
                throw new RuntimeException("The first sheet is empty");
            }//w  w w . ja v  a2  s . co m
            int limit = sheet.getLastRowNum();
            for (int i = 0; i <= limit; i++) {
                Row row = sheet.getRow(i);
                if (row == null || row.getCell(0) == null) {
                    break;
                }
                client.saveReport(PopulatorUtil.getReportConfigurationBean(row.getCell(0).getStringCellValue(),
                        row.getCell(1).getStringCellValue(), row.getCell(2).getStringCellValue(),
                        row.getCell(3).getStringCellValue()));
            }
        }
    }
}

From source file:org.wso2.carbon.registry.samples.populator.Main.java

License:Open Source License

private static void addPermissions(ConfigurationContext configContext, File dataDirectory) throws Exception {
    UserManagementClient userManager = new UserManagementClient(cookie, CommandHandler.getServiceURL(),
            configContext);//from w ww .j av a 2s .  c  o m
    Workbook[] workbooks = PopulatorUtil.getWorkbooks(dataDirectory, "permission");
    for (Workbook workbook : workbooks) {
        Sheet sheet = workbook.getSheet(workbook.getSheetName(0));
        if (sheet == null || sheet.getLastRowNum() == -1) {
            throw new RuntimeException("The first sheet is empty");
        }
        int limit = sheet.getLastRowNum();
        for (int i = 0; i <= limit; i++) {
            Row row = sheet.getRow(i);
            if (row == null || row.getCell(0) == null) {
                break;
            }
            userManager.setRoleResourcePermission(getCellValue(row.getCell(0), null),
                    getCellValue(row.getCell(1), null), splitAndTrim(getCellValue(row.getCell(2), null), ","));
        }
    }
}