On 16/05/15 11:02, Nick Burch wrote:
> On Fri, 15 May 2015, David North wrote:
>> One change which we have in our local build of POI is the extraction of
>> super-interfaces to make streaming read of worksheets a bit nicer:
>>
>> "CellEssence" is implemented by XSSFCell, HSSFCell and SXSSFCell:
>>
>> "RowEssence" is similar and exposes CellEssences for that row.
>>
>> Is the introduction of these interfaces something you'd consider
>> accepting a patch for? How do the names sound? Full list of methods
>> below for the record.
>
> Are you able to post a bit of your streaming reading code so we can
> see how it fits in there? Might help us understand the idea a bit
> better, and why you couldn't just use the existing Row and Cell
> interfaces on your code
>
> Naming wise, I wonder if the common SL stuff on the branch might have
> a good convention there already we could follow? (I can't see an
> equivalent from a quick grep to base off of)

As we understand it, the SXSSF interfaces are all about streaming
/write/ of workbooks. Streaming read is possible but rather more
low-level, for example:-

    XSSFReader reader = new XSSFReader(pkg);
    ReadOnlySharedStringsTable sst = new ReadOnlySharedStringsTable(pkg);
    XMLReader parser = createSheetReader(workbookIsDate1904, sheetName,
sst, reader.getStylesTable());
    try (final InputStream targetSheet = reader.getSheet(sheetId)) {
      InputSource sheetSource = new InputSource(targetSheet);
      parser.parse(sheetSource);
    }

And the content handler would look like:

SheetContentsHandler sheetContentsHandler = new SheetContentsHandler() {

      public void startRow(final int rowNum) {
      }

      public void endRow() {
      }

      @Override
      public void stringCell(final CellReference cellCoordinate, final
RichTextString text, final CellStyle style) {
      }

       // more methods for different types of cell...
}

This is quite low-level, though the pieces are all there. In order to
make it possible to transition some existing code written in terms of
Row and Cell across to streaming (while still being able to test it
against the non-streaming read), we invented CellEssence and RowEssence
as the minimal set of information from Row/Cell which is easy to
assemble during a streaming read using the above handler. So if we push
the interfaces upstream it would make sense to provide a handler, at
least as an example, showing how to create row and cell essences from a
streaming parse. Here's an extract from ours:

      public void startRow(final int rowNum) {
        _currentRow = new StreamedRowEssence(rowNum);
      }

      public void endRow() throws E {
        essenceHandler.handleRow(_currentRow);
      }

      @Override
      public void stringCell(final CellReference cellCoordinate, final
RichTextString text, final CellStyle style) {
        StreamedCellEssence cell = addCell(cellCoordinate, style);
        cell.setStringValue(text);
        cell.setCellType(STCellType.STR);
      }

Implementing Row/Cell on the objects created here would be a bit of a
lie as lots of methods would have to throw UnsupportedOperationException.

Thanks,
David

-- 
David North, Technical Lead, CoreFiling Limited
http://www.corefiling.com
Phone: +44-1865-203192

Reply via email to