LoginSignup
0
1

More than 1 year has passed since last update.

JavaでExcelをいじるメモ

Posted at

先に結論

  • Poiライブラリ を使う
    • 日本語は文字化け・警告が出る
  • csvファイルを使う
    • ひとまず使える

日本語が入っていないファイルー>Poiを使う(警告は無視する)
日本語が入っている->csvで頑張る。

Poi

を参考にIntelliJにPoiをインストールし

を参考に実行した。

結果

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
value_name �F �c��
value_sex �F �j
value_age �F 26��

Log4j2というロガーがないのか・・・よくわからない
さらに文字化けしている。

csvファイル

サンプルコード

    public static void main(String[] args) {
        String fileName = "C:\\t\\test.csv";

        File file = new File(fileName);
        if (!file.exists()) {
            System.out.print("ファイルが存在しません");
            return;
        }

        try (FileReader fileReader = new FileReader(fileName);
             InputStreamReader osr  = new InputStreamReader(new FileInputStream(file), "SJIS");
             BufferedReader bufferedReader = new BufferedReader(osr)) {
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                String[] arrayStr = line.split(",");

                for (String str : arrayStr) {
                    System.out.println(str);
                }
            }
        } catch (IOException e) {
            System.out.println(e);
        }

結果

?��田中
男
26歳

一個目が不明

しかし、文字化けはしていない。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1