从xls文件中读取希腊字符到java

时间:2021-02-28 16:03:33

I am trying to read an xls file in java and convert it to csv. The problem is that it contains greek characters. I have used various different methods with no success.

我试图在java中读取xls文件并将其转换为csv。问题是它包含希腊字符。我使用了各种不同的方法但没有成功。

br = new BufferedReader(new InputStreamReader(
            new FileInputStream(saveDir+"/"+fileName+".xls"), "UTF-8")); 
FileWriter writer1 = new FileWriter(saveDir+"/A"+fileName+".csv");
byte[] bytes = thisLine.getBytes("UTF-8");
writer1.append(new String(bytes, "UTF-8"));

used that with different encoders, like utf16 and windoes-1253 and ofcourse with out using the bytes array. none worked. any ideas?

使用不同的编码器,如utf16和windoes-1253,以及使用bytes数组。没人工作。有任何想法吗?

2 个解决方案

#1


Use "ISO-8859-7" instead of "UTF-8". It is for latin and greek. See documentation

使用“ISO-8859-7”代替“UTF-8”。这是拉丁语和希腊语。见文档

 InputStream in = new BufferedInputStream(new FileInputStream(new File(myfile)));

        result = new Scanner(in,"ISO-8859-7").useDelimiter("\\A").next();

#2


A Byte Order Mask (BOM) should be entered at the start of the CSV file.

应在CSV文件的开头输入字节顺序掩码(BOM)。

Can you try this code?

你能试试这段代码吗?

PrintWriter writer1 = new PrintWriter(saveDir+"/A"+fileName+".csv");
writer1.print('\ufeff');
....

#1


Use "ISO-8859-7" instead of "UTF-8". It is for latin and greek. See documentation

使用“ISO-8859-7”代替“UTF-8”。这是拉丁语和希腊语。见文档

 InputStream in = new BufferedInputStream(new FileInputStream(new File(myfile)));

        result = new Scanner(in,"ISO-8859-7").useDelimiter("\\A").next();

#2


A Byte Order Mask (BOM) should be entered at the start of the CSV file.

应在CSV文件的开头输入字节顺序掩码(BOM)。

Can you try this code?

你能试试这段代码吗?

PrintWriter writer1 = new PrintWriter(saveDir+"/A"+fileName+".csv");
writer1.print('\ufeff');
....