1.读取excel文件
读取.xlsx常见方式有:
1. Workbook wb = new XSSFWorkbook(new FileInputStream(fileName));
2. Workbook wb = WorkbookFactory.create( new File(filename));
读取.xls常见的方式有:
1. Workbook wb = new HSSFWorkbook(new FileInputStream(fileName));
2. Workbook wb = WorkbookFactory.create( new File(filename));
2.新建一个workbook
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet(sheetName);
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
cell.setCellValue(""); //设置单元格内容
cell.setCellStyle(cellStyle); //设置单元格风格
//将上面创建的workbook写出到excel文件,后缀为.xls
FileOutputStream output = null;
try {
output = new FileOutputStream(filename);
wb.write(output);
output.flush();
System.out.println("Successfullt export excel file!");
} catch (Exception e) {
e.printS