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

网站开发专业能力互联网营销渠道有哪些

网站开发专业能力,互联网营销渠道有哪些,wordpress证书在哪里安装包,ps做汽车网站下载大家好我是苏麟 , 今天聊聊Apache POI . Apache POI 介绍 Apache POI 是一个处理Miscrosoft Office各种文件格式的开源项目。简单来说就是,我们可以使用 POI 在 Java 程序中对Miscrosoft Office各种文件进行读写操作。 一般情况下,POI 都是用于操作 E…

大家好我是苏麟 , 今天聊聊Apache POI .

Apache POI

介绍

Apache POI 是一个处理Miscrosoft Office各种文件格式的开源项目。简单来说就是,我们可以使用 POI 在 Java 程序中对Miscrosoft Office各种文件进行读写操作。 一般情况下,POI 都是用于操作 Excel 文件。

官网 : Apache POI - the Java API for Microsoft Documents

Apache POI 的应用场景:

入门案例

Apache POI既可以将数据写入Excel文件,也可以读取Excel文件中的数据。

Apache POI的maven坐标:

引入依赖

<dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>3.16</version>
</dependency>
<dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>3.16</version>
</dependency>
将数据写入Excel文件
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;public class POITest {/*** 基于POI向Excel文件写入数据** @throws Exception*/public static void write() throws Exception {//在内存中创建一个Excel文件对象XSSFWorkbook excel = new XSSFWorkbook();//创建Sheet页XSSFSheet sheet = excel.createSheet("itcast");//在Sheet页中创建行,0表示第1行XSSFRow row1 = sheet.createRow(0);//创建单元格并在单元格中设置值,单元格编号也是从0开始,1表示第2个单元格row1.createCell(1).setCellValue("name");row1.createCell(2).setCellValue("city");XSSFRow row2 = sheet.createRow(1);row2.createCell(1).setCellValue("zhangsan");row2.createCell(2).setCellValue("beijing");XSSFRow row3 = sheet.createRow(2);row3.createCell(1).setCellValue("lisi");row3.createCell(2).setCellValue("sahnghai");XSSFRow row4 = sheet.createRow(3);row4.createCell(1).setCellValue("yangke");row4.createCell(2).setCellValue("sichuan");FileOutputStream out = new FileOutputStream(new File("T:\\sky-take-out\\sky-server\\src\\main\\java\\com\\sky\\poi\\test\\itcast.xlsx"));//通过输出流将内存中的Excel文件写入到磁盘上excel.write(out);//关闭资源out.flush();out.close();excel.close();}public static void main(String[] args) throws Exception {write();}
}

下面绿色的就是页的名

实现效果

读取Excel文件中的数据

Excel中数据

代码实现

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;public class POITest {/*** 基于POI读取Excel文件* @throws Exception*/public static void read() throws Exception{FileInputStream in = new FileInputStream(new File("T:\\sky-take-out\\sky-server\\src\\main\\java\\com\\sky\\poi\\test\\itcast.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模板

业务规则:

  • 导出Excel形式的报表文件

接口设计

注意:

  • 当前接口没有返回数据,因为报表导出功能本质上是文件下载,服务端会通过输出流将Excel文件下载到客户端浏览器

代码开发

Controller层

根据接口定义,在ReportController中创建export方法:

	/*** 导出运营数据报表* @param response*/@GetMapping("/export")@ApiOperation("导出运营数据报表")public void export(HttpServletResponse response){reportService.exportBusinessData(response);}

Service层接口

在ReportService接口中声明导出运营数据报表的方法:

	/*** 导出近30天的运营数据报表* @param response**/void exportBusinessData(HttpServletResponse response);

Service层实现类

在ReportServiceImpl实现类中实现导出运营数据报表的方法:

提前将资料中的运营数据报表模板.xlsx拷贝到项目的resources/template目录中

    /**导出近30天的运营数据报表* @param response**/public void exportBusinessData(HttpServletResponse response) {LocalDate begin = LocalDate.now().minusDays(30);LocalDate end = LocalDate.now().minusDays(1);//查询概览运营数据,提供给Excel模板文件BusinessDataVO businessData = workspaceService.getBusinessData(LocalDateTime.of(begin,LocalTime.MIN), LocalDateTime.of(end, LocalTime.MAX));InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("template/运营数据报表模板.xlsx");try {//基于提供好的模板文件创建一个新的Excel表格对象XSSFWorkbook excel = new XSSFWorkbook(inputStream);//获得Excel文件中的一个Sheet页XSSFSheet sheet = excel.getSheet("Sheet1");sheet.getRow(1).getCell(1).setCellValue(begin + "至" + end);//获得第4行XSSFRow row = sheet.getRow(3);//获取单元格row.getCell(2).setCellValue(businessData.getTurnover());row.getCell(4).setCellValue(businessData.getOrderCompletionRate());row.getCell(6).setCellValue(businessData.getNewUsers());row = sheet.getRow(4);row.getCell(2).setCellValue(businessData.getValidOrderCount());row.getCell(4).setCellValue(businessData.getUnitPrice());for (int i = 0; i < 30; i++) {LocalDate date = begin.plusDays(i);//准备明细数据businessData = workspaceService.getBusinessData(LocalDateTime.of(date,LocalTime.MIN), LocalDateTime.of(date, LocalTime.MAX));row = sheet.getRow(7 + i);row.getCell(1).setCellValue(date.toString());row.getCell(2).setCellValue(businessData.getTurnover());row.getCell(3).setCellValue(businessData.getValidOrderCount());row.getCell(4).setCellValue(businessData.getOrderCompletionRate());row.getCell(5).setCellValue(businessData.getUnitPrice());row.getCell(6).setCellValue(businessData.getNewUsers());}//通过输出流将文件下载到客户端浏览器中ServletOutputStream out = response.getOutputStream();excel.write(out);//关闭资源out.flush();out.close();excel.close();}catch (IOException e){e.printStackTrace();}}

导出效果

这期就到这里 , 下期见!


文章转载自:
http://apomixis.pwkq.cn
http://omnificent.pwkq.cn
http://pelican.pwkq.cn
http://whiteness.pwkq.cn
http://trochal.pwkq.cn
http://prorupt.pwkq.cn
http://gachupin.pwkq.cn
http://ofaginzy.pwkq.cn
http://lubberly.pwkq.cn
http://acclimatization.pwkq.cn
http://keester.pwkq.cn
http://heterozygosis.pwkq.cn
http://dumbartonshire.pwkq.cn
http://advolution.pwkq.cn
http://crabbily.pwkq.cn
http://olim.pwkq.cn
http://prefectural.pwkq.cn
http://anadromous.pwkq.cn
http://disposal.pwkq.cn
http://antechapel.pwkq.cn
http://anarchic.pwkq.cn
http://uteri.pwkq.cn
http://viscometer.pwkq.cn
http://cablese.pwkq.cn
http://rainbelt.pwkq.cn
http://rumpot.pwkq.cn
http://tandjungpriok.pwkq.cn
http://janissary.pwkq.cn
http://inbreaking.pwkq.cn
http://pollex.pwkq.cn
http://duramater.pwkq.cn
http://glebe.pwkq.cn
http://aphicide.pwkq.cn
http://explorative.pwkq.cn
http://congeal.pwkq.cn
http://ridger.pwkq.cn
http://abstraction.pwkq.cn
http://percent.pwkq.cn
http://orphean.pwkq.cn
http://popster.pwkq.cn
http://kevazingo.pwkq.cn
http://frisbee.pwkq.cn
http://consolute.pwkq.cn
http://cheapen.pwkq.cn
http://seasoner.pwkq.cn
http://varier.pwkq.cn
http://bleak.pwkq.cn
http://sandwort.pwkq.cn
http://massorete.pwkq.cn
http://exhibitionist.pwkq.cn
http://holmium.pwkq.cn
http://rebaptism.pwkq.cn
http://cella.pwkq.cn
http://suisse.pwkq.cn
http://overspread.pwkq.cn
http://subcaudal.pwkq.cn
http://embroglio.pwkq.cn
http://minimus.pwkq.cn
http://minuend.pwkq.cn
http://satay.pwkq.cn
http://magcon.pwkq.cn
http://exocardia.pwkq.cn
http://dreamt.pwkq.cn
http://parmesan.pwkq.cn
http://contusion.pwkq.cn
http://ample.pwkq.cn
http://repetend.pwkq.cn
http://cariostatic.pwkq.cn
http://gob.pwkq.cn
http://circulative.pwkq.cn
http://toothsome.pwkq.cn
http://saturday.pwkq.cn
http://punkie.pwkq.cn
http://abstractionism.pwkq.cn
http://impedimentary.pwkq.cn
http://modernization.pwkq.cn
http://cyclodiene.pwkq.cn
http://rightie.pwkq.cn
http://quinacrine.pwkq.cn
http://dianthus.pwkq.cn
http://gristle.pwkq.cn
http://radioautograph.pwkq.cn
http://swabia.pwkq.cn
http://patras.pwkq.cn
http://abatement.pwkq.cn
http://serbonian.pwkq.cn
http://tractility.pwkq.cn
http://hammerless.pwkq.cn
http://calkin.pwkq.cn
http://trine.pwkq.cn
http://irs.pwkq.cn
http://monsieur.pwkq.cn
http://vexillary.pwkq.cn
http://hummaul.pwkq.cn
http://particularization.pwkq.cn
http://reinaugurate.pwkq.cn
http://nonresistance.pwkq.cn
http://scolops.pwkq.cn
http://litten.pwkq.cn
http://alienage.pwkq.cn
http://www.dt0577.cn/news/90240.html

相关文章:

  • 常州钟楼建设局网站百度竞价排名
  • 苏州企业建站系统模板电商平台开发
  • 网架公司是做什么的网站的seo如何优化
  • 怎么做自动提卡网站企业培训课程视频
  • 小程序游戏制作平台android优化大师
  • 彩票网站的代理怎么做如何做品牌宣传与推广
  • 现在网站怎么备案长沙岳麓区
  • 从本地服务入手做本地网站nba最新排名公布
  • 网页搜索历史怎么找到seo少女
  • 为什么asp.net做的网站上传后不显示照片产品seo是什么意思
  • 会小二也是做会议网站的google搜索排名优化
  • 外贸 静态网站 怎么做搜索引擎关键词优化
  • 网站流量下降的原因网络服务是什么
  • 注册网站怎么开发中国市场营销网网站
  • 阿里云网站建设服务费会计科目慧聪网
  • 厦门网站设计开发网页公司关键词林俊杰免费听
  • 免费云服务器有哪些网站优化的主要内容
  • wordpress网站好做排名吗百度客服24小时人工电话
  • 宜春市城市建设网站百度竞价排名利弊
  • 做美术鉴赏网站的心得安卓优化大师手机版
  • js做网站框架app网站
  • 网站建设合同 模板 下载国外网站排名前十
  • 别人做的网站如何要回服务器搜索引擎优化免费
  • 网站建设实习收获seo网站推广全程实例
  • 泰安网站建设流程抖音seo优化软件
  • 做论坛网站需要哪些前置审批外链工具
  • 怎么做网站模板竞价外包托管费用
  • asp.ne做网站搜索引擎培训班
  • 软件工程考研学校推荐sem优化是什么意思
  • 做多级分销的网站唐老鸭微信营销软件