I sent this earlier, but I am very interested to know if HSSFWorkbook.getSSTString(int) will be removed or restricted in upcoming releases of POI. See below for the reason for my concern. Thank you.
> ---- [EMAIL PROTECTED] wrote:
> > Why was HSSFWorkbook.getSSTString(int) deprecated? I parse spreadsheets
> > that are uploaded via a web application and there are times I get
> > spreadsheets that look like they have data but when the normal methods of
> > getting data out of the cells are used, it does not return any data. The
> > only way I can get the data out of the spreadsheet is to use the
> > getSSTString method. When I saw it was deprecated in 3.0, I was hopeful
> > that the issue was corrected, but I just tried it and I am still required
> > to use getSSTString to get the data.
> >
> > A code snippet form the code I use to get the data from the spreadsheet is
> > as follows and I have attached an example spreadsheet that has this issue.
> > Note that if you open it and save it, it will not have the issue anymore.
> > If you are going to try it out, just save it directly from the email.
> >
> > Thanks for any help. If more information is needed, I will be happy to
> > provide it.
> >
> > int rowCnt = sheet.getLastRowNum();
> > for (int rowNum = 0; rowNum <= rowCnt; rowNum++)
> > {
> > boolean isBlankRow = true;
> > HSSFRow row = sheet.getRow(rowNum);
> > if (row == null)
> > {
> > System.out.println("Row " + rowNum + " was NULL.");
> > continue;
> > }
> >
> > Collection errors = new ArrayList();
> > Object voObject = null;
> > try
> > {
> > voObject = voClass.newInstance();
> > } catch (IllegalAccessException ex)
> > {
> > ex.printStackTrace();
> > throw new RwtException(ExceptionConstants.GENERAL_EX,
> > RwtException.SYSTEM_EXCEPTION,
> > RwtException.FATAL_ERROR, ex);
> > } catch (InstantiationException ex)
> > {
> > ex.printStackTrace();
> > throw new RwtException(ExceptionConstants.GENERAL_EX,
> > RwtException.SYSTEM_EXCEPTION,
> > RwtException.FATAL_ERROR, ex);
> > }
> >
> > int cellCnt = row.getLastCellNum();
> > Collection mapColumns = fileMap.getColumns();
> > if (hasHeader && rowNum == 0)
> > {
> > System.out.println("Validating the header!!!");
> > Collection headerErrors = validateHeader(row,
> > mapColumns,
> > file.getFileName(), rowNum);
> > if (headerErrors.size() > 0)
> > {
> > System.out.println("Found error in header.");
> > throw new InvalidHeaderException(headerErrors);
> > }
> > } else
> > {
> > Collection cellValues = new ArrayList();
> > for (short cellNum = 0; cellNum < cellCnt; cellNum++)
> > {
> > HSSFCell cell = row.getCell(cellNum);
> > if (cell != null
> > && cell.getCellType() !=
> > HSSFCell.CELL_TYPE_BLANK)
> > {
> > // Get the value of the cell and approximate
> > its type
> > int cellType = cell.getCellType();
> > Object cellValue = null;
> > if (cellType == HSSFCell.CELL_TYPE_NUMERIC)
> > {
> > double cellDoubleValue = cell
> > .getNumericCellValue();
> > if (HSSFDateUtil.isCellDateFormatted(cell))
> > {
> > cellValue = new Timestamp(HSSFDateUtil
> > .getJavaDate(cellDoubleValue)
> > .getTime());
> > } else
> > {
> > long cellLongValue = (long)
> > cellDoubleValue;
> > if (cellLongValue == cellDoubleValue)
> > {
> > cellValue = new Long(cellLongValue);
> > } else
> > {
> > cellValue = new
> > Double(cellDoubleValue);
> > }
> > }
> > } else if (cellType ==
> > HSSFCell.CELL_TYPE_STRING)
> > {
> > // WR-1579 begin
> > HSSFRichTextString richText =
> > cell.getRichStringCellValue();
> > cellValue = richText.getString();
> > // WR-1579 end
> > }
> >
> > foundRowData = true;
> > cellValues.add(cellValue);
> > } else
> > {
> > cellValues.add("");
> > }
> > }
> >
> > /* If no valid cell has been found
> > * to this point in the spreadsheet
> > * try to get a value from the Shared
> > * String Table at the row's position.
> > *
> > * See page 389 in the
> > * Excel 97 Developer's Kit
> > */
> > if (!foundRowData)
> > {
> > System.out
> > .println("No cell data has been found for
> > row: "
> > + rowNum);
> >
> > try
> > {
> > /* If and SST value is found then the cellValues
> > * Collection must be cleared to remove any
> > empty
> > * Strings added in the cell loop, above.
> > */
> > System.out
> > .println("Looking for cell data from
> > Shared String Table: "
> > + sstPosition); // WR-0964
> >
> > String sstString = workbook
> > .getSSTString(sstPosition);
> > cellValues = new ArrayList();
> > cellValues.add(sstString);
> > System.out
> > .println("Set cell data from Shared
> > String Table: "
> > + sstPosition); // WR-0964
> > } catch (Exception e)
> > {
> > System.out
> > .println("Failed to get Shared String
> > Table String: "
> > + sstPosition); // WR-0964
> > }
> > sstPosition++;
> > }
22R26405accounts_sstexample.xls
Description: MS-Excel spreadsheet
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
