// Create an 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(); }