import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class PoiSample {
public static void main(String[] args) {
//Excelデータ生成
Workbook wb = new XSSFWorkbook(); //ブックの生成
Sheet sh = wb.createSheet(); //シートの生成
Row row = sh.createRow(0); //行の生成(1行目)
Cell cell = row.createCell(0); //セルの生成(A列)
cell.setCellValue("サンプル"); //文字のセット
//上下中央揃えにする
CellStyle cs = wb.createCellStyle();
cs.setVerticalAlignment(VerticalAlignment.CENTER);
cell.setCellStyle(cs);
//Excelファイル準備
FileOutputStream out = null;
String path = "D:¥¥sample.xlsx";
try {
//Excel出力
out = new FileOutputStream(path);
wb.write(out);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
wb.close();
out.close();
} catch (Exception ex2) {
ex2.printStackTrace();
}
}
}
}