// Create to a xlsx file stream FileOutputStream outputStream = null; try { outputStream = new FileOutputStream("OptionsToOptimizeFileSize.xlsx"); } catch (FileNotFoundException e) { e.printStackTrace(); } // Create a new workbook Workbook workbook = new Workbook(); InputStream fileStream = this.getResourceStream("xlsx/file needs to be optimized.xlsx"); workbook.open(fileStream); XlsxSaveOptions options = new XlsxSaveOptions(); options.setExcludeEmptyRegionCells(true); options.setExcludeUnusedStyles(true); options.setExcludeUnusedNames(true); workbook.save(outputStream, options); // Close the xlsx stream try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); }
// Create to a xlsx file stream var outputStream: FileOutputStream? = null try { outputStream = FileOutputStream("OptionsToOptimizeFileSize.xlsx"); } catch (e: FileNotFoundException) { e.printStackTrace() } // Create a new workbook var workbook = Workbook() val fileStream: InputStream? = this.getResourceStream("xlsx/file needs to be optimized.xlsx") workbook.open(fileStream) val options = XlsxSaveOptions() options.setExcludeEmptyRegionCells(true) options.setExcludeUnusedStyles(true) options.setExcludeUnusedNames(true) workbook.save(outputStream, options) // Close the xlsx stream try { if(outputStream != null){ outputStream.close() } } catch (e: IOException) { e.printStackTrace() }