POI学习笔记
poi概述:
Apache POI 是 Apache 软件基金会的开放源码函式库,POI 提供 API 给 Java 程序对Microsoft Office 格式
档案读和写的功能。
poi特点:
1. 效率高
2. 支持公式,宏,一些企业应用上会非常实用
3. 能够修饰单元格属性
4. 支持字体、数字、日期操作
5. API 丰富,支持多种模式的读写
6. 支持大数量大文件的读写操作
poi导入导出excle
1. 导入poi依赖jar
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
2.poi导出
1.poi导出excel文件
public class POIExportTest {
public static void main(String[] args) throws IOException {
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("第一张表");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("编号");
workbook.write(new FileOutputStream(new File("E:\\Java\\3_Framework\\ideaCode\\poi\\src\\main\\webapp\\第一张表.xls")));
}
}
2.poi调整样式导出excel文件
public class POIExportTest {
public static void main(String[] args) throws IOException {
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("第一张表");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue(new Date());
sheet.setColumnWidth(0,8000);
Font font = workbook.createFont();
font.setColor(Font.COLOR_RED);
DataFormat dataFormat = workbook.createDataFormat();
short format = dataFormat.getFormat("yyyy年MM月dd日");
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setAlignment(HorizontalAlignment.CENTER);