LoginSignup
0
2

More than 5 years have passed since last update.

JAVAでEXCELファイル更新サンプル

Last updated at Posted at 2017-12-03

//下記のURLでPOIのJARファイルをダウンロードする。
https://www.apache.org/dyn/closer.lua/poi/release/bin/poi-bin-3.17-20170915.tar.gz

import java.io.;
import org.apache.poi.ss.usermodel.
;

public class UpdateExcel {
public static void main(String[] args) throws Exception {
// Excelファイル
File f = new File("C:\Book1.xlsx");
InputStream is = new FileInputStream(f);
Workbook wb = WorkbookFactory.create(is);
is.close();

    // シート1
    Sheet s = wb.getSheetAt(0);

    //第一行目
    Row r0 = s.getRow(0);
    // A1
    Cell A1 = r0.getCell(0);
    A1.setCellValue("W");
    // A2
    Cell A2 = r0.getCell(1);
    A2.setCellValue("K");
    // A3
    Cell A3 = r0.getCell(2);
    A3.setCellValue("O");

    OutputStream os = new FileOutputStream(f);
    wb.write(os);
}

}

0
2
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
2