网络及建设公司网站,电子商务平台经营者对,贵阳seo网站建设,怎么样做短视频一、Apache POI
1、介绍
Apache POI 是一个处理Miscrosoft Office各种文件格式的开源项目。简单来说就是#xff0c;我们可以使用 POI 在 Java 程序中对Miscrosoft Office各种文件进行读写操作。
一般情况下#xff0c;POI 都是用于操作 Excel 文件。
2、Apache POI 怎么…一、Apache POI
1、介绍
Apache POI 是一个处理Miscrosoft Office各种文件格式的开源项目。简单来说就是我们可以使用 POI 在 Java 程序中对Miscrosoft Office各种文件进行读写操作。
一般情况下POI 都是用于操作 Excel 文件。
2、Apache POI 怎么玩
导依赖
dependencygroupIdorg.apache.poi/groupIdartifactIdpoi/artifactIdversion3.16/version
/dependency
dependencygroupIdorg.apache.poi/groupIdartifactIdpoi-ooxml/artifactIdversion3.16/version
/dependency
将数据写入Excel文件
public class POI {/*** 基于POI向Excel文件写入数据* throws Exception*/public static void write() throws Exception{//在内存中创建一个Excel文件对象XSSFWorkbook excel new XSSFWorkbook();//创建Sheet页XSSFSheet sheet excel.createSheet(islunatic);//在Sheet页中创建行0表示第1行XSSFRow row1 sheet.createRow(0);//创建单元格并在单元格中设置值单元格编号也是从0开始1表示第2个单元格row1.createCell(1).setCellValue(姓名);row1.createCell(2).setCellValue(城市);XSSFRow row2 sheet.createRow(1);row2.createCell(1).setCellValue(hai);row2.createCell(2).setCellValue(北京);XSSFRow row3 sheet.createRow(2);row3.createCell(1).setCellValue(bbiao);row3.createCell(2).setCellValue(上海);FileOutputStream out new FileOutputStream(new File(D:\\islunatic.xlsx));//通过输出流将内存中的Excel文件写入到磁盘上excel.write(out);//释放资源out.flush();out.close();excel.close();}public static void main(String[] args) throws Exception {write();}
}
读取Excel文件数据
public class POI{/*** 基于POI读取Excel文件* throws Exception*/public static void read() throws Exception{FileInputStream in new FileInputStream(new File(D:\\islunatic.xlsx));//通过输入流读取指定的Excel文件XSSFWorkbook excel new XSSFWorkbook(in);//获取Excel文件的第1个Sheet页XSSFSheet sheet excel.getSheetAt(0);//获取Sheet页中的最后一行的行号int lastRowNum sheet.getLastRowNum();for (int i 0; i lastRowNum; i) {//获取Sheet页中的行XSSFRow titleRow sheet.getRow(i);//获取行的第2个单元格XSSFCell cell1 titleRow.getCell(1);//获取单元格中的文本内容String cellValue1 cell1.getStringCellValue();//获取行的第3个单元格XSSFCell cell2 titleRow.getCell(2);//获取单元格中的文本内容String cellValue2 cell2.getStringCellValue();System.out.println(cellValue1 cellValue2);}//关闭资源in.close();excel.close();}public static void main(String[] args) throws Exception {read();}
}二、导出Excel表
学习