// Create a new workbook Workbook workbook = new Workbook(); // region Define custom classes /* public class CustomParser implements ICsvParser { @Override public void Parse(CsvParseResult csvParseResult, CsvParseContext csvParseContext) { if (csvParseContext.getText().startsWith("00")) { csvParseResult.setValue(csvParseContext.getText()); } else if(csvParseContext.getColumn() == 5 || csvParseContext.getColumn() == 6) { csvParseResult.setNumberFormat("#.00"); } else if(csvParseResult.getNumberFormat().equals("m/d/yyyy h:mm")){ csvParseResult.setNumberFormat("m/d/yyyy"); } } } */ InputStream fileStream = this.getResourceStream("xlsx/CustomParseOnReadingCsvFiles.csv"); // Create CsvOpenOptions and custom parser rules. CsvOpenOptions csvOpenOptions = new CsvOpenOptions(); csvOpenOptions.setParser(new CustomParser()); // Open csv file with option. workbook.open(fileStream, csvOpenOptions); IWorksheet worksheet = workbook.getActiveSheet(); // Change column width and row height int[] columnWidths = { 15, 12, 24, 15, 25, 12, 15 }; int[] rowHeights = { 19, 17, 17, 17, 17, 17, 17, 17 }; for(int i = 0; i < columnWidths.length; i++) { worksheet.getColumns().get(i).setColumnWidth(columnWidths[i]); } for(int i = 0; i < rowHeights.length; i++) { worksheet.getRows().get(i).setRowHeight(rowHeights[i]); } worksheet.getSheetView().setDisplayGridlines(false); worksheet.getRange("A1").setValue("PURCHASE ORDERS"); // Set style worksheet.getRange("A1:G1").merge(); worksheet.getRange("A1").getFont().setSize(14); worksheet.getRange("A1").getFont().setBold(true); worksheet.getRange("A1").setHorizontalAlignment(HorizontalAlignment.Center); worksheet.getRange("A2:G8").setHorizontalAlignment(HorizontalAlignment.Right); worksheet.getRange("C2:C8").setHorizontalAlignment(HorizontalAlignment.Left); worksheet.getRange("E2:E8").setHorizontalAlignment(HorizontalAlignment.Left); worksheet.getRange("A2:G2").getFont().setSize(10); worksheet.getRange("A2:G2").getFont().setBold(true); worksheet.getRange("A2:G2").getInterior().setColor(Color.FromArgb(255, 242, 204)); worksheet.getRange("A3:G8").getFont().setSize(9); worksheet.getRange("A1:G8").getFont().setName("Trebuchet MS"); worksheet.getRange("A1:G8").getBorders().setLineStyle(BorderLineStyle.Thin); worksheet.getRange("A1:G8").getBorders().get(BordersIndex.InsideVertical).setLineStyle(BorderLineStyle.None); worksheet.getRange("A1:G8").getBorders().get(BordersIndex.EdgeTop).setLineStyle(BorderLineStyle.None); worksheet.getRange("A1:G8").getBorders().get(BordersIndex.EdgeRight).setLineStyle(BorderLineStyle.None); // Save to an excel file workbook.save("CustomParserOnReadingCsvFiles.xlsx");