Darka
Darka

Reputation: 2768

Apache POI read excel xlsx with greek language

There are a lot of topics how to read XLSX files and write to file and them work for me, but not for greek (just example) words. Excel looks like this:

srcid   city    county
00008   ΠΑΤΡΑ   ΑΧΑΪΑΣ
00008   ΠΑΛΛΗΝΗ ΑΤΤΙΚΗΣ
00008   ΠΑΤΡΑ   ΑΧΑΪΑΣ

When I read this, I get ???? where are cities and counties. I tried different example: ToCSV , XLSX2CSV

Something wrong with charset, but I dont know what. I updated examples with UTF-8 encoding, but no luck.

I am using this dependencies: org.apache.poi poi 3.9

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.9</version>
</dependency>

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>ooxml-schemas</artifactId>
    <version>1.1</version>
</dependency>

<dependency>
    <groupId>org.apache.xmlbeans</groupId>
    <artifactId>xmlbeans</artifactId>
    <version>2.5.0</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>openxml4j</artifactId>
    <version>1.0-beta</version>
</dependency>
 <dependency>
    <groupId>dom4j</groupId>
    <artifactId>dom4j</artifactId>
    <version>1.6.1</version>
</dependency>   

Please help. I can't find out what is wrong. Maybe something this system encoding?

Upvotes: 0

Views: 1488

Answers (1)

Joop Eggen
Joop Eggen

Reputation: 109532

ToCSV.saveCSVFile uses a FileWriter, which uses the default platform encoding. Instead do:

bw = new BufferedWriter(
        new FileOutputStreamWriter(new FileOutputStream(file), "UTF-8"));

(Then it is always UTF-8.)

Upvotes: 2

Related Questions