0

jexcelライブラリで遊んでいます

次のことを行う小さなプログラムをコーディングしようとしました。

  1. xlsファイルを読む
  2. シートでいくつかの計算を行い、別の場所に書き込みます

パブリッククラスDataProcessor {

    private String inputFile;
    private String outputFile;



private Sheet sheet;
    private Workbook w;

    public void setInputFile(String inputFile) {
        this.inputFile = inputFile;
    }

    public void setOutputFile(String outputFile) {
        this.outputFile = outputFile;
    }

    public void read() throws IOException {
        File inputWorkbook = new File(inputFile);
        Workbook w;
        try {
            w = Workbook.getWorkbook(inputWorkbook);
            sheet = w.getSheet(0);
        } catch (BiffException e) {
            e.printStackTrace();
        }
    }

    @SuppressWarnings("deprecation")
    public void write() throws IOException, WriteException {
        File file = new File(inputFile);
        WorkbookSettings wbSettings = new WorkbookSettings();

        wbSettings.setLocale(new Locale("en", "EN"));

        WritableWorkbook workbook = Workbook.createWorkbook(file, wbSettings);
        workbook.createSheet("Lolonator", 0);
        workbook.createSheet("Lolonator123", 1);
        workbook.copy(w);

        workbook.write();
        workbook.close();
    }

    public static void main(String[] args) throws IOException, WriteException {
        ReadExcel test = new ReadExcel();
        test.setInputFile("C:/Users/Desktop/sheet1.xls");
        test.read();
        System.out.println("####################################################");
        System.out.println("File read!");

//      Write
        System.out.println("####################################################");
        System.out.println("Start to write the file!");
        WriteExcel out = new WriteExcel();
        out.setOutputFile("C:/Users/Desktop/sheet2.xls");
        out.write();
        System.out.println("Please check the result file!");

    }

}

ただし、これは機能しません。プログラムは最後まで例外なく実行されますが、シートに出力がありません。あなたの答えに本当に感謝します!!!

4

1 に答える 1