I am trying to create a program that would convert .csv file to .xlsx file using Apache POI. Everything works fine except that the .xlsx file generated does not display german letters with umlaut (ü,ä,ö) properly. It simply prints a question mark. Would anyone be so kind as to help me with this? Any help is much appreciated.
Here is the code that I have written. I am not an expert in Java so I apologize in advance if my code seems pretty basic.
private static void csvtoxlsx() {
try{
String csvfile = "test.csv";
String xlsxfile = "test-changed.xlsx";
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("sheet1");
XSSFFont xssfFont = workbook.createFont();
xssfFont.setCharSet(XSSFFont.ANSI_CHARSET);
XSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setFont(xssfFont);
String currentLine;
int RowNum = 0;
BufferedReader br = new BufferedReader(new FileReader(csvfile));
while((currentLine = br.readLine()) != null){
String[] str = currentLine.split(";");
RowNum++;
XSSFRow currentRow = sheet.createRow(RowNum);
for(int i=0; i< str.length; i++){
str[i] = str[i].replaceAll("\"","");
str[i] = str[i].replaceAll("=","");
XSSFCell cell = currentRow.createCell(i);
cell.setCellStyle(cellStyle);
cell.setCellValue(str[i].trim());
}
}
FileOutputStream fileOutputStream = new FileOutputStream(xlsxfile);
workbook.write(fileOutputStream);
fileOutputStream.close();
System.out.println("success");
}catch (Exception e){
e.printStackTrace();
}
}
FileReader