publicclassTools { /** * Convert CSV file to Excel file * @param dir Directory: `/home/`, `C:/Users/` * @param filename File name: `filename` */ publicstaticvoidconvertCsvToExcel(String dir, String filename) { // Load the CSV file Workbookworkbook=newWorkbook(); workbook.loadFromFile(dir + filename + ".csv", ",", 1, 1); // Get the first worksheet Worksheetsheet= workbook.getWorksheets().get(0); // Access the used range in the worksheet CellRangeusedRange= sheet.getAllocatedRange(); // Ignore errors when saving numbers in the range as text usedRange.setIgnoreErrorOptions(EnumSet.of(IgnoreErrorType.NumberAsText)); // Adjust row height and column width automatically usedRange.autoFitColumns(); usedRange.autoFitRows(); // Save the document workbook.saveToFile(dir + filename + ".xlsx", ExcelVersion.Version2013); } }