JAva読み書きexcelのPOI編—002
poi excelファイルの作成は、接尾辞を作成する.xls excelファイル は、接尾辞を作成する.xlsx excelファイル
バージョンpoi-3.10.1の使用
比較的に簡単で、多く言いません!
@Test
public void testCreateWorkbook_xls() {
HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
// Worksheet( sheet xls )
HSSFSheet sheetOne = hssfWorkbook.createSheet();
HSSFSheet sheetTwo = hssfWorkbook.createSheet();
HSSFSheet sheetThree = hssfWorkbook.createSheet(" ");
// excel ,xls
FileOutputStream fileOutputStream = null;
String filePath = "D:\\test.xls";
try {
fileOutputStream = new FileOutputStream(filePath);
hssfWorkbook.write(fileOutputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println(e.toString());
} catch (IOException e) {
e.printStackTrace();
System.out.println(e.toString());
} finally {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
System.out.println(e.toString());
}
}
}
// Workbook OOXML (.xlsx)
@Test
public void testCreateWorkbook_xlsx(){
// excel ,xlsx
String filePath = "D:\\test.xlsx";
FileOutputStream fileOutputStream = null;
XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
XSSFSheet xssfSheetOne = xssfWorkbook.createSheet();
XSSFSheet xssfSheetTwo = xssfWorkbook.createSheet("two");
try {
fileOutputStream = new FileOutputStream(filePath);
xssfWorkbook.write(fileOutputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
バージョンpoi-3.10.1の使用
比較的に簡単で、多く言いません!