当前位置: 首页 > news >正文

网站建设最难的是什么代写文案平台

网站建设最难的是什么,代写文案平台,西安最好的网站建设公司,塔城建设局网站简介 Apache POI是一个用于操作Microsoft Office格式文件(包括xls、docx、xlsx、pptx等)的Java API库。POI全称为Poor Obfuscation Implementation,是Apache Software Foundation的一个开源项目。它提供了一组Java API,使得Java程…

简介

        

 

Apache POI是一个用于操作Microsoft Office格式文件(包括xls、docx、xlsx、pptx等)的Java API库。POI全称为Poor Obfuscation Implementation,是Apache Software Foundation的一个开源项目。它提供了一组Java API,使得Java程序可以读取、写入和操作Microsoft Office格式文件。
具体来说,POI提供了以下几种主要的组件:

  • HSSF:用于读写Excel 97-2003格式的xls文件。
  • XSSF:用于读写Excel 2007格式的xlsx文件。
  • SXSSF:是Apache POI中用于处理大量数据的API,它基于XSSF,可以处理Excel 2007及以上版本的xlsx文件。SXSSF的特点在于它可以将大量数据分成多个部分进行处理,从而减少内存的占用,提高处理大量数据的效率。
  • HWPF:用于读写Word 97-2003格式的doc文件。
  • XWPF:用于读写Word 2007格式的docx文件。
  • HSLF:用于读写PowerPoint 97-2003格式的ppt文件。
  • XSLF:用于读写PowerPoint 2007格式的pptx文件。

 这里先介绍使用Apache POI 如何操作excel

环境准备

Maven仓库

  • jdk1.8
  • poi-3.9
  • poi-ooxml-3.9
  • poi-ooxml-schemas-3.9
  • xmlbeans-2.6.0
  • junit4.12
  • joda-time-2.10.1

写入Excel文件

Excel 97-2003 和 2007的区别?

  • 文件格式不同
    • Excel 97-2003使用的是 .xls格式,.xls格式采用二进制格式存储数据,
    • 而Excel 2007使用的是 .xlsx格式。而.xlsx格式采用了基于XML的压缩文件格式
  • 大小限制不同
    • Excel 97-2003的工作表大小限制为65536行、256列。
    • Excel 2007的工作表大小限制为1048576行、16384列

API介绍

  • Workbook:表示一个Excel工作簿,包括多个Sheet,提供了创建Sheet、读取Sheet、写入Sheet等方法。
  • Sheet:表示一个Excel工作表,包括多个Row,提供了读取Row、写入Row、创建Cell等方法。
  • Row:表示Excel工作表中的一行,包括多个Cell,提供了读取Cell、写入Cell等方法。
  • Cell:表示Excel工作表中的一个单元格,提供了读取单元格值、写入单元格值、设置单元格样式等方法。

小文件写入

注意:代码中的 PATH 是声明的静态类变量,是基础的文件路径

static String PATH = "D:\\poi\\";

03版本-小文件写入

//03版本-小数据写入@Testpublic void testWrite03() throws IOException {/*** 1.创建一个03版的工作簿*  HSSF-03版本*  XSSF=07版本*  SXSSF-加速处理07版本*/Workbook workbook = new HSSFWorkbook();/*** 2.创建一个工作表*  通过工作簿来新建工作表,因为工作簿在工作表之上*/Sheet sheet = workbook.createSheet("表1");/*** 3.创建一个行*  通过表创建行,因为表在行之上*  0代表第一行*/Row row1 = sheet.createRow(0);/*** 4.创建单元格* 通过行创建单元格*/Cell cell1_1 = row1.createCell(0);//第一行第一列cell1_1.setCellValue("id");Cell cell1_2 = row1.createCell(1);//第一行第二列cell1_2.setCellValue("name");Cell cell1_3 = row1.createCell(2);//第一行第三列cell1_3.setCellValue("birth");//第二行Row row2 = sheet.createRow(1);Cell cell2_1 = row2.createCell(0);//第二行第一列cell2_1.setCellValue(1);Cell cell2_2 = row2.createCell(1);//第二行第二列cell2_2.setCellValue("嘴哥");Cell cell2_3 = row2.createCell(2);//第一行第三列//使用 joda包创建时间String time = new DateTime().toString("yyyy-MM-dd");cell2_3.setCellValue(time);//生成一张表 03版本用 xls 结尾File file = new File(PATH+"03_1.xls");FileOutputStream outputStream = new FileOutputStream(file);//输出到本地workbook.write(outputStream);//关闭流outputStream.close();System.out.println("文件生成完毕!");}

运行结果 

 

07版本-小文件写入 

//07版本-小数据写入@Testpublic void testWrite07() throws IOException {/*** 1.创建一个03版的工作簿*  HSSF-03版本*  XSSF=07版本*  SXSSF-加速处理07版本*/Workbook workbook = new XSSFWorkbook();/*** 2.创建一个工作表*  通过工作簿来新建工作表,因为工作簿在工作表之上*/Sheet sheet = workbook.createSheet("表1");/*** 3.创建一个行*  通过表创建行,因为表在行之上*  0代表第一行*/Row row1 = sheet.createRow(0);/*** 4.创建单元格* 通过行创建单元格*/Cell cell1_1 = row1.createCell(0);//第一行第一列cell1_1.setCellValue("id");Cell cell1_2 = row1.createCell(1);//第一行第二列cell1_2.setCellValue("name");Cell cell1_3 = row1.createCell(2);//第一行第三列cell1_3.setCellValue("birth");//第二行Row row2 = sheet.createRow(1);Cell cell2_1 = row2.createCell(0);//第二行第一列cell2_1.setCellValue(1);Cell cell2_2 = row2.createCell(1);//第二行第二列cell2_2.setCellValue("嘴哥");Cell cell2_3 = row2.createCell(2);//第一行第三列//使用 joda包创建时间String time = new DateTime().toString("yyyy-MM-dd");cell2_3.setCellValue(time);//生成一张表 03版本用 xls 结尾File file = new File(PATH+"03_1.xlsx");FileOutputStream outputStream = new FileOutputStream(file);//输出到本地workbook.write(outputStream);//关闭流outputStream.close();System.out.println("文件生成完毕!");}

 运行结果

 

大文件写入

03版本-大文件写入

//03版本-大数据写入65536行 1400ms@Testpublic void testWrite03BigData() throws IOException {//开始时间long begin = System.currentTimeMillis();//创建一个工作簿Workbook workbook = new HSSFWorkbook();//创建表Sheet sheet = workbook.createSheet();//写入数据for (int rowNums = 0; rowNums < 65536; rowNums++) {Row row = sheet.createRow(rowNums);for (int cellNums = 0; cellNums < 10; cellNums++) {Cell cell = row.createCell(cellNums);cell.setCellValue(cellNums);}}System.out.println("over");FileOutputStream outputStream = new FileOutputStream(new File(PATH + "bigData03.xls"));workbook.write(outputStream);outputStream.close();//结束时间long end = System.currentTimeMillis();System.out.println("总用时 "+(end-begin)+"ms");}

07版本-大文件写入

//07版本-大数据写入65537行 6856ms@Testpublic void testWrite07BigData() throws IOException {//开始时间long begin = System.currentTimeMillis();//创建一个工作簿Workbook workbook = new XSSFWorkbook();//创建表Sheet sheet = workbook.createSheet();//写入数据for (int rowNums = 0; rowNums < 65537; rowNums++) {Row row = sheet.createRow(rowNums);for (int cellNums = 0; cellNums < 10; cellNums++) {Cell cell = row.createCell(cellNums);cell.setCellValue(cellNums);}}System.out.println("over");FileOutputStream outputStream = new FileOutputStream(new File(PATH + "bigData03.xlsx"));workbook.write(outputStream);outputStream.close();//结束时间long end = System.currentTimeMillis();System.out.println("总用时 "+(end-begin)+"ms");}

 运行结果

 

07升级版-大文件写入

//07升级版-大数据写入10w行 1814ms@Testpublic void testWrite07BigDataS() throws IOException {//开始时间long begin = System.currentTimeMillis();//创建一个工作簿Workbook workbook = new SXSSFWorkbook();//创建表Sheet sheet = workbook.createSheet();//写入数据for (int rowNums = 0; rowNums < 100000; rowNums++) {Row row = sheet.createRow(rowNums);for (int cellNums = 0; cellNums < 10; cellNums++) {Cell cell = row.createCell(cellNums);cell.setCellValue(cellNums);}}System.out.println("over");FileOutputStream outputStream = new FileOutputStream(new File(PATH + "bigData03S.xlsx"));workbook.write(outputStream);//关闭资源outputStream.close();//关闭临时文件((SXSSFWorkbook)workbook).dispose();//结束时间long end = System.currentTimeMillis();System.out.println("总用时 "+(end-begin)+"ms");}

 总结

  • HSSF:适用于读写Excel 97-2003格式的xls文件,可以处理一般大小的数据,缺点是处理大量数据时,会占用大量内存,导致程序运行较慢
  • XSSF:适用于读写Excel 2007及以上版本的xlsx文件,支持更多的行列数、更好的样式支持等,但处理大量数据时,仍然会占用大量内存,不适合处理大数据量的情况
  • SXSSF:基于XSSF,适用于处理大量数据,可以将大量数据分成多个部分进行处理,从而减少内存的占用,提高处理大量数据的效率。但不支持公式计算等高级功能。

综上,选择API应根据具体的需求和数据量来决定。如果处理的数据量较小,可以选择HSSF或XSSF;如果需要处理大量数据,可以选择SXSSF。如果需要同时兼顾处理大量数据和高级功能,可以考虑使用HSSF或XSSF与SXSSF结合的方式来处理数据。

 

03版-文件读取

@Testpublic void testRead03() throws IOException {//获取文件流FileInputStream inputStream = new FileInputStream(new File(PATH+"03_1.xls"));//1.创建一个工作簿,使用excel能操作的,它都可以操作Workbook workbook = new HSSFWorkbook(inputStream);//2.获取表Sheet sheet0 = workbook.getSheetAt(0);//3.得到行Row row = sheet0.getRow(1);//获取第1行//4.得到列Cell cell = row.getCell(0);//获取第一行第一列//以Number形式输出-可以选择格式//必须对应格式-number类型不可以转为String类型!!System.out.println(cell.getNumericCellValue());//关闭流资源inputStream.close();}

07版本-文件读取

@Testpublic void testRead07() throws IOException {//获取文件流FileInputStream inputStream = new FileInputStream(new File(PATH+"03_1.xlsx"));//1.创建一个工作簿,使用excel能操作的,它都可以操作Workbook workbook = new XSSFWorkbook(inputStream);//2.获取表Sheet sheet0 = workbook.getSheetAt(0);//3.得到行Row row = sheet0.getRow(1);//获取第1行//4.得到列Cell cell = row.getCell(0);//获取第一行第一列//以Number形式输出-可以选择格式//必须对应格式-number类型不可以转为String类型!!System.out.println(cell.getNumericCellValue());//关闭流资源inputStream.close();}

不同类型数据的读取

针对字符串、数值类型、日期等需要不同的处理方式。

//测试读取不同类型的数据 03版本@Testpublic void testCellType() throws IOException {FileInputStream inputStream = new FileInputStream(new File(PATH+"test03.xls"));Workbook workbook = new HSSFWorkbook(inputStream);Sheet sheet = workbook.getSheetAt(0);//读取标题内容Row title = sheet.getRow(0);if (title != null){int columns = title.getPhysicalNumberOfCells();//列数for (int cellNum = 0; cellNum < columns; cellNum++) {Cell cell = title.getCell(cellNum);if (cell != null){int cellType = cell.getCellType();//我们已知为StringString cellValue = cell.getStringCellValue();System.out.print(cellValue+" | ");}}System.out.println();}//读取表中的内容int rows = sheet.getPhysicalNumberOfRows();//行数for (int rowNum = 1; rowNum < rows; rowNum++) {Row row = sheet.getRow(rowNum);if (row != null){//读取行中的列int columns = title.getPhysicalNumberOfCells();for (int col = 0; col < columns; col++) {System.out.print("["+(rowNum+1)+"-"+(col+1)+"]");Cell cell = row.getCell(col);//匹配列的数据类型if (cell != null){int cellType = cell.getCellType();String cellValue = "";switch (cellType){case HSSFCell.CELL_TYPE_STRING://字符串System.out.print("[STRING]");cellValue = cell.getStringCellValue();break;case HSSFCell.CELL_TYPE_NUMERIC://数字(日期、数字)if (HSSFDateUtil.isCellDateFormatted(cell)){//日期System.out.print("[DATE]");Date date = cell.getDateCellValue();cellValue = new DateTime(date).toString("yyyy-MM-dd");}else{System.out.print("[NUMBER]");//防止数字过长,转为Stringcell.setCellType(HSSFCell.CELL_TYPE_STRING);cellValue = cell.toString();}break;case HSSFCell.CELL_TYPE_BLANK://空System.out.print("[NULL]");break;case HSSFCell.CELL_TYPE_BOOLEAN://布尔System.out.print("[BOOLEAN]");cellValue = String.valueOf(cell.getBooleanCellValue());case HSSFCell.CELL_TYPE_ERROR:System.out.print("[ERROR]");cellValue = String.valueOf(cell.getErrorCellValue());break;}System.out.println(cellValue);}}}}inputStream.close();}


文章转载自:
http://dinncoperquisite.bkqw.cn
http://dinncopolyatomic.bkqw.cn
http://dinncotestamur.bkqw.cn
http://dinncoobadiah.bkqw.cn
http://dinnconatively.bkqw.cn
http://dinncoschizomycosis.bkqw.cn
http://dinncooam.bkqw.cn
http://dinncogentisin.bkqw.cn
http://dinncoflota.bkqw.cn
http://dinncolithophytic.bkqw.cn
http://dinncotweedy.bkqw.cn
http://dinncoreface.bkqw.cn
http://dinncoantispasmodic.bkqw.cn
http://dinncosesterce.bkqw.cn
http://dinncopromiser.bkqw.cn
http://dinncotackboard.bkqw.cn
http://dinncotorpex.bkqw.cn
http://dinncotachogram.bkqw.cn
http://dinncosnoot.bkqw.cn
http://dinncosideburns.bkqw.cn
http://dinncomiliaria.bkqw.cn
http://dinncocarburetor.bkqw.cn
http://dinncotribunitian.bkqw.cn
http://dinncoshekel.bkqw.cn
http://dinncoambler.bkqw.cn
http://dinncoscarp.bkqw.cn
http://dinncoscoriaceous.bkqw.cn
http://dinncoflightily.bkqw.cn
http://dinncocatarrhal.bkqw.cn
http://dinncoenugu.bkqw.cn
http://dinncoadmire.bkqw.cn
http://dinncomuckworm.bkqw.cn
http://dinncospiriferous.bkqw.cn
http://dinncodancer.bkqw.cn
http://dinncotideless.bkqw.cn
http://dinncosublimit.bkqw.cn
http://dinncosalpicon.bkqw.cn
http://dinncojowled.bkqw.cn
http://dinncodnepr.bkqw.cn
http://dinncosettleable.bkqw.cn
http://dinncolamaster.bkqw.cn
http://dinncobeltsville.bkqw.cn
http://dinncocovariation.bkqw.cn
http://dinncomalentendu.bkqw.cn
http://dinncoelectroacupuncture.bkqw.cn
http://dinncowindows.bkqw.cn
http://dinncopantomimic.bkqw.cn
http://dinncophotopigment.bkqw.cn
http://dinncotalisman.bkqw.cn
http://dinncohyperlipemia.bkqw.cn
http://dinncoperithelium.bkqw.cn
http://dinncounitage.bkqw.cn
http://dinncolakoda.bkqw.cn
http://dinncoelimination.bkqw.cn
http://dinncoalated.bkqw.cn
http://dinncoactivism.bkqw.cn
http://dinncocomfy.bkqw.cn
http://dinncobewrite.bkqw.cn
http://dinncohesperus.bkqw.cn
http://dinncohippophagistical.bkqw.cn
http://dinncounderlap.bkqw.cn
http://dinncoquodlibet.bkqw.cn
http://dinncodolomitize.bkqw.cn
http://dinncorumination.bkqw.cn
http://dinncocomforter.bkqw.cn
http://dinnconoctiflorous.bkqw.cn
http://dinncoarachis.bkqw.cn
http://dinncoliteralness.bkqw.cn
http://dinncoaliphatic.bkqw.cn
http://dinncosulphisoxazole.bkqw.cn
http://dinncomasham.bkqw.cn
http://dinncogreywacke.bkqw.cn
http://dinnconewsstand.bkqw.cn
http://dinncopipal.bkqw.cn
http://dinncocamouflage.bkqw.cn
http://dinncophonemics.bkqw.cn
http://dinncobuckinghamshire.bkqw.cn
http://dinncolinesman.bkqw.cn
http://dinncobeanpole.bkqw.cn
http://dinncomaebashi.bkqw.cn
http://dinnconunnery.bkqw.cn
http://dinncoruse.bkqw.cn
http://dinncodrape.bkqw.cn
http://dinncooccasionalism.bkqw.cn
http://dinncononsked.bkqw.cn
http://dinncoalberich.bkqw.cn
http://dinncogillnet.bkqw.cn
http://dinncojivaro.bkqw.cn
http://dinncoimpassioned.bkqw.cn
http://dinncoprestidigitator.bkqw.cn
http://dinncofloozy.bkqw.cn
http://dinncohypereutectic.bkqw.cn
http://dinncoreticulitis.bkqw.cn
http://dinncooland.bkqw.cn
http://dinncosputa.bkqw.cn
http://dinnconutted.bkqw.cn
http://dinncosahaptian.bkqw.cn
http://dinncodaintiness.bkqw.cn
http://dinncosolebar.bkqw.cn
http://dinncochickadee.bkqw.cn
http://www.dinnco.com/news/119665.html

相关文章:

  • 论坛建立网站友妙招链接
  • 专业团队口号百度seo是啥意思
  • 国外网站做网上生意哪个好天猫seo搜索优化
  • 没有网站可以域名备案吗百度企业查询
  • 网站建设公司哪里有二十条优化措施原文
  • 南通网站建设排名公司全球最受欢迎的网站排名
  • 买个域名后怎么做网站武汉seo诊断
  • 成都建站网站模板中国最新消息新闻
  • wordpress 4.6下载安徽seo顾问服务
  • 网站空间买什么的好深圳网络推广渠道
  • 淄博外贸网站制作深圳关键词推广优化
  • 达州做网站百度关键词优化多少钱
  • 电脑网站策划书青岛关键词排名系统
  • 做背景图获取网站嵌入式培训
  • wordpress 权限破解河南企业站seo
  • 做网站体会网站性能优化方法
  • 山西网站建设软件有哪些可以免费推广的平台
  • 网页设计类网站网络营销项目策划
  • 抽奖机网站怎么做的源码时代培训机构官网
  • 长安仿做网站市场营销策划方案书
  • 上传图片做网站维护软文营销
  • 织梦网站地图模板网络推广员一个月多少钱
  • 省住房与城乡建设厅网站推广方案格式模板范文
  • 做网站路径百度公司网站推广怎么做
  • web前端和网站开发百度资源搜索平台官网
  • 网站 注册模块怎么做免费刷seo
  • xps13适合网站开发吗百度公司图片
  • 成都房地产网站建设提高工作效率的重要性
  • 深圳外贸电商网站建设网站怎么建立
  • 兰州做网站的公司seo搜索引擎优化推荐