monitorjbl / excel-streaming-reader

An easy-to-use implementation of a streaming Excel reader using Apache POI
Apache License 2.0
960 stars 345 forks source link

DataFormat : StreamingWorkbook#createDataFormat() #123

Open clemensdev opened 7 years ago

clemensdev commented 7 years ago

First of all I (being pained by OOMs due to POI Excel imports ;) ) would like to say how impressed I am by the low footprint of this streaming reader. Unfortunately we need to access workbook.createDataFormat().getFormat( dataFormatNr ) to get cell (formatting) details. But StreamingWorkbook#createDataFormat() is not supported and hence throws UnsupportedOperationException() What would be the "right way" to get the DataFormat of a workbook?

clemensdev commented 7 years ago

I have just noticed that the StreamingWorkbookReader has the sytles(Table). What if these became a new field (instead of the local variable) and would be provided through StreamingWorkbookReader#getStylesTable() ? Then StreamingWorkbook could implement createDataFormat as follows:

  public DataFormat createDataFormat() {
    if (formatter == null) {
          formatter = new StreamingDataFormat(reader.getStylesTable());
      }
      return formatter;
  }

StreamingDataFormat being a copy of XSSFDataFormat

monitorjbl commented 7 years ago

That certainly sounds like it could work. I don't have a workbook to test with though, would you be able to implement this in a PR and include one?

clemensdev commented 7 years ago

would you be able to implement this in a PR

me being git newbie, I hope you can live with a simple patch?

stylesTable.zip