Example usage for org.apache.poi.hssf.usermodel HSSFCell getStringCellValue

List of usage examples for org.apache.poi.hssf.usermodel HSSFCell getStringCellValue

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFCell getStringCellValue.

Prototype

public String getStringCellValue() 

Source Link

Document

get the value of the cell as a string - for numeric cells we throw an exception.

Usage

From source file:org.wso2.carbon.registry.reporting.test.Carbon11686.java

License:Open Source License

/**
 * verifies Activity report generation with type set to Excel
 *
 * @throws org.apache.axis2.AxisFault//  w  w  w  .  j a  v  a2s.  com
 * @throws Exception
 */
@Test(groups = "wso2.greg", description = "verifies report generation with type set to Excel", dependsOnMethods = "testActivityReportHTML")
public void testActivityReportExcelType() throws AxisFault, Exception {
    ByteArrayOutputStream report = getReportOutputStream("Excel");

    assertNotNull(report);

    saveByteArrayOutputStreamtoFile(report);

    try {
        FileInputStream myInput = new FileInputStream(Dest_file);

        POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);

        HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);

        HSSFSheet mySheet = myWorkBook.getSheetAt(0);

        HSSFRow customRow = mySheet.getRow(4);
        HSSFCell customCell = customRow.getCell(2);
        assertTrue(customCell.getStringCellValue().contains(userNameRandom));

        customCell = customRow.getCell(2);
        assertTrue(customCell.getStringCellValue().contains("has added the resource"));

        customCell = customRow.getCell(2);
        assertTrue(customCell.getStringCellValue().contains(testGovernanceLCRXT));

        customRow = mySheet.getRow(6);
        customCell = customRow.getCell(2);
        assertTrue(customCell.getStringCellValue().contains(userNameRandom));

        customCell = customRow.getCell(2);
        assertTrue(customCell.getStringCellValue().contains("has added the resource"));
        //This is only valid for the fresh instance (with fresh database)
        //            customCell = customRow.getCell(2);
        //            System.out.println("String cell value #####################################" + customCell.getStringCellValue());
        //            assertTrue(customCell.getStringCellValue().contains(testGovernanceLCtemplate));
    } catch (Exception e) {
        throw e;
    }
}

From source file:org.wso2.carbon.registry.reporting.test.ReportCopyingTestCases.java

License:Open Source License

/**
 * Copy an existing report then change its report type and verify
 * - whether the new resource generates the report successfully
 * - whether the existing resource generates the report successfully as
 * before/*from   w  w  w. j  a v  a 2s .c  o  m*/
 *
 * @throws Exception
 */
@Test(groups = "wso2.greg", description = "Copy an existing report then change its report type", dependsOnMethods = "testCopyReportConfig")
public void testCopyReportConfigChangeType() throws Exception {
    ReportConfigurationBean configurationBeanOriginal = reportAdminServiceClient
            .getSavedReport("TestGovernanceLCReport");
    ReportConfigurationBean configurationBeanCopy = reportAdminServiceClient
            .getSavedReport("TestGovernanceLCReportCopy");

    configurationBeanCopy.setType("Excel");

    reportAdminServiceClient.saveReport(configurationBeanCopy);

    configurationBeanCopy.setAttributes(testLCattributes);

    DataHandler report = reportAdminServiceClient.getReportBytes(configurationBeanCopy);

    saveDataHandlerToFile(report);

    try {
        FileInputStream myInput = new FileInputStream(Dest_file);

        POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);

        HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);

        HSSFSheet mySheet = myWorkBook.getSheetAt(0);

        HSSFRow customRow = mySheet.getRow(9);
        HSSFCell customCell = customRow.getCell(2);
        assertTrue(customCell.getStringCellValue().equals("G-regTesting"));

        customCell = customRow.getCell(5);
        assertTrue(customCell.getStringCellValue().equals(artifactName + "1"));

        customCell = customRow.getCell(8);
        assertTrue(customCell.getStringCellValue().equals("4.5.0"));

        customCell = customRow.getCell(12);
        assertTrue(customCell.getStringCellValue().equals("Smoke test"));
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }

    configurationBeanOriginal.setAttributes(testLCattributes);

    report = reportAdminServiceClient.getReportBytes(configurationBeanOriginal);

    String result = readInputStreamAsString(report.getInputStream());

    assertTrue(result.contains("G-regTesting"));
    assertTrue(result.contains("4.5.0"));
    assertTrue(result.contains("Smoke test"));
}

From source file:org.wso2.carbon.registry.reporting.test.ReportGenerationTestCases.java

License:Open Source License

/**
 * verifies report generation with type set to Excel
 *
 * @throws AxisFault/*w w  w .  j  a  va  2  s .c om*/
 * @throws Exception
 */
@Test(groups = "wso2.greg", description = "verifies report generation with type set to Excel", dependsOnMethods = "testAddResourcesForReportGenerationTesting")
public void testGetReportExcelType() throws AxisFault, Exception {
    ReportConfigurationBean configurationBean = reportAdminServiceClient
            .getSavedReport("TestGovernanceLCReport");
    configurationBean.setType("Excel");
    configurationBean.setAttributes(testLCattributes);

    DataHandler report = reportAdminServiceClient.getReportBytes(configurationBean);

    saveDataHandlerToFile(report);

    try {
        FileInputStream myInput = new FileInputStream(Dest_file);

        POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);

        HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);

        HSSFSheet mySheet = myWorkBook.getSheetAt(0);

        HSSFRow customRow = mySheet.getRow(9);
        HSSFCell customCell = customRow.getCell(2);
        assertTrue(customCell.getStringCellValue().equals("G-regTesting"));

        customCell = customRow.getCell(5);
        assertTrue(customCell.getStringCellValue().equals(artifactName + "1"));

        customCell = customRow.getCell(8);
        assertTrue(customCell.getStringCellValue().equals("4.5.0"));

        customCell = customRow.getCell(12);
        assertTrue(customCell.getStringCellValue().equals("Smoke test"));
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }

}

From source file:org.xianairlines.action.staffs.StaffsImportAction.java

private Date parse(HSSFCell cell) {
    DateUtil du = new DateUtil();
    if (cell.getCellType() == 0)
        return cell.getDateCellValue();
    if (cell.getCellType() == 1)
        return du.parse(cell.getStringCellValue(), "yyyyMMdd");
    return null;/*from w w  w . j  ava 2s . c o  m*/
}

From source file:org.xianairlines.action.staffs.StaffsImportAction.java

private String readCell(HSSFCell cell) {
    if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
        return cell.getStringCellValue();
    } else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
        return String.valueOf(cell.getNumericCellValue());
    } else if (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {

    }//from   w  w  w  . ja v  a 2  s . c o m
    return null;
}

From source file:org.zilverline.extractors.ExcelExtractor.java

License:Open Source License

/**
 * Extract the content from the given Excel file. As a side effect the type is set too.
 * //from   w  w  w. j  a v a 2  s.co  m
 * @see org.zilverline.extractors.AbstractExtractor#getContent(java.io.File)
 */
public final Reader getContent(final File f) {
    Reader reader = null;

    setType("EXCEL");

    try {
        CharArrayWriter writer = new CharArrayWriter();

        POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(f));
        HSSFWorkbook workbook = new HSSFWorkbook(fs);

        for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
            HSSFSheet sheet = workbook.getSheetAt(i);

            Iterator rows = sheet.rowIterator();
            while (rows.hasNext()) {
                HSSFRow row = (HSSFRow) rows.next();

                Iterator cells = row.cellIterator();
                while (cells.hasNext()) {
                    HSSFCell cell = (HSSFCell) cells.next();
                    switch (cell.getCellType()) {
                    case HSSFCell.CELL_TYPE_NUMERIC:
                        String num = Double.toString(cell.getNumericCellValue()).trim();
                        if (num.length() > 0) {
                            writer.write(num + " ");
                        }
                        break;
                    case HSSFCell.CELL_TYPE_STRING:
                        String text = cell.getStringCellValue().trim();
                        if (text.length() > 0) {
                            writer.write(text + " ");
                        }
                        break;
                    default: // skip
                    }
                }
            }
        }
        setSummary(getSummaryFromContent(writer.toString()));

        return new CharArrayReader(writer.toCharArray());
    } catch (Exception e) {
        log.warn("Can't extract contents for: " + f.getName(), e);
    }

    return reader;
}

From source file:org.zilverline.extractors.ExcelExtractor.java

License:Open Source License

/**
 * Extract the content from the given Excel file. As a side effect the type is set too.
 * /*from w ww  .ja va 2  s  . c  o m*/
 * @see org.zilverline.extractors.AbstractExtractor#getContent(java.io.File)
 */
public final String getContent(final InputStream is) {
    try {
        CharArrayWriter writer = new CharArrayWriter();

        POIFSFileSystem fs = new POIFSFileSystem(is);
        HSSFWorkbook workbook = new HSSFWorkbook(fs);

        for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
            HSSFSheet sheet = workbook.getSheetAt(i);

            Iterator rows = sheet.rowIterator();
            while (rows.hasNext()) {
                HSSFRow row = (HSSFRow) rows.next();

                Iterator cells = row.cellIterator();
                while (cells.hasNext()) {
                    HSSFCell cell = (HSSFCell) cells.next();
                    switch (cell.getCellType()) {
                    case HSSFCell.CELL_TYPE_NUMERIC:
                        String num = Double.toString(cell.getNumericCellValue()).trim();
                        if (num.length() > 0) {
                            writer.write(num + " ");
                        }
                        break;
                    case HSSFCell.CELL_TYPE_STRING:
                        String text = cell.getStringCellValue().trim();
                        if (text.length() > 0) {
                            writer.write(text + " ");
                        }
                        break;
                    default: // skip
                    }
                }
            }
        }

        return new String(writer.toCharArray());
    } catch (Exception e) {
        log.warn("Can't extract contents", e);
    }

    return "";
}

From source file:payroll.jobs.JobFactory.java

private String getAdvancedJobType(HSSFRow unprocessedRow) {
    int advancedJobTypeIndex = formatChecker.getAdvancedTypeLocation();
    HSSFRow currentRow = unprocessedRow;
    HSSFCell advancedTypeCell = currentRow.getCell(advancedJobTypeIndex);
    String jobType = advancedTypeCell.getStringCellValue();
    return jobType;
}

From source file:payroll.jobs.RowParser.java

/**
 * Method to parse a row containing Job data.
 * @param inRow HSSFRow to be processed.
 *//*from w  ww.j  a v a2s  .  com*/
public void processRow(HSSFRow inRow) {

    HSSFCell accountNumberCell = inRow.getCell(accountNumberIndex);
    accountNumber = accountNumberCell.getStringCellValue();
    HSSFCell workOrderNumberCell = inRow.getCell(workOrderIndex);
    workOrderNumber = workOrderNumberCell.getStringCellValue();
    HSSFCell dateCell = inRow.getCell(dateIndex);
    date = dateCell.getDateCellValue();
    HSSFCell techIDCell = inRow.getCell(techIDIndex);
    techID = techIDCell.getStringCellValue();
    HSSFCell customerNameCell = inRow.getCell(customerNameIndex);
    customerName = customerNameCell.getStringCellValue();

}

From source file:payroll.tasks.TaskFactory.java

private static String getStringCellValue(HSSFCell inCell) {
    HSSFCell cell = inCell;
    String value;/*w  ww .  ja v a  2 s.  c o  m*/

    // Check to see if cell is numeric (Receiver) or not (Could be anything)
    int cellType = cell.getCellType();
    // If cell is numeric
    if (cellType == 0) {
        // Get numeric cell's value as a Double
        Double cellValue = cell.getNumericCellValue();
        // Convert double value to string to be able to instantiate task
        value = Double.toString(cellValue);
    }
    // Else get cell's value as String
    else {
        value = cell.getStringCellValue();
    }
    return value;
}