poi读取excel模板,并填充数据

article/2025/10/21 3:50:50

一、POI介绍

        Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能。

基本功能:

HSSF - 提供读写Microsoft Excel格式档案的功能。
XSSF - 提供读写Microsoft Excel OOXML格式档案的功能。
HWPF - 提供读写Microsoft Word格式档案的功能。
HSLF - 提供读写Microsoft PowerPoint格式档案的功能。
HDGF - 提供读写Microsoft Visio格式档案的功能。

下载地址:

1、Apache官网:https://poi.apache.org/download.html
2、https://archive.apache.org/dist/poi/release/bin/


二、功能详解

        首先,在项目内部有一个excel表格模板,本项目后缀名使用的是.xlsx,在WebRoot目录下新建一个文件夹formmb,存放这个表格模板,此表格模板内无数据,但有一些相应的列名作为解释,目的就是读取这个模板,然后把从数据库取出的数据填充到相应的表格。
        读取表格模板后,有两种方式填充数据
一种是,需要填充数据的单元格固定,有具体的坐标;
另一种是,需要填充的单元格以行的形式,根据数据的条数逐条增行.

解释:

在表格中的sheet页数,从0开始,即第一个sheet页为0;
行数和列数也是从0开始
比如:(1.2.1) 表示:第二个sheet页第三行第二列


三、代码演示:

1、准备工作

前提准备:先把表格模板放在新建的文件下
如图:
在这里插入图片描述
表格中有种方式需要读取并填充数据,这里展示两种样式:
1、固定坐标填充数据
在这里插入图片描述

2、以行形式填充
在这里插入图片描述

2、具体代码

       项目采用ssm框架,因此这里有控制器和mapper文件,但是模式可能传统的模式不太一样,比如传参等,大体上还是一致的,废话不多说,看代码

ForWardFormsController.java

package com.sinosoft.controller.business.infodisclosure;import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;import org.apache.log4j.Logger;
import org.apache.poi.hssf.util.HSSFColor;
import org.springframework.stereotype.Repository;import com.sinosoft.controller.base.BaseController;
import com.sinosoft.entity.Page;
import com.sinosoft.service.business.infodisclosure.ForWardFormsService;
import com.sinosoft.utils.PageData;
import com.sinosoft.utils.WriteExcelUtil;import net.sf.json.JSONObject;@Repository(value="forWardFormsController")
public class ForWardFormsController implements BaseController {protected Logger logger = Logger.getLogger(this.getClass());@Resource(name = "forWardFormsService")private ForWardFormsService forwardFormsService;@Overridepublic String dispanse(String funcId, Page pageReq, HttpServletRequest request) {String returnStr = "";if("exchangeBuyBackQuery".equals(funcId)){					//读取管理人报告信息excel模板returnStr = exchangeBuyBackQuery(pageReq,request);}return returnStr;}/*** 读取管理人报告信息excel模板* @param pageReq* @param request* @return*/private String exchangeBuyBackQuery(Page pageReq, HttpServletRequest request) {// 存放结果集List<List<Map<String, String>>> queryValue = new ArrayList<List<Map<String, String>>>();// 存放sheet页List<String> sheetList = new ArrayList<String>();// 存放开始行数List<String> rowList = new ArrayList<String>();List<Map<String, String>> fs = null;List<Short> colors = new ArrayList<Short>();PageData pd_result = new PageData();PageData pd = new PageData();pd = new PageData(request);pageReq.setPd(pd);Map<String, String> resultMap = new HashMap<String, String>();try {//1计划资产净值和收益情况fs = forwardFormsService.SheetOnePage(pageReq);if(fs.size() != 0 ){queryValue.add(fs);sheetList.add("0");/*真对坐标固定的sheet,将开始行写成"tuoguan-sheetone",在EXCEL导出方法内会解析开始行,若其中包含“tuoguan”,则进入key值与坐标一一对应的方法,“sheetone”用于到配置文件获取具体坐标*/rowList.add("tuoguan-sheetone");colors.add( HSSFColor.WHITE.index);}//2计划投资资产分布情况fs=null;fs = forwardFormsService.SheetTwoPage(pageReq);if(fs.size() != 0 ){queryValue.add(fs);sheetList.add("1");/*真对坐标固定的sheet,将开始行写成"tuoguan-sheettwo",在EXCEL导出方法内会解析开始行,若其中包含“tuoguan”,则进入key值与坐标一一对应的方法,“sheettwo”用于到配置文件获取具体坐标*/rowList.add("tuoguan-sheettwo");colors.add( HSSFColor.WHITE.index);}//3计划管理费用fs=null;fs = forwardFormsService.SheetThreePage(pageReq);if(fs.size() != 0 ){queryValue.add(fs);sheetList.add("2");/*真对坐标固定的sheet,将开始行写成"tuoguan-sheettwo",在EXCEL导出方法内会解析开始行,若其中包含“tuoguan”,则进入key值与坐标一一对应的方法,“sheettwo”用于到配置文件获取具体坐标*/rowList.add("tuoguan-sheetthree");colors.add( HSSFColor.WHITE.index);}//4计划管理费用明细fs=null;fs = forwardFormsService.SheetFourPage(pageReq);if(fs.size() != 0 ){queryValue.add(fs);sheetList.add("3");/*真对坐标固定的sheet,将开始行写成"tuoguan-sheettwo",在EXCEL导出方法内会解析开始行,若其中包含“tuoguan”,则进入key值与坐标一一对应的方法,“sheettwo”用于到配置文件获取具体坐标*/rowList.add("tuoguan-sheetfour");colors.add( HSSFColor.WHITE.index);}//5资产负债表fs=null;fs = forwardFormsService.SheetFivePage(pageReq);if(fs.size() != 0 ){queryValue.add(fs);sheetList.add("4");/*真对坐标固定的sheet,将开始行写成"tuoguan-sheettwo",在EXCEL导出方法内会解析开始行,若其中包含“tuoguan”,则进入key值与坐标一一对应的方法,“sheettwo”用于到配置文件获取具体坐标*/rowList.add("tuoguan-sheetfive");colors.add( HSSFColor.WHITE.index);}//6净资产变动表fs=null;fs = forwardFormsService.SheetSixPage(pageReq);if(fs.size() != 0 ){queryValue.add(fs);sheetList.add("5");/*真对坐标固定的sheet,将开始行写成"tuoguan-sheettwo",在EXCEL导出方法内会解析开始行,若其中包含“tuoguan”,则进入key值与坐标一一对应的方法,“sheettwo”用于到配置文件获取具体坐标*/rowList.add("tuoguan-sheetsix");colors.add( HSSFColor.WHITE.index);}//7养老金产品分布fs=null;//每月成本统计-展示计提当月列 fs = forwardFormsService.SheetSevenPage(pageReq);if(fs.size() != 0){queryValue.add(fs);sheetList.add("6");rowList.add("2");colors.add( HSSFColor.WHITE.index);}String[] sheet = new String[sheetList.size()];sheetList.toArray(sheet);String[] row = new String[rowList.size()];rowList.toArray(row);Date date = new Date();SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");String time = sdf.format(date);String modeName = pd.getString("modeName");   //模板文件名String downLoadName = pd.getString("filename");  //填完数据后生成的文件的文件名String fileDownloadName = downLoadName + time+ ".xlsx";/*excel导出方法* modeName:模板名称。* sheet:sheet页的序号* row:写入的开始行数(类似主表的位置已经确定的,需要传入)* queryValue:所有数值的集合* fileDownloadName:下载至文件服务器的文件的名称* * */if(queryValue.size()==0){//文件下载路径//String fileDownloadPath=resultMap.get("fileDownloadPath");pd_result.put("err_code", "");pd_result.put("err_message", "");pd_result.put("fileDownloadPath", "");}else{resultMap=WriteExcelUtil.GetExcelAddredds(request, modeName, sheet, row, queryValue,fileDownloadName,colors);//文件下载路径String fileDownloadPath=resultMap.get("fileDownloadPath");pd_result.put("err_code", "");pd_result.put("err_message", "");pd_result.put("fileDownloadPath", fileDownloadPath);}}catch(Exception e) {e.printStackTrace();logger.error(e);pd_result.put("err_code", "error");pd_result.put("err_message", e.getCause().getMessage());pd_result.put("totalCount", 0);pd_result.put("queryValue", null);}return JSONObject.fromObject(pd_result).toString();}}

通过WriteExcelUtil.GetExcelAddredds(request, modeName, sheet, row, queryValue,fileDownloadName,colors);读取模板

需要在config.properties中配置模板中的固定坐标

#文件生成地址
downLoadFormPath=D:/data/form/#1计划资产净值和收益情况   固定坐标
sheetonekey=A3,B3,C3,D3,E3,F3
sheetonecoord=0.2.0,0.2.1,0.2.2,0.2.3,0.2.4,0.2.5#2计划投资资产分布情况
sheettwokey=C2,D2,E2,C3,D3,C4,D4,C5,D5,C6,D6,C7,D7,C8,D8,C9,D9,C10,D10,C11,D11,C12,D12,C13,D13,C14,D14,C15,D15,C16,D16,C17,D17,C18,D18,C19,D19,C20,D20,C21,D21,C22,D22,C23,D23,C24,D24,C25,D25,C26,D26,C27,D27,C28,D28,C29,D29,C30,D30,C31,D31,C32,D32,C33,D33,C34,D34,C35,D35,E11,E27,E34
sheettwocoord=1.1.2,1.1.3,1.1.4,1.2.2,1.2.3,1.3.2,1.3.3,1.4.2,1.4.3,1.5.2,1.5.3,1.6.2,1.6.3,1.7.2,1.7.3,1.8.2,1.8.3,1.9.2,1.9.3,1.10.2,1.10.3,1.11.2,1.11.3,1.12.2,1.12.3,1.13.2,1.13.3,1.14.2,1.14.3,1.15.2,1.15.3,1.16.2,1.16.3,1.17.2,1.17.3,1.18.2,1.18.3,1.19.2,1.19.3,1.20.2,1.20.3,1.21.2,1.21.3,1.22.2,1.22.3,1.23.2,1.23.3,1.24.2,1.24.3,1.25.2,1.25.3,1.26.2,1.26.3,1.27.2,1.27.3,1.28.2,1.28.3,1.29.2,1.29.3,1.30.2,1.30.3,1.31.2,1.31.3,1.32.2,1.32.3,1.33.2,1.33.3,1.34.2,1.34.3,1.10.4,1.26.4,1.33.4#3计划管理费用
sheetthreekey=B2,C2,B3,C3,B4,C4
sheetthreecoord=2.1.1,2.1.2,2.2.1,2.2.2,2.3.1,2.3.2#4计划管理费用明细
sheetfourkey=B1,B4,B5,B6,B7,B8,B9,B10,B11,B12,C5,C6,C7
sheetfourcoord=3.0.1,3.3.1,3.4.1,3.5.1,3.6.1,3.7.1,3.8.1,3.9.1,3.10.1,3.11.1,3.4.2,3.5.2,3.6.2#5资产负债表
sheetfivekey=B5,B6,B7,B8,B9,B10,B11,B12,B13,B14,B15,B16,B17,B18,B19,B20,B21,B22,B23,B24,B25,B26,C5,C6,C7,C8,C9,C10,C11,C12,C13,C14,C15,C16,C17,C18,C19,C20,C21,C22,C23,C24,C25,C26,E5,E6,E7,E8,E9,E10,E11,E12,E13,E14,E15,E16,E17,E18,E19,E21,E22,E23,E24,E26,F5,F6,F7,F8,F9,F10,F11,F12,F13,F14,F15,F16,F17,F18,F19,F21,F22,F23,F24,F26
sheetfivecoord=4.4.1,4.5.1,4.6.1,4.7.1,4.8.1,4.9.1,4.10.1,4.11.1,4.12.1,4.13.1,4.14.1,4.15.1,4.16.1,4.17.1,4.18.1,4.19.1,4.20.1,4.21.1,4.22.1,4.23.1,4.24.1,4.25.1,4.4.2,4.5.2,4.6.2,4.7.2,4.8.2,4.9.2,4.10.2,4.11.2,4.12.2,4.13.2,4.14.2,4.15.2,4.16.2,4.17.2,4.18.2,4.19.2,4.20.2,4.21.2,4.22.2,4.23.2,4.24.2,4.25.2,4.4.4,4.5.4,4.6.4,4.7.4,4.8.4,4.9.4,4.10.4,4.11.4,4.12.4,4.13.4,4.14.4,4.15.4,4.16.4,4.17.4,4.18.4,4.20.4,4.21.4,4.22.4,4.23.4,4.25.4,4.4.5,4.5.5,4.6.5,4.7.5,4.8.5,4.9.5,4.10.5,4.11.5,4.12.5,4.13.5,4.14.5,4.15.5,4.16.5,4.17.5,4.18.5,4.20.5,4.21.5,4.22.5,4.23.5,4.25.5#6净资产变动表
sheetsixkey=B2,B4,B5,B6,B7,B8,B9,B10,B11,B12,B13,B14,B15,B16,B17,B18,B19,B20,B21,C4,C5,C6,C7,C8,C9,C10,C11,C12,C13,C14,C15,C16,C17,C18,C19,C20,C21
sheetsixcoord=5.1.1,5.3.1,5.4.1,5.5.1,5.6.1,5.7.1,5.8.1,5.9.1,5.10.1,5.11.1,5.12.1,5.13.1,5.14.1,5.15.1,5.16.1,5.17.1,5.18.1,5.19.1,5.20.1,5.3.2,5.4.2,5.5.2,5.6.2,5.7.2,5.8.2,5.9.2,5.10.2,5.11.2,5.12.2,5.13.2,5.14.2,5.15.2,5.16.2,5.17.2,5.18.2,5.19.2,5.20.2

WriteExcelUtil.java

package com.sinosoft.utils;import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;import javax.servlet.http.HttpServletRequest;import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
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;public class WriteExcelUtil {private static Logger logger = Logger.getLogger(WriteExcelUtil.class);/*** EXCEL导出方法:* 1、将查询结果集的key值替换为坐标* 2、使用XSSFWorkbook读取模板EXCEL* 3、使用SXSSFWorkbook将模板EXCEL和查询结果集整体写入到一个新的EXCEL,并生成流* 4、将流写入文件服务器,并返回生成EXCEL的地址名称。* * 注:由于XSSFWorkbook在写入大量数据的EXCEL时会占用大量内存甚至造成内存溢出,所以需要选用SXSSFWorkbook写EXCEL*/public static HashMap<String,String> GetExcelAddredds(HttpServletRequest request, String modeName,String sheet[], String[] row, List<List<Map<String, String>>> queryValue,String fileDownloadName,List<Short> colors){//获取模版路径String modelPath = request.getSession().getServletContext().getRealPath("/formmb")+ File.separator + modeName;logger.info(modeName + ":" + modelPath);//下载文件的名称String[] ExcelAddredds = new String[queryValue.size()];List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();Properties getProperties = PropertyUitls.getProperties("config.properties");String path =getProperties.getProperty("downLoadFormPath");//将查询结果集的key值替换为坐标for(int i = 0 ; i < queryValue.size() ; i ++){//定义集合,需要转换Map<String, Object> valuesTemp = new HashMap<String, Object>();String Addredds ="";//固定坐标的sheet页的if(row[i].indexOf("tuoguan")!=-1){String sheetN = row[i].substring(8);//key值String key =getProperties.getProperty(sheetN+"key");//坐标值String coord =getProperties.getProperty(sheetN+"coord");String[] a =key.split(",");String[] b =coord.split(",");System.out.println(queryValue.get(i).get(0));//将查询结果集中的key替换为坐标coordMap<String, String> result1 = (Map<String, String>) replaceKeys2( (Map<String, String>) queryValue.get(i).get(0), a, b);valuesTemp = mapValuesZB(result1,sheet[i],row[i]);Addredds = coord;}else{valuesTemp = mapValues(queryValue.get(i),sheet[i],row[i]);Addredds = getAddredds(queryValue.get(i), sheet[i], row[i]);}ExcelAddredds[i] = Addredds;values.add(valuesTemp);       	}return downloadFile(values,ExcelAddredds,row,modelPath, fileDownloadName,path,colors);}/*** 获取具体坐标(通用方法)* @param List<Map<String, String>> queryeResult* @return*/	public static String getAddredds(List<Map<String, String>> queryeResult,String sheet,String startRow){//定义地址StringBuffer addres = new StringBuffer();//循环存入全部的坐标for (int i = 0 ; i < queryeResult.size() ; i ++){//获取第一个map的key值,列Map<String, String> mapTemp = queryeResult.get(i);//存放到一个数组中,得到需要写入的列String [] cols = new String[mapTemp.size()];int colIndex = 0;for (String key : mapTemp.keySet()) {cols[colIndex++] = key;}for (int j = 0 ; j < cols.length ; j ++){//存入开始sheeet页addres.append(sheet);addres.append(".");//行坐标自动递增addres.append(Integer.parseInt(startRow)+i);addres.append(".");//列坐标按查询字段结束数字取值Pattern p = Pattern.compile("[^0-9]"); Matcher m = p.matcher(cols[j]);addres.append(m.replaceAll(""));if(j < cols.length-1){addres.append(",");}}if(i < queryeResult.size()-1){addres.append(",");}}return addres.toString();}/*** 替换map的key值* 以实际需要的格式返回map数据,格式为{"0.0.0=value,..."}* @param listMap	List<Map<String, String>>* @param sheet		写入的sheet页* @param startRow	开始写入的行数* @return*/public static Map<String, Object> mapValues(List<Map<String, String>> listMap,String sheet,String startRow){// 替换map的key值if(listMap.get(0) == null || listMap.get(0).size() == 0){return null;}Map<String, Object> map = new HashMap<String, Object>();String[] address = getAddreddsArray(listMap, sheet, startRow);int index = 0;for(int i = 0 ; i < listMap.size() ; i ++){Map<String, String> mapTemp = listMap.get(i);for (String key : mapTemp.keySet()) {map.put(address[index++], mapTemp.get(key));}}return map;}/*** 获取坐标 传入的 List<Map<String, String>>* @param queryeResult		List<Map<String, String>>		list* @param sheet				String							写入sheet页* @param startRow			String							开始行数* @return*/public static String[] getAddreddsArray(List<Map<String, String>> queryeResult,String sheet,String startRow){//定义长度----------针对与报表导出,数据  总行数*总列数 < 200万	使用int类型(最大返回数据单元999999999)int length = 0;//获取长度----------返回的map可能是长短不一的for(int i = 0 ; i < queryeResult.size() ; i ++){if(queryeResult.get(i).size() == 0 || queryeResult.get(i) == null){String[] s = {""};return s;}length += queryeResult.get(i).size();}//定义地址String[] address = new String[length];int index = 0;//循环存入全部的坐标for (int i = 0 ; i < queryeResult.size() ; i ++){//获取第i个map的key值,列Map<String, String> mapTemp = queryeResult.get(i);//获取需要写入的列,存放到一个数组中String [] cols = new String[mapTemp.size()];int colIndex = 0;for (String key : mapTemp.keySet()) {cols[colIndex++] = key;}for (int j = 0 ; j < cols.length ; j ++){String str = "";//存入开始sheeet页str += sheet + ".";//行坐标自动递增str += Integer.parseInt(startRow)+i+"" + "." ;//列坐标按查询字段结束数字取值Pattern p = Pattern.compile("[^0-9]"); Matcher m = p.matcher(cols[j]);str += m.replaceAll("");address[index++] = str;}}return address;}/*** EXCEL导入文件服务器* @param values		结果集* @param execlPoint	写入坐标* @param row		开始行* @param modelFile		模板* @param fileDownloadName		生成文件名* @param path		文件服务器路径* @return*/	private static HashMap<String,String> downloadFile(List<Map<String, Object>> values, String[] execlPoint,String[] row,String modelFile,String fileDownloadName,  String path,List<Short> colors) {// 下载报表BufferedInputStream bis = null;BufferedOutputStream bos = null;HashMap<String,String> resultMap =new HashMap<String,String>();try {//EXCEL写入方法,生成流ByteArrayOutputStream os = writeDataToExecl(modelFile, execlPoint, row, values, colors, fileDownloadName);byte[] content = os.toByteArray();InputStream is = new ByteArrayInputStream(content);String fileDownloadPath = path+fileDownloadName;File f = new File(fileDownloadPath);resultMap.put("fileDownloadPath", fileDownloadPath);FileOutputStream down = new FileOutputStream(f);bis = new BufferedInputStream(is);bos = new BufferedOutputStream(down);byte[] buff = new byte[2048];int bytesRead;while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {bos.write(buff, 0, bytesRead);}} catch (Exception e) {e.printStackTrace();logger.error(e);} finally {if (bis != null) {try {bis.close();} catch (IOException e) {e.printStackTrace();}}if (bos != null) {try {bos.close();} catch (IOException e) {e.printStackTrace();}}}return resultMap;}/*** 读取EXCEL模板并写入数据* @param modelFile		模板excel名称* @param execlPoint	写入坐标* @param values		写入值* @return*/public static ByteArrayOutputStream writeDataToExecl(String modelFile, String[] execlPoint, String[] row, List<Map<String, Object>> values,List<Short> colors, String fileDownloadName) {ByteArrayOutputStream os = null;FileInputStream input = null;try {os = new ByteArrayOutputStream();logger.info(modelFile);input = new FileInputStream(new File(modelFile));XSSFWorkbook workBook = new XSSFWorkbook(new BufferedInputStream(input));SXSSFWorkbook SworkBook = new SXSSFWorkbook(100);for(int i = 0 ; i < values.size() ; i ++){//如果没有数据,那么不执行写的操作if(values.get(i).size()==0 || values.get(i) == null){continue;}String[] ss = execlPoint[i].split(",");//获取结束的列String endCell = getEndCell(values.get(i));//写EXCELShort color=null;if(colors.size()>i){color =colors.get(i);}workBook = SwriteWorkBook(SworkBook,workBook,ss, values.get(i),endCell, row[i],color);}workBook.write(os);os.flush();} catch (Exception e) {logger.info(e);e.printStackTrace();}finally {try {if(os != null){os.close();}} catch (IOException e) {logger.info(e);e.printStackTrace();}try {if(input != null){input.close();}} catch (IOException e) {logger.info(e);e.printStackTrace();}}return os;  }/*** 写入EXCEL* @param workBook  XSSFWorkbook  一个工作薄* @param ss		String[]  绝对坐标* @param values	Map<String, Object>  与绝对值对应的map集合* @return* @throws IOException */public static XSSFWorkbook SwriteWorkBook(SXSSFWorkbook SworkBook,XSSFWorkbook workBook,String[] ss,Map<String, Object> values,String endCell,String row,Short color) throws IOException {// 设置公共单元格样式,包括单元格的四周框线、单元格格式,背景色if (color == null) {color = 0;}// 一次性将统一创建样式相对于每个单元格分别创建样式,可提高写入效率Map<String, CellStyle> styleMap = new HashMap<String, CellStyle>();CellStyle styleSL = NMCellStyle(workBook, color);for (int i = 0; i < ss.length; i++) {String[] sss = ss[i].split("\\.");/** 思路: 1、判断该值(即坐标sss)所在的sheet模板是否已经写入SworkBook 2、* 若没有写入sheet模板,将sheet模板写入SworkBook(包括样式),并将该值写入对应坐标* 3、若已经读取sheet页模板,则判断是否已经写入该值所在的行 3.1、若该行已经存在,则插入数值 3.2、若该行不存在,则生成该行,并插入数据* */XSSFSheet sheetMB = workBook.getSheetAt(Integer.parseInt(sss[0]));String sheetName = sheetMB.getSheetName();int lastRows = sheetMB.getLastRowNum();
//            SXSSFSheet sheetS = (SXSSFSheet) SworkBook.getSheet(sheetName);XSSFSheet sheetS1 = (XSSFSheet) workBook.getSheet(sheetName);// sheet页已经存在,模板已经读取,则根据坐标写入数据XSSFRow
//        	SXSSFRow RowS = (SXSSFRow) sheetS.getRow(Integer.parseInt(sss[1]));
//        	SXSSFCell cellS = (SXSSFCell) RowS.getCell(Integer.parseInt(sss[2]));XSSFRow RowS = (XSSFRow) sheetS1.getRow(Integer.parseInt(sss[1]));if (RowS == null) {RowS = (XSSFRow) sheetS1.createRow(Integer.parseInt(sss[1]));int lastCell = Integer.parseInt(endCell);for (int k = 0; k < lastCell + 1; k++) {XSSFCell cellS = (XSSFCell) RowS.getCell(k);if (cellS == null) {cellS = (XSSFCell) RowS.createCell(k);}String value = null;if (k == Integer.parseInt(sss[2])) {if (values.get(ss[i]) != null) {value = values.get(ss[i]).toString();}}cellS = setCell(workBook, cellS, RowS, value, styleSL);}} else {XSSFCell cellS = (XSSFCell) RowS.getCell(Integer.parseInt(sss[2]));if (cellS == null) {cellS = (XSSFCell) RowS.createCell(Integer.parseInt(sss[2]));}String value = null;if (values.get(ss[i]) != null) {value = values.get(ss[i]).toString();}cellS = setCell(workBook, cellS, RowS, value, styleSL);}}return workBook;}//设置cell的值和样式public static XSSFCell setCell(XSSFWorkbook SworkBook,XSSFCell cellS,XSSFRow RowS ,String value,CellStyle styleSL ){//给单元格赋值if (value == null) {cellS.setCellValue("-");// 给单元格赋值cellS.setCellStyle(styleSL);} else {  	cellS.setCellValue(value+"");// 给单元格赋String值
//    		cellS.setCellStyle(styleSL);}return cellS;}//设置cell的值和样式public static SXSSFCell setCell1(SXSSFWorkbook SworkBook,SXSSFCell cellS,SXSSFRow RowS ,String value,Map<String,CellStyle> styleMap ){//给单元格赋值if (value == null) {cellS.setCellValue("-");// 给单元格赋值cellS.setCellStyle(styleMap.get("0"));} else {String val="";cellS.setCellValue(value+"");// 给单元格赋String值cellS.setCellStyle(styleMap.get("0"));}return cellS;}/*** 获取结束列* @param values* @return*/private static String getEndCell(Map<String, Object> values) {Integer endCell = 0;for (String key : values.keySet()) {String[] keys = key.split("\\.");if(endCell < Integer.parseInt(keys[2])){endCell = Integer.parseInt(keys[2]);}}return endCell.toString();}/** 用于处理坐标明确的sheet页,* 将查询结果集的key值与坐标进行替换* */public static Map<String, Object> mapValuesZB(Map<String, String> listMap,String sheet,String startRow){if(listMap == null || listMap.size() == 0){return null;}Map<String, Object> map = new HashMap<String, Object>();for(String key : listMap.keySet()){map.put(key, listMap.get(key));}return map;}public static Map<String, String> replaceKeys2(Map<String, String> map,String[] a, String[] b) {Map<String,String> result = new HashMap<String,String>();for (String key : map.keySet()) {System.out.println("key= "+ key + " and value= " + map.get(key));for (int i = 0 ; i< a.length;i++){if (key.equals(a[i])){result.put(b[i],map.get(key));}}}return result;}//设置通用Cell样式public static CellStyle NMCellStyle(XSSFWorkbook workBook,short color){CellStyle style =  workBook.createCellStyle();/*if(color!=0&&color!=HSSFColor.WHITE.index){style.setFillPattern(CellStyle.SOLID_FOREGROUND);style.setFillForegroundColor(color);}*/style.setBorderBottom(CellStyle.BORDER_THIN);style.setBorderLeft(CellStyle.BORDER_THIN);style.setBorderRight(CellStyle.BORDER_THIN);style.setBorderTop(CellStyle.BORDER_THIN);Font sfont =  workBook.createFont();//单元格字体//常规字符类型的Short high = 14;sfont.setFontHeightInPoints(high);//字体大小sfont.setFontName("宋体");//字体类型style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//水平居中style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中style.setFont(sfont);return style;}}

ForWardFormsService.java

package com.sinosoft.service.business.infodisclosure;import java.util.List;
import java.util.Map;import javax.annotation.Resource;import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;import com.sinosoft.dao.DaoSupport;
import com.sinosoft.entity.Page;@Service("forWardFormsService")
public class ForWardFormsService {protected static Logger logger = Logger.getLogger(ForWardFormsService.class);@Resource(name = "daoSupport")private DaoSupport dao;/** description:1计划资产净值和收益情况* author: Penghui Su* time: 2018/11/29 09:13:00* forWardFormsMapper*/public List<Map<String, String>> SheetOnePage(Page page)throws Exception{return (List<Map<String, String>>) dao.findForList("noticeGenerateMapper.SheetOne", page);}/** description:2计划投资资产分布情况* author: Penghui Su* time: 2018/11/29 09:13:00* forWardFormsMapper*/public List<Map<String, String>> SheetTwoPage(Page page)throws Exception{return (List<Map<String, String>>) dao.findForList("noticeGenerateMapper.SheetTwo", page);}/** description:3计划管理费用* author: Penghui Su* time: 2018/11/29 09:13:00* forWardFormsMapper*/public List<Map<String, String>> SheetThreePage(Page page)throws Exception{return (List<Map<String, String>>) dao.findForList("noticeGenerateMapper.SheetThree", page);}/** description:4计划管理费用明细* author: Penghui Su* time: 2018/11/29 09:13:00* forWardFormsMapper*/public List<Map<String, String>> SheetFourPage(Page page)throws Exception{return (List<Map<String, String>>) dao.findForList("noticeGenerateMapper.SheetFour", page);}/** description:5资产负债表* author: Penghui Su* time: 2018/11/29 09:13:00* forWardFormsMapper*/public List<Map<String, String>> SheetFivePage(Page page)throws Exception{return (List<Map<String, String>>) dao.findForList("noticeGenerateMapper.SheetFive", page);}/** description:6净资产变动表* author: Penghui Su* time: 2018/11/29 09:13:00* forWardFormsMapper*/public List<Map<String, String>> SheetSixPage(Page page)throws Exception{return (List<Map<String, String>>) dao.findForList("noticeGenerateMapper.SheetSix", page);}/** description:7养老金产品分布* author: Penghui Su* time: 2018/11/29 09:13:00* forWardFormsMapper*/public List<Map<String, String>> SheetSevenPage(Page page)throws Exception{return (List<Map<String, String>>) dao.findForList("noticeGenerateMapper.SheetSeven", page);}}

NoticeGenerateMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="noticeGenerateMapper"><!-- 查询管理人--><resultMap id="psOrganInfoResultMap" type="com.sinosoft.utils.PageData"><result column="mngType" property="mngType"/><result column="mgName" property="mngName"/><result column="mngCode" property="mngCode"/></resultMap><!-- 计划建立:分支机构信息列表查询--><select id="listPageShowMngName" parameterType="pd" resultType="com.sinosoft.utils.PageData" resultMap="psOrganInfoResultMap" statementType="PREPARED">SELECT obc.CUSTODIANNAME || obi.IVSTMNGNAME as mgName,obm.mngcode,getcodename('ManagerType',obm.mngtype)mngtypeFROM OP_BP_ManagerLink obm left join OP_B_IvstManager obion obm.mngcode = obi.IVSTMNGCODE left join OP_B_Custodian obc on obm.mngcode = obc.custodiancodeWHERE obm.plancode='00000000000000000293' and obm.mngtype in (02,04)</select><!--1计划资产净值和收益情况  --><resultMap id="sheetOneResultMap" type="com.sinosoft.utils.PageData"><result column="A3" property="A3"/><result column="B3" property="B3"/><result column="C3" property="C3"/><result column="D3" property="D3"/><result column="E3" property="E3"/><result column="F3" property="F3"/></resultMap><select id="SheetOne" parameterType="pd" resultType="com.sinosoft.utils.PageData" resultMap="sheetOneResultMap" statementType="PREPARED">SELECTcase when (to_char(opc.BEFOREMONEY,'fm9999990.0099'))is null then '-'else  to_char(opc.BEFOREMONEY,'fm9999990.0099') end A3,case when (to_char(opc.selloutamount,'fm9999990.0099'))is null then '-'else  to_char(opc.selloutamount,'fm9999990.0099') end B3,case when (to_char(opc.aftermoney,'fm9999990.0099'))is null then '-'else  to_char(opc.aftermoney,'fm9999990.0099') end C3,case when (to_char(opc.payredeemmoney,'fm9999990.0099'))is null then '-'else  to_char(opc.payredeemmoney,'fm9999990.0099') end D3,case when (to_char(opc.invconversionmoney,'fm9999990.0099'))is null then '-'else  to_char(opc.invconversionmoney,'fm9999990.0099') end E3,case when (to_char(opc.otherbuyamount,'fm9999990.0099'))is null then '-'else  to_char(opc.otherbuyamount,'fm9999990.0099') end F3FROM OP_P_CollectDetail opcWHERE opc.COLLECTSN='00000000000000000152'</select><!-- 2计划投资资产分布情况 --><resultMap id="sheetTwoResultMap" type="com.sinosoft.utils.PageData"><result column="C2" property="C2"/><result column="D2" property="D2"/><result column="E2" property="E2"/><result column="C3" property="C3"/><result column="D3" property="D3"/><result column="C4" property="C4"/><result column="D4" property="D4"/><result column="C5" property="C5"/><result column="D5" property="D5"/><result column="C6" property="C6"/><result column="D6" property="D6"/><result column="C7" property="C7"/><result column="D7" property="D7"/><result column="C8" property="C8"/><result column="D8" property="D8"/><result column="C9" property="C9"/><result column="D9" property="D9"/><result column="C10" property="C10"/><result column="D10" property="D10"/><result column="C11" property="C11"/><result column="D11" property="D11"/><result column="C12" property="C12"/><result column="D12" property="D12"/><result column="C13" property="C13"/><result column="D13" property="D13"/><result column="C14" property="C14"/><result column="D14" property="D14"/><result column="C15" property="C15"/><result column="D15" property="D15"/><result column="C16" property="C16"/><result column="D16" property="D16"/><result column="C17" property="C17"/><result column="D17" property="D17"/><result column="C18" property="C18"/><result column="D18" property="D18"/><result column="C19" property="C19"/><result column="D19" property="D19"/><result column="C20" property="C20"/><result column="D20" property="D20"/><result column="C21" property="C21"/><result column="D21" property="D21"/><result column="C22" property="C22"/><result column="D22" property="D22"/><result column="C23" property="C23"/><result column="D23" property="D23"/><result column="C24" property="C24"/><result column="D24" property="D24"/><result column="C25" property="C25"/><result column="D25" property="D25"/><result column="C26" property="C26"/><result column="D26" property="D26"/><result column="C27" property="C27"/><result column="D27" property="D27"/><result column="C28" property="C28"/><result column="D28" property="D28"/><result column="C29" property="C29"/><result column="D29" property="D29"/><result column="C30" property="C30"/><result column="D30" property="D30"/><result column="C31" property="C31"/><result column="D31" property="D31"/><result column="C32" property="C32"/><result column="D32" property="D32"/><result column="C33" property="C33"/><result column="D33" property="D33"/><result column="C34" property="C34"/><result column="D34" property="D34"/><result column="C35" property="C35"/><result column="D35" property="D35"/><result column="E11" property="E11"/><result column="E27" property="E27"/><result column="E34" property="E34"/><result column="A3" property="A3"/><result column="A3" property="A3"/><result column="A3" property="A3"/></resultMap><select id="SheetTwo" parameterType="pd" resultType="com.sinosoft.utils.PageData" resultMap="sheetTwoResultMap" statementType="PREPARED">
select'1' C2,'2' D2,'3' E2,'4' C3,'5' D3,'6' C4,'7' D4,'8' C5,'9' D5,'10' C6,'11' D6,'12' C7,'13' D7,'14' C8,'15' D8,'16' C9,'17' D9,'18' C10,'19' D10,'20' C11,'21' D11,'22' C12,'23' D12,'24' C13,'25' D13,'26' C14,'27' D14,'28' C15,'29' D15,'30' C16,'31' D16,'32' C17,'33' D17,'34' C18,'35' D18,'36' C19,'37' D19,'38' C20,'39' D20,'40' C21,'41' D21,'42' C22,'43' D22,'44' C23,'45' D23,'46' C24,'47' D24,'48' C25,'49' D25,'50' C26,'51' D26,'52' C27,'53' D27,'54' C28,'55' D28,'56' C29,'57' D29,'58' C30,'59' D30,'60' C31,'61' D31,'62' C32,'63' D32,'64' C33,'65' D33,'66' C34,'67' D34,'68' C35,'69' D35,'70' E11,'71' E27,'72' E34from dual</select><!-- 3计划管理费用 --><resultMap id="sheetThreeResultMap" type="com.sinosoft.utils.PageData"><result column="B2" property="B2"/><result column="C2" property="C2"/><result column="B3" property="B3"/><result column="C3" property="C3"/><result column="B4" property="B4"/><result column="C4" property="C4"/></resultMap><select id="SheetThree" parameterType="pd" resultType="com.sinosoft.utils.PageData" resultMap="sheetThreeResultMap" statementType="PREPARED">select '1.00' B2,'2.00' C2,'3.00' B3,'4.00' C3,'5.00' B4,'6.00' C4from dual</select><!-- 4计划管理费用明细 --><resultMap id="sheetFourResultMap" type="com.sinosoft.utils.PageData"><result column="B1" property="B1"/><result column="B4" property="B4"/><result column="B5" property="B5"/><result column="B6" property="B6"/><result column="B7" property="B7"/><result column="B8" property="B8"/><result column="B9" property="B9"/><result column="B12" property="B12"/><result column="B10" property="B10"/><result column="B11" property="B11"/><result column="C5" property="C5"/><result column="C6" property="C6"/><result column="C7" property="C7"/></resultMap><select id="SheetFour" parameterType="pd" resultType="com.sinosoft.utils.PageData" resultMap="sheetFourResultMap" statementType="PREPARED">select'1.00' B1,'2.00' B4,'3.00' B5,'4.00' B6,'5.00' B7,'6.00' B8,'7.00' B9,'8.00' B10,'9.00' B11,'10.00' B12,'11.00' C5,'12.00' C6,'13.00' C7from dual</select><!-- 5资产负债表 --><resultMap id="sheetFiveResultMap" type="com.sinosoft.utils.PageData"><result column="B5" property="B5"/><result column="B6" property="B6"/><result column="B7" property="B7"/><result column="B8" property="B8"/><result column="B9" property="B9"/><result column="B10" property="B10"/><result column="B11" property="B11"/><result column="B12" property="B12"/><result column="B13" property="B13"/><result column="B14" property="B14"/><result column="B15" property="B15"/><result column="B16" property="B16"/><result column="B17" property="B17"/><result column="B18" property="B18"/><result column="B19" property="B19"/><result column="B20" property="B20"/><result column="B21" property="B21"/><result column="B22" property="B22"/><result column="B23" property="B23"/><result column="B24" property="B24"/><result column="B25" property="B25"/><result column="B26" property="B26"/><result column="C5" property="C5"/><result column="C6" property="C6"/><result column="C7" property="C7"/><result column="C8" property="C8"/><result column="C9" property="C9"/><result column="C10" property="C10"/><result column="C11" property="C11"/><result column="C12" property="C12"/><result column="C13" property="C13"/><result column="C14" property="C14"/><result column="C15" property="C15"/><result column="C16" property="C16"/><result column="C17" property="C17"/><result column="C18" property="C18"/><result column="C19" property="C19"/><result column="C20" property="C20"/><result column="C21" property="C21"/><result column="C22" property="C22"/><result column="C23" property="C23"/><result column="C24" property="C24"/><result column="C25" property="C25"/><result column="C26" property="C26"/><result column="E5" property="E5"/><result column="E6" property="E6"/><result column="E7" property="E7"/><result column="E8" property="E8"/><result column="E9" property="E9"/><result column="E10" property="E10"/><result column="E11" property="E11"/><result column="E12" property="E12"/><result column="E13" property="E13"/><result column="E14" property="E14"/><result column="E15" property="E15"/><result column="E16" property="E16"/><result column="E17" property="E17"/><result column="E18" property="E18"/><result column="E19" property="E19"/><result column="E21" property="E21"/><result column="E22" property="E22"/><result column="E23" property="E23"/><result column="E24" property="E24"/><result column="E26" property="E26"/><result column="F5" property="F5"/><result column="F6" property="F6"/><result column="F7" property="F7"/><result column="F8" property="F8"/><result column="F9" property="F9"/><result column="F10" property="F10"/><result column="F11" property="F11"/><result column="F12" property="F12"/><result column="F13" property="F13"/><result column="F14" property="F14"/><result column="F15" property="F15"/><result column="F16" property="F16"/><result column="F17" property="F17"/><result column="F18" property="F18"/><result column="F19" property="F19"/><result column="F21" property="F21"/><result column="F22" property="F22"/><result column="F23" property="F23"/><result column="F24" property="F24"/><result column="F26" property="F26"/></resultMap><select id="SheetFive" parameterType="pd" resultType="com.sinosoft.utils.PageData" resultMap="sheetFiveResultMap" statementType="PREPARED">SELECT'1' B5,'2' B6,'3' B7,'4' B8,'5' B9,'6' B10,'7' B11,'8' B12,'9' B13,'10' B14,'11' B15,'12' B16,'13' B17,'14' B18,'15' B19,'16' B20,'17' B21,'18' B22,'19' B23,'20' B24,'21' B25,'22' B26,'23' C5,'24' C6,'25' C7,'26' C8,'27' C9,'28' C10,'29' C11,'30' C12,'31' C13,'32' C14,'33' C15,'34' C16,'35' C17,'36' C18,'37' C19,'38' C20,'39' C21,'40' C22,'41' C23,'42' C24,'43' C25,'44' C26,'45' E5,'46' E6,'47' E7,'48' E8,'49' E9,'50' E10,'51' E11,'52' E12,'53' E13,'54' E14,'55' E15,'56' E16,'57' E17,'58' E18,'59' E19,'60' E21,'61' E22,'62' E23,'63' E24,'64' E26,'65' F5,'66' F6,'67' F7,'68' F8,'69' F9,'70' F10,'71' F11,'72' F12,'73' F13,'74' F14,'75' F15,'76' F16,'77' F17,'78' F18,'79' F19,'80' F21,'81' F22,'82' F23,'83' F24,'84' F26FROM dual</select><!-- 6净资产变动表 --><resultMap id="sheetSixResultMap" type="com.sinosoft.utils.PageData"><result column="B2" property="B2"/><result column="B4" property="B4"/><result column="B5" property="B5"/><result column="B6" property="B6"/><result column="B7" property="B7"/><result column="B8" property="B8"/><result column="B9" property="B9"/><result column="B10" property="B10"/><result column="B11" property="B11"/><result column="B12" property="B12"/><result column="B13" property="B13"/><result column="B14" property="B14"/><result column="B15" property="B15"/><result column="B16" property="B16"/><result column="B17" property="B17"/><result column="B18" property="B18"/><result column="B19" property="B19"/><result column="B20" property="B20"/><result column="B21" property="B21"/><result column="C4" property="C4"/><result column="C5" property="C5"/><result column="C6" property="C6"/><result column="C7" property="C7"/><result column="C8" property="C8"/><result column="C9" property="C9"/><result column="C10" property="C10"/><result column="C11" property="C11"/><result column="C12" property="C12"/><result column="C13" property="C13"/><result column="C14" property="C14"/><result column="C15" property="C15"/><result column="C16" property="C16"/><result column="C17" property="C17"/><result column="C18" property="C18"/><result column="C19" property="C19"/><result column="C20" property="C20"/><result column="C21" property="C21"/></resultMap><select id="SheetSix" parameterType="pd" resultType="com.sinosoft.utils.PageData" resultMap="sheetSixResultMap" statementType="PREPARED">select '1' B2,'2' B4,'3' B5,'4' B6,'5' B7,'6' B8,'7' B9,'8' B10,'9' B11,'10' B12,'11' B13,'12' B14,'13' B15,'14' B16,'15' B17,'16' B18,'17' B19,'18' B20,'19' B21,'20' C4,'21' C5,'22' C6,'23' C7,'24' C8,'25' C9,'26' C10,'27' C11,'28' C12,'29' C13,'30' C14,'31' C15,'32' C16,'33' C17,'34' C18,'35' C19,'36' C20,'37' C21from dual</select><!-- 7养老金产品分布 --><resultMap id="sheetSevenResultMap" type="com.sinosoft.utils.PageData"><result column="A0" property="A0"/><result column="A1" property="A1"/><result column="B2" property="B2"/><result column="C3" property="C3"/><result column="D4" property="D4"/><result column="E5" property="E5"/><result column="F6" property="F6"/><result column="G7" property="G7"/><result column="H8" property="H8"/><result column="I9" property="I9"/><result column="J10" property="J10"/><result column="K11" property="K11"/></resultMap><select id="SheetSeven" parameterType="pd" resultType="com.sinosoft.utils.PageData" resultMap="sheetSevenResultMap" statementType="PREPARED">SELECTto_char(row_number() over (order by opc.BEFOREMONEY))  A0, case when (to_char(opc.BEFOREMONEY,'fm9999990.0099'))is null then '-'else  to_char(opc.BEFOREMONEY,'fm9999990.0099') end A1,case when (to_char(opc.payredeemmoney,'fm9999990.0099'))is null then '-'else  to_char(opc.payredeemmoney,'fm9999990.0099') end B2,case when (to_char(opc.aftermoney,'fm9999990.0099'))is null then '-'else  to_char(opc.aftermoney,'fm9999990.0099') end C3,case when (to_char(opc.payredeemmoney,'fm9999990.0099'))is null then '-'else  to_char(opc.payredeemmoney,'fm9999990.0099') end D4,case when (to_char(opc.invconversionmoney,'fm9999990.0099'))is null then '-'else  to_char(opc.invconversionmoney,'fm9999990.0099') end E5,case when (to_char(opc.otherbuyamount,'fm9999990.0099'))is null then '-'else  to_char(opc.otherbuyamount,'fm9999990.0099') end F6,case when (to_char(opc.aftermoney,'fm9999990.0099'))is null then '-'else  to_char(opc.aftermoney,'fm9999990.0099') end G7,case when (to_char(opc.aftermoney,'fm9999990.0099'))is null then '-'else  to_char(opc.aftermoney,'fm9999990.0099') end H8,case when (to_char(opc.payredeemmoney,'fm9999990.0099'))is null then '-'else  to_char(opc.payredeemmoney,'fm9999990.0099') end I9,case when (to_char(opc.invconversionmoney,'fm9999990.0099'))is null then '-'else  to_char(opc.invconversionmoney,'fm9999990.0099') end J10,case when (to_char(opc.otherbuyamount,'fm9999990.0099'))is null then '-'else  to_char(opc.otherbuyamount,'fm9999990.0099') end K11FROM OP_P_CollectDetail opc--where opc.COLLECTSN ='00000000000000000152'WHERE opc.COLLECTSN in ('00000000000000000152','00000000000000000149')UNION ALL SELECT '合计'  A0,'-' A1,'-' B2,'-' C3,'-' D4,' ' E5,case when (to_char(17950878.06,'fm9999999999990.0099'))is null then '-'else  to_char(17950878.06,'fm9999999999990.0099') end F6,'-' G7,'-' H8,' ' I9,case when (to_char(17950878.06,'fm99999999999990.0099'))is null then '-'else  to_char(17950878.06,'fm99999999999990.0099') end J10,case when (to_char(78.06,'fm999990.0099'))is null then '-'else  to_char(78.06,'fm999990.0099') end K11FROM OP_P_CollectDetail opWHERE op.COLLECTSN = '00000000000000000152'</select>
</mapper>

js页面
需要把以下两个参数传到控制器,具体方式这里就不说了,有很多种

modeName:"tuoguanhuizong.xlsx",    //表格模板名
filename:"createLate"     		//填充完数据生成一个新的文件名

通过以上代码就能完成读取一个空的模板,然后把数据填充上,使用数据为了演示效果而做,效果如下:
在这里插入图片描述

在这里插入图片描述


author:su1573


http://chatgpt.dhexx.cn/article/15F6uKm1.shtml

相关文章

java使用poi操作读取Excel文件

在上代码之前首先说说Excel文件的一些名词 工作区workbook&#xff1a;可以理解为一个Excel文件&#xff0c;比如LinkL.xlsx文件 表sheet&#xff1a;一个.xlsx文件中的不同表 行row&#xff1a;表中的一行数据 单元格cell&#xff1a;每一行中的每一个数据就是单元格 附&…

使用Java通过POI读取EXCEL中的数据

这里有个Excel&#xff0c;怎么使用java读取excel中的数据呢&#xff1f; 文件存放位置&#xff1a; 首先引入poi的jar包 <dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>3.17</version></…

使用POI读取excel文件内容

1.前言 项目中要求读取excel文件内容&#xff0c;并将其转化为xml格式。常见读取excel文档一般使用POI和JExcelAPI这两个工具。这里我们介绍使用POI实现读取excel文档。 2.代码实例&#xff1a; package edu.sjtu.erplab.poi;import java.io.FileInputStream;import java.io.Fi…

使用POI读取Excel文件

使用POI读取Excel文件 一、前言 用户可以通过上传excel文件&#xff0c;后端通过读取excel文件的内容并将内容写入数据库中以便更好的使用。 本文档使用的excel的工具类既可以读取有合并单元格的文件也可以读取没有合并单元格的文件&#xff0c;并且读取到单元格的数据进行了…

POI读写Excel的基本使用

一、Excel导入导出的应用场景 1、数据导入&#xff1a;减轻录入工作量 2、数据导出&#xff1a;统计信息归档 3、数据传输&#xff1a;异构系统之间数据传输 二、POI简介&#xff08;Apache POI&#xff09; 1、什么是POI Apache POI是Apache软件基金会的开放源码函式库&…

C# 加载DotNetBar组件

C#作为前端的开发软件&#xff0c;使用的人很多&#xff0c;但是原生的C#界面较为简陋&#xff0c;已经不能满足公司级的开发工作了&#xff0c;今天这篇博客的主要内容是讲一下怎么在C#端使用一个可以提升界面美感的第三方控件&#xff0c;DotNetBar 首先去官网下载最新的DotN…

DevComponents.DotNetBar2 美化包使用以及验证教程

使用这个美化包是在别人项目上看到的&#xff0c;遇到一些懵逼问题&#xff0c;不断总结&#xff0c;所以写一下教程 DotNetBar 美化包控件不可编辑问题&#xff1a; 如图&#xff1a; 解决办法&#xff1a; 安装DotNetBar 这个软件&#xff08;有试用版&#xff09;&#xff…

winform DevComponents.DotNetBar2 添加到工具栏方法

当C#项目引入皮肤组件&#xff0c;或其他组件是&#xff0c;发现工具框里面没有引用的组件怎么办&#xff1f; 1.组件的引用 我是把下载好的*.dll组件&#xff0c;复制到项目的\bin\Debug\路径下&#xff0c;然后在项目处右键-->添加引用&#xff0c;这样组件就引入项目了…

DotNetBar控件的多文档界面的实现

DotNetBar是一个不错的DotNET控件套装&#xff0c;原来是一个DLL文件&#xff0c;能够做出很漂亮的界面效果&#xff0c;记得在8.0以前的版本&#xff0c;好像实现多文档界面稍显得麻烦一些&#xff0c;我的Winform框架、WCF框架虽然也提供了这样多文档的界面&#xff0c;不过都…

C#之DotNetBar2使用方法 - itemPanel1

用itemPanel做个按钮菜单&#xff0c;模拟用来操控开关按钮 对象buttonItem1的属性&#xff08;itempanel可以添加的子控件列表对象&#xff0c;根据需要选择&#xff0c;这里用到的Button&#xff09; 可以用控件自带的样式&#xff0c;也可以用代码控制&#xff0c;也可以预先…

winfrom DotNetBar sideNav控件使用问题

sideNav初始UI 在最开始的界面&#xff0c;不知道设置了什么东西&#xff0c;然后没有那个东西 最后又新建了个项目&#xff0c;一个一个对比参数。还是没找到&#xff01;倒是发现几个其他的参数属性 在这里记录下 这是分别对应的是对sideNav的sideNavPanel的折叠 最大化 隐藏…

界面控件DotNetBar for WinForms使用教程:highlight组件使用教程

DotNetBar for WinForms是一个拥有89个组件的用户界面控件套包&#xff0c;用户可以使用Visual Studio 2005-2015轻松地创建专业的用户界面。十多年来DotNetBar帮助开发人员轻松地创建易用的专业Windows Forms (WinForms) 用户界面。DotNetBar是全世界第一个引入全功能Office 2…

C#之DotNetBar2使用方法 - superTabControl1

C#版本&#xff1a;DevComponents.DotNetBar2 14.1.0 &#xff08;可以搜下各种版本&#xff09; 常用的控件使用属性&#xff0c;方法&#xff1b; 1&#xff09;superTabControl1 关闭和菜单设置方法 visibletrue/false closebox :关闭当前选中的TAB menubox:切换tab的菜…

DevComponents.DotNetBar2之SuperTabControl使用技巧

关于类似SuperTabControl的使用如何动态调整其TAB标签的顺序问题&#xff0c;搜了全网也没有找到类似答案&#xff0c;都提到tab键的顺序或者是通过控件界面进行调整其顺序&#xff0c;都不是想要的结果&#xff0c;有个网友问的类似问题但是没有一个答案可用。经过反复测试总结…

界面控件DotNetBar for WinForms使用教程:LayoutControl详解(二)

DotNetBar for WinForms是一个拥有89个组件的用户界面控件套包&#xff0c;用户可以使用Visual Studio 2005-2015轻松地创建专业的用户界面。十多年来DotNetBar帮助开发人员轻松地创建易用的专业Windows Forms (WinForms) 用户界面。 点击下载DotNetBar for WinForms最新试用版…

DotNetBar布局(一)

相信大家搞.NET桌面程序开发都会用到一些界面布局的组件&#xff0c;常用的由DotNetBar和devexpress。今天主要将DotNetBar在项目中布局简单介绍一下&#xff0c;个人感觉这个控件还是有很多bug的&#xff0c;不知道什么时候就出现莫名奇妙的排版问题错误。比如突然在设计视图D…

dotnetbar-SuperTabControl禁止调整顺序

superTabCtl.ReorderTabsEnabled false; 禁止调整TAB顺序 superTabCtl.CloseButtonOnTabsAlwaysDisplayedfalse; 禁止x关闭按钮一直在TAB上显示 superTabCtl.CloseButtonOnTabsVisibletrue/false;关闭按钮是否可见 注意&#xff1a; superTabitem.CloseButtonVisibletru…

Visual Studio 2019 中使用 DotNetBar

1、下载并安装DotNetBarSetupTrial 2、在新建项目或者现有项目中进行引用&#xff0c;找到DotNetBar安装路径中需要用到的dll引用&#xff0c;引用路径正确是关键 3、在工具箱中添加选项卡&#xff0c;加载需要用到的控件 先在工具箱空白处添加选项卡&#xff0c;方便管理&am…

DotNetBar for WinForms使用教程:图表控件用户指南(一)

DotNetBar for WinForms是一个拥有89个组件的用户界面控件套包&#xff0c;用户可以使用Visual Studio 2005-2015轻松地创建专业的用户界面。十多年来DotNetBar帮助开发人员轻松地创建易用的专业Windows Forms (WinForms) 用户界面。DotNetBar是全世界第一个引入全功能Office 2…

c# 使用dotnetbar 控件绘制曲线图形

废话不说,直接上过程 加载dotnetbar库后,将chartcontrol控件拖动到界面上,选择line polt 增加一个按钮,绘制曲线功能 private void buttonX26_Click(object sender, EventArgs e) { CreateChartSeries1(); } public void CreateChart…