• freemarker+poi实现动态生成excel文件及解析excel文件


    freemarker+poi动态生成excel文件

     pom文件配置:

    1. <dependency>
    2. <groupId>org.springframework.boot</groupId>
    3. <artifactId>spring-boot-starter-freemarker</artifactId>
    4. </dependency>

    配置文件:

    1. # 模板后缀名
    2. spring.freemarker.suffix:.ftl
    3. # 文档类型
    4. spring.freemarker.content-type:text/html
    5. # 页面编码
    6. spring.freemarker.charset:UTF-8
    7. # 页面缓存
    8. spring.freemarker.cache:false
    9. # 模板路径
    10. spring.freemarker.template-loader-path:classpath:/templates/

    生成模板ftl文件步骤:

    1、新建excel文件:test.xlsx

     2、把文件另存为xml文件,即test.xml

     3、把test.xml修改文件后缀名,改为test.ftl

     4、ftl文件格式化在线 XML 格式化 | 菜鸟工具

     5、test.ftl文件中添加动态数据参数

    1. <#if userList??>
    2. <#list userList as user>
    3. <Row>
    4. <Cell>
    5. <Data ss:Type="String">${user.name}</Data>
    6. </Cell>
    7. <Cell>
    8. <Data ss:Type="Number">${user.age}</Data>
    9. </Cell>
    10. <Cell ss:StyleID="s51" ss:HRef="mailto:${user.email}">
    11. <Data ss:Type="String">${user.email}</Data>
    12. </Cell>
    13. </Row>
    14. </#list>
    15. </#if>

    最终把test.ftl文件放到resources/templates下,freemarker默认读取模板文件的位置

    下面使用springboot+freemarker动态生成并在线下载excel文件

    1. package com.example.stu1.freemark;
    2. import lombok.Data;
    3. /**
    4. * @Author yangcai
    5. * @create 2022/7/1 16:43
    6. */
    7. @Data
    8. public class User {
    9. private int age;
    10. private String name;
    11. private String email;
    12. }
    1. import freemarker.template.Template;
    2. import org.springframework.web.bind.annotation.GetMapping;
    3. import org.springframework.web.bind.annotation.RestController;
    4. import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
    5. import javax.annotation.Resource;
    6. import javax.servlet.http.HttpServletResponse;
    7. import java.io.PrintWriter;
    8. import java.net.URLEncoder;
    9. import java.util.ArrayList;
    10. import java.util.HashMap;
    11. import java.util.List;
    12. import java.util.Map;
    13. /**
    14. * @Author yangcai
    15. * @create 2022/7/1 16:43
    16. */
    17. @RestController
    18. public class UserController {
    19. @Resource
    20. FreeMarkerConfigurer freemarkerConfigurer;
    21. @GetMapping("/index")
    22. public void index(HttpServletResponse response) {
    23. String userName ="userName";
    24. String fileName = userName +"测试导出的" + ".xlsx";
    25. Map<String,Object> resultMap= getList();
    26. downloadDoc(freemarkerConfigurer, "/test.ftl", resultMap, fileName, response);
    27. }
    28. Map<String,Object> getList(){
    29. Map<String,Object> map = new HashMap<>();
    30. List<User> userList = new ArrayList<>();
    31. User user1 = new User();
    32. user1.setAge(26);
    33. user1.setEmail("707656893@qq.com");
    34. user1.setName("张无忌");
    35. userList.add(user1);
    36. User user2 = new User();
    37. user2.setAge(27);
    38. user2.setEmail("111111111@qq.com");
    39. user2.setName("逍遥子");
    40. userList.add(user2);
    41. User user3 = new User();
    42. user3.setAge(28);
    43. user3.setEmail("222222222@qq.com");
    44. user3.setName("乔峰");
    45. userList.add(user3);
    46. map.put("userList",userList);
    47. return map;
    48. }
    49. public void downloadDoc(FreeMarkerConfigurer freemarkerConfigurer, String modelPath, Map<String, Object> data,
    50. String fileName, HttpServletResponse response) {
    51. try {
    52. Template template = freemarkerConfigurer.getConfiguration().getTemplate(modelPath);
    53. response.reset();
    54. response.setContentType("application/octet-stream;charset=utf-8");
    55. response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
    56. PrintWriter writer = response.getWriter();
    57. template.process(data, writer);
    58. writer.flush();
    59. } catch (Exception e) {
    60. e.printStackTrace();
    61. }
    62. }
    63. }

    请求:http://localhost:8080/index

    会生成一个xlsx文件:文件内容如下

    注意:这个excel文件本质还是一个xml文件,用WPS能正常打开,但是用office打开会提示文件格式不正确

     所以要真正的生成excel,还需要使用poi,poi的目的就是把xml文件转换成excel文件

    pom引入poi相关jar:

    1. <dependency>
    2. <groupId>org.apache.poi</groupId>
    3. <artifactId>poi</artifactId>
    4. <version>3.16</version>
    5. </dependency>
    6. <dependency>
    7. <groupId>org.apache.poi</groupId>
    8. <artifactId>poi-ooxml</artifactId>
    9. <version>3.16</version>
    10. </dependency>
    11. <dependency>
    12. <groupId>cn.eonml</groupId>
    13. <artifactId>freemarker-excel</artifactId>
    14. <version>0.1.5</version>
    15. </dependency>

    自定义工具类:

    1. //
    2. // Source code recreated from a .class file by IntelliJ IDEA
    3. // (powered by Fernflower decompiler)
    4. //
    5. package com.example.stu1.freemark;
    6. import com.yongjiu.commons.utils.XmlReader;
    7. import com.yongjiu.dto.freemarker.input.ExcelImageInput;
    8. import com.yongjiu.dto.freemarker.input.FreemarkerInput;
    9. import com.yongjiu.entity.excel.Cell;
    10. import com.yongjiu.entity.excel.CellRangeAddressEntity;
    11. import com.yongjiu.entity.excel.Column;
    12. import com.yongjiu.entity.excel.Data;
    13. import com.yongjiu.entity.excel.Row;
    14. import com.yongjiu.entity.excel.Style;
    15. import com.yongjiu.entity.excel.Table;
    16. import com.yongjiu.entity.excel.Worksheet;
    17. import com.yongjiu.entity.excel.Style.Border;
    18. import com.yongjiu.util.ColorUtil;
    19. import freemarker.template.Configuration;
    20. import freemarker.template.Template;
    21. import freemarker.template.TemplateExceptionHandler;
    22. import java.awt.image.BufferedImage;
    23. import java.io.BufferedWriter;
    24. import java.io.ByteArrayOutputStream;
    25. import java.io.File;
    26. import java.io.FileOutputStream;
    27. import java.io.IOException;
    28. import java.io.OutputStream;
    29. import java.io.OutputStreamWriter;
    30. import java.io.Writer;
    31. import java.util.ArrayList;
    32. import java.util.Iterator;
    33. import java.util.List;
    34. import java.util.Locale;
    35. import java.util.Map;
    36. import javax.imageio.ImageIO;
    37. import javax.servlet.http.HttpServletResponse;
    38. import org.apache.commons.io.FileUtils;
    39. import org.apache.poi.hssf.usermodel.HSSFCell;
    40. import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
    41. import org.apache.poi.hssf.usermodel.HSSFDataFormat;
    42. import org.apache.poi.hssf.usermodel.HSSFFont;
    43. import org.apache.poi.hssf.usermodel.HSSFPalette;
    44. import org.apache.poi.hssf.usermodel.HSSFRichTextString;
    45. import org.apache.poi.hssf.usermodel.HSSFRow;
    46. import org.apache.poi.hssf.usermodel.HSSFSheet;
    47. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    48. import org.apache.poi.hssf.util.HSSFColor;
    49. import org.apache.poi.ss.usermodel.BorderStyle;
    50. import org.apache.poi.ss.usermodel.CellStyle;
    51. import org.apache.poi.ss.usermodel.CellType;
    52. import org.apache.poi.ss.usermodel.Comment;
    53. import org.apache.poi.ss.usermodel.Drawing;
    54. import org.apache.poi.ss.usermodel.FillPatternType;
    55. import org.apache.poi.ss.usermodel.HorizontalAlignment;
    56. import org.apache.poi.ss.usermodel.IndexedColors;
    57. import org.apache.poi.ss.usermodel.Sheet;
    58. import org.apache.poi.ss.usermodel.VerticalAlignment;
    59. import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
    60. import org.apache.poi.ss.util.CellRangeAddress;
    61. import org.apache.poi.ss.util.RegionUtil;
    62. import org.apache.poi.xssf.usermodel.XSSFCell;
    63. import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
    64. import org.apache.poi.xssf.usermodel.XSSFDataFormat;
    65. import org.apache.poi.xssf.usermodel.XSSFFont;
    66. import org.apache.poi.xssf.usermodel.XSSFRichTextString;
    67. import org.apache.poi.xssf.usermodel.XSSFRow;
    68. import org.apache.poi.xssf.usermodel.XSSFSheet;
    69. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    70. import org.dom4j.Document;
    71. import org.dom4j.io.SAXReader;
    72. import org.slf4j.Logger;
    73. import org.slf4j.LoggerFactory;
    74. import org.springframework.util.CollectionUtils;
    75. import org.springframework.util.ObjectUtils;
    76. public class FreeMarkerTemplateUtil {
    77. private static final Logger log = LoggerFactory.getLogger(FreeMarkerTemplateUtil.class);
    78. public FreeMarkerTemplateUtil() {
    79. }
    80. public static void exportToFile(Map dataMap, String templateName, String templateFilePath, String fileFullPath) {
    81. try {
    82. File file = new File(fileFullPath);
    83. FileUtils.forceMkdirParent(file);
    84. FileOutputStream outputStream = new FileOutputStream(file);
    85. exportToStream(dataMap, templateName, templateFilePath, outputStream);
    86. } catch (Exception var6) {
    87. var6.printStackTrace();
    88. }
    89. }
    90. public static void exportToStream(Map dataMap, String templateName, String templateFilePath, FileOutputStream outputStream) {
    91. try {
    92. Template template = getTemplate(templateName, templateFilePath);
    93. OutputStreamWriter outputWriter = new OutputStreamWriter(outputStream, "UTF-8");
    94. Writer writer = new BufferedWriter(outputWriter);
    95. template.process(dataMap, writer);
    96. writer.flush();
    97. writer.close();
    98. outputStream.close();
    99. } catch (Exception var7) {
    100. var7.printStackTrace();
    101. }
    102. }
    103. public static void exportImageExcel(String excelFilePath, FreemarkerInput freemarkerInput) {
    104. try {
    105. File file = new File(excelFilePath);
    106. FileUtils.forceMkdirParent(file);
    107. FileOutputStream outputStream = new FileOutputStream(file);
    108. createImageExcleToStream(freemarkerInput, outputStream);
    109. FileUtils.forceDelete(new File(freemarkerInput.getXmlTempFile() + freemarkerInput.getFileName() + ".xml"));
    110. log.info("导出成功,导出到目录:" + file.getCanonicalPath());
    111. } catch (Exception var4) {
    112. var4.printStackTrace();
    113. }
    114. }
    115. public static void exportImageExcelNew(String excelFilePath, FreemarkerInput freemarkerInput) {
    116. try {
    117. File file = new File(excelFilePath);
    118. FileUtils.forceMkdirParent(file);
    119. FileOutputStream outputStream = new FileOutputStream(file);
    120. createExcelToStream(freemarkerInput, outputStream);
    121. FileUtils.forceDelete(new File(freemarkerInput.getXmlTempFile() + freemarkerInput.getFileName() + ".xml"));
    122. log.info("导出成功,导出到目录:" + file.getCanonicalPath());
    123. } catch (Exception var4) {
    124. var4.printStackTrace();
    125. }
    126. }
    127. public static void exportImageExcelNew(HttpServletResponse response, FreemarkerInput freemarkerInput) {
    128. try {
    129. OutputStream outputStream = response.getOutputStream();
    130. response.reset();
    131. response.setContentType("application/msexcel;charset=UTF-8");
    132. response.setHeader("Content-Disposition", "attachment;filename=\"" + new String((freemarkerInput.getFileName() + ".xlsx").getBytes("GBK"), "ISO8859-1") + "\"");
    133. response.setHeader("Response-Type", "Download");
    134. createExcelToStream(freemarkerInput, outputStream);
    135. FileUtils.forceDelete(new File(freemarkerInput.getXmlTempFile() + freemarkerInput.getFileName() + ".xml"));
    136. } catch (Exception var3) {
    137. var3.printStackTrace();
    138. }
    139. }
    140. public static void exportImageExcel(HttpServletResponse response, FreemarkerInput freemarkerInput) {
    141. try {
    142. OutputStream outputStream = response.getOutputStream();
    143. response.reset();
    144. response.setContentType("application/msexcel;charset=UTF-8");
    145. response.setHeader("Content-Disposition", "attachment;filename=\"" + new String((freemarkerInput.getFileName() + ".xls").getBytes("GBK"), "ISO8859-1") + "\"");
    146. response.setHeader("Response-Type", "Download");
    147. createImageExcleToStream(freemarkerInput, outputStream);
    148. FileUtils.forceDelete(new File(freemarkerInput.getXmlTempFile() + freemarkerInput.getFileName() + ".xml"));
    149. } catch (Exception var3) {
    150. var3.printStackTrace();
    151. }
    152. }
    153. private static Template getTemplate(String templateName, String filePath) throws IOException {
    154. Configuration configuration = new Configuration(Configuration.VERSION_2_3_28);
    155. configuration.setDefaultEncoding("UTF-8");
    156. configuration.setTemplateUpdateDelayMilliseconds(0L);
    157. configuration.setEncoding(Locale.CHINA, "UTF-8");
    158. configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    159. configuration.setClassForTemplateLoading(FreeMarkerTemplateUtil.class, filePath);
    160. configuration.setOutputEncoding("UTF-8");
    161. return configuration.getTemplate(templateName, "UTF-8");
    162. }
    163. private static void createImageExcleToStream(FreemarkerInput freemarkerInput, OutputStream outputStream) {
    164. BufferedWriter out = null;
    165. try {
    166. Template template = getTemplate(freemarkerInput.getTemplateName(), freemarkerInput.getTemplateFilePath());
    167. File tempXMLFile = new File(freemarkerInput.getXmlTempFile() + freemarkerInput.getFileName() + ".xml");
    168. FileUtils.forceMkdirParent(tempXMLFile);
    169. out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tempXMLFile), "UTF-8"));
    170. template.process(freemarkerInput.getDataMap(), out);
    171. if (log.isDebugEnabled()) {
    172. log.debug("1.完成将文本数据导入到XML文件中");
    173. }
    174. SAXReader reader = new SAXReader();
    175. Document document = reader.read(tempXMLFile);
    176. Map<String, Style> styleMap = readXmlStyle(document);
    177. log.debug("2.完成解析XML中样式信息");
    178. List<Worksheet> worksheets = readXmlWorksheet(document);
    179. if (log.isDebugEnabled()) {
    180. log.debug("3.开始将XML信息写入Excel,数据为:" + worksheets.toString());
    181. }
    182. HSSFWorkbook wb = new HSSFWorkbook();
    183. Iterator var10 = worksheets.iterator();
    184. while(var10.hasNext()) {
    185. Worksheet worksheet = (Worksheet)var10.next();
    186. HSSFSheet sheet = wb.createSheet(worksheet.getName());
    187. Table table = worksheet.getTable();
    188. List<Row> rows = table.getRows();
    189. List<Column> columns = table.getColumns();
    190. int createRowIndex;
    191. if (columns != null && columns.size() > 0) {
    192. createRowIndex = 0;
    193. for(int i = 0; i < columns.size(); ++i) {
    194. Column column = (Column)columns.get(i);
    195. createRowIndex = getCellWidthIndex(createRowIndex, i, column.getIndex());
    196. sheet.setColumnWidth(createRowIndex, (int)column.getWidth() * 50);
    197. }
    198. }
    199. createRowIndex = 0;
    200. List<CellRangeAddressEntity> cellRangeAddresses = new ArrayList();
    201. for(int rowIndex = 0; rowIndex < rows.size(); ++rowIndex) {
    202. Row rowInfo = (Row)rows.get(rowIndex);
    203. if (rowInfo != null) {
    204. createRowIndex = getIndex(createRowIndex, rowIndex, rowInfo.getIndex());
    205. HSSFRow row = sheet.createRow(createRowIndex);
    206. if (rowInfo.getHeight() != null) {
    207. Integer height = rowInfo.getHeight() * 20;
    208. row.setHeight(height.shortValue());
    209. }
    210. List<Cell> cells = rowInfo.getCells();
    211. if (!CollectionUtils.isEmpty(cells)) {
    212. int startIndex = 0;
    213. for(int cellIndex = 0; cellIndex < cells.size(); ++cellIndex) {
    214. Cell cellInfo = (Cell)cells.get(cellIndex);
    215. if (cellInfo != null) {
    216. startIndex = getIndex(startIndex, cellIndex, cellInfo.getIndex());
    217. HSSFCell cell = row.createCell(startIndex);
    218. String styleID = cellInfo.getStyleID();
    219. Style style = (Style)styleMap.get(styleID);
    220. CellStyle dataStyle = wb.createCellStyle();
    221. setBorder(style, dataStyle);
    222. setAlignment(style, dataStyle);
    223. setValue((HSSFWorkbook)wb, cellInfo, (HSSFCell)cell, style, dataStyle);
    224. setCellColor(style, dataStyle);
    225. cell.setCellStyle(dataStyle);
    226. if (cellInfo.getComment() != null) {
    227. Data data = cellInfo.getComment().getData();
    228. Comment comment = sheet.createDrawingPatriarch().createCellComment(new HSSFClientAnchor(0, 0, 0, 0, (short)3, 3, (short)5, 6));
    229. comment.setString(new HSSFRichTextString(data.getText()));
    230. cell.setCellComment(comment);
    231. }
    232. startIndex = getCellRanges(createRowIndex, cellRangeAddresses, startIndex, cellInfo, style);
    233. }
    234. }
    235. }
    236. }
    237. }
    238. addCellRange((HSSFSheet)sheet, cellRangeAddresses);
    239. }
    240. log.debug("4.开始写入图片:" + freemarkerInput.getExcelImageInputs());
    241. if (!CollectionUtils.isEmpty(freemarkerInput.getExcelImageInputs())) {
    242. writeImageToExcel(freemarkerInput.getExcelImageInputs(), wb);
    243. }
    244. log.debug("5.完成写入图片:" + freemarkerInput.getExcelImageInputs());
    245. wb.write(outputStream);
    246. outputStream.close();
    247. } catch (Exception var39) {
    248. var39.printStackTrace();
    249. log.error("导出excel异常:" + var39.getMessage());
    250. } finally {
    251. try {
    252. out.close();
    253. } catch (Exception var38) {
    254. }
    255. }
    256. }
    257. private static void createExcelToStream(FreemarkerInput freemarkerInput, OutputStream outputStream) {
    258. BufferedWriter out = null;
    259. try {
    260. Template template = getTemplate(freemarkerInput.getTemplateName(), freemarkerInput.getTemplateFilePath());
    261. File tempXMLFile = new File(freemarkerInput.getXmlTempFile() + freemarkerInput.getFileName() + ".xml");
    262. FileUtils.forceMkdirParent(tempXMLFile);
    263. out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tempXMLFile), "UTF-8"));
    264. template.process(freemarkerInput.getDataMap(), out);
    265. if (log.isDebugEnabled()) {
    266. log.debug("1.完成将文本数据导入到XML文件中");
    267. }
    268. SAXReader reader = new SAXReader();
    269. Document document = reader.read(tempXMLFile);
    270. Map<String, Style> styleMap = readXmlStyle(document);
    271. log.debug("2.完成解析XML中样式信息");
    272. List<Worksheet> worksheets = readXmlWorksheet(document);
    273. if (log.isDebugEnabled()) {
    274. log.debug("3.开始将XML信息写入Excel,数据为:" + worksheets.toString());
    275. }
    276. XSSFWorkbook wb = new XSSFWorkbook();
    277. Iterator var10 = worksheets.iterator();
    278. while(var10.hasNext()) {
    279. Worksheet worksheet = (Worksheet)var10.next();
    280. XSSFSheet sheet = wb.createSheet(worksheet.getName());
    281. Table table = worksheet.getTable();
    282. List<Row> rows = table.getRows();
    283. List<Column> columns = table.getColumns();
    284. int createRowIndex;
    285. if (columns != null && columns.size() > 0) {
    286. createRowIndex = 0;
    287. for(int i = 0; i < columns.size(); ++i) {
    288. Column column = (Column)columns.get(i);
    289. createRowIndex = getCellWidthIndex(createRowIndex, i, column.getIndex());
    290. sheet.setColumnWidth(createRowIndex, (int)column.getWidth() * 50);
    291. }
    292. }
    293. for(int i = 0 ; i<1000;i++){
    294. sheet.setColumnWidth(i,3000);
    295. }
    296. createRowIndex = 0;
    297. List<CellRangeAddressEntity> cellRangeAddresses = new ArrayList();
    298. for(int rowIndex = 0; rowIndex < rows.size(); ++rowIndex) {
    299. Row rowInfo = (Row)rows.get(rowIndex);
    300. if (rowInfo != null) {
    301. createRowIndex = getIndex(createRowIndex, rowIndex, rowInfo.getIndex());
    302. XSSFRow row = sheet.createRow(createRowIndex);
    303. if (rowInfo.getHeight() != null) {
    304. Integer height = rowInfo.getHeight() * 20;
    305. row.setHeight(height.shortValue());
    306. }
    307. List<Cell> cells = rowInfo.getCells();
    308. if (!CollectionUtils.isEmpty(cells)) {
    309. int startIndex = 0;
    310. for(int cellIndex = 0; cellIndex < cells.size(); ++cellIndex) {
    311. Cell cellInfo = (Cell)cells.get(cellIndex);
    312. if (cellInfo != null) {
    313. startIndex = getIndex(startIndex, cellIndex, cellInfo.getIndex());
    314. XSSFCell cell = row.createCell(startIndex);
    315. String styleID = cellInfo.getStyleID();
    316. Style style = (Style)styleMap.get(styleID);
    317. CellStyle dataStyle = wb.createCellStyle();
    318. setBorder(style, dataStyle);
    319. setAlignment(style, dataStyle);
    320. setValue((XSSFWorkbook)wb, cellInfo, (XSSFCell)cell, style, dataStyle);
    321. setCellColor(style, dataStyle);
    322. cell.setCellStyle(dataStyle);
    323. if (cellInfo.getComment() != null) {
    324. Data data = cellInfo.getComment().getData();
    325. Comment comment = sheet.createDrawingPatriarch().createCellComment(new XSSFClientAnchor(0, 0, 0, 0, 3, 3, 5, 6));
    326. comment.setString(new XSSFRichTextString(data.getText()));
    327. cell.setCellComment(comment);
    328. }
    329. startIndex = getCellRanges(createRowIndex, cellRangeAddresses, startIndex, cellInfo, style);
    330. }
    331. }
    332. }
    333. }
    334. }
    335. addCellRange((XSSFSheet)sheet, cellRangeAddresses);
    336. }
    337. log.debug("4.开始写入图片:" + freemarkerInput.getExcelImageInputs());
    338. if (!CollectionUtils.isEmpty(freemarkerInput.getExcelImageInputs())) {
    339. writeImageToExcel(freemarkerInput.getExcelImageInputs(), wb);
    340. }
    341. log.debug("5.完成写入图片:" + freemarkerInput.getExcelImageInputs());
    342. wb.write(outputStream);
    343. outputStream.close();
    344. } catch (Exception var39) {
    345. var39.printStackTrace();
    346. log.error("导出excel异常:" + var39.getMessage());
    347. } finally {
    348. try {
    349. out.close();
    350. } catch (Exception var38) {
    351. }
    352. }
    353. }
    354. public static Map<String, Style> readXmlStyle(Document document) {
    355. Map<String, Style> styleMap = XmlReader.getStyle(document);
    356. return styleMap;
    357. }
    358. public static List<Worksheet> readXmlWorksheet(Document document) {
    359. List<Worksheet> worksheets = XmlReader.getWorksheet(document);
    360. return worksheets;
    361. }
    362. private static int getIndex(int columnIndex, int i, Integer index) {
    363. if (index != null) {
    364. columnIndex = index - 1;
    365. }
    366. if (index == null && columnIndex != 0) {
    367. ++columnIndex;
    368. }
    369. if (index == null && columnIndex == 0) {
    370. columnIndex = i;
    371. }
    372. return columnIndex;
    373. }
    374. private static int getCellWidthIndex(int columnIndex, int i, Integer index) {
    375. if (index != null) {
    376. columnIndex = index;
    377. }
    378. if (index == null && columnIndex != 0) {
    379. ++columnIndex;
    380. }
    381. if (index == null && columnIndex == 0) {
    382. columnIndex = i;
    383. }
    384. return columnIndex;
    385. }
    386. private static void setBorder(Style style, CellStyle dataStyle) {
    387. if (style != null && style.getBorders() != null) {
    388. for(int k = 0; k < style.getBorders().size(); ++k) {
    389. Border border = (Border)style.getBorders().get(k);
    390. if (border != null) {
    391. if ("Bottom".equals(border.getPosition())) {
    392. dataStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    393. dataStyle.setBorderBottom(BorderStyle.THIN);
    394. }
    395. if ("Left".equals(border.getPosition())) {
    396. dataStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    397. dataStyle.setBorderLeft(BorderStyle.THIN);
    398. }
    399. if ("Right".equals(border.getPosition())) {
    400. dataStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
    401. dataStyle.setBorderRight(BorderStyle.THIN);
    402. }
    403. if ("Top".equals(border.getPosition())) {
    404. dataStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
    405. dataStyle.setBorderTop(BorderStyle.THIN);
    406. }
    407. }
    408. }
    409. }
    410. }
    411. private static void writeImageToExcel(List<ExcelImageInput> excelImageInputs, HSSFWorkbook wb) throws IOException {
    412. BufferedImage bufferImg = null;
    413. if (!CollectionUtils.isEmpty(excelImageInputs)) {
    414. Iterator var3 = excelImageInputs.iterator();
    415. while(var3.hasNext()) {
    416. ExcelImageInput excelImageInput = (ExcelImageInput)var3.next();
    417. Sheet sheet = wb.getSheetAt(excelImageInput.getSheetIndex());
    418. if (sheet != null) {
    419. Drawing patriarch = sheet.createDrawingPatriarch();
    420. HSSFClientAnchor anchor = excelImageInput.getAnchorXls();
    421. anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
    422. String imagePath = excelImageInput.getImgPath();
    423. ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
    424. bufferImg = ImageIO.read(new File(imagePath));
    425. String imageType = imagePath.substring(imagePath.lastIndexOf(".") + 1, imagePath.length());
    426. ImageIO.write(bufferImg, imageType, byteArrayOut);
    427. patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), 5));
    428. }
    429. }
    430. }
    431. }
    432. private static void writeImageToExcel(List<ExcelImageInput> excelImageInputs, XSSFWorkbook wb) throws IOException {
    433. BufferedImage bufferImg = null;
    434. if (!CollectionUtils.isEmpty(excelImageInputs)) {
    435. Iterator var3 = excelImageInputs.iterator();
    436. while(var3.hasNext()) {
    437. ExcelImageInput excelImageInput = (ExcelImageInput)var3.next();
    438. Sheet sheet = wb.getSheetAt(excelImageInput.getSheetIndex());
    439. if (sheet != null) {
    440. Drawing patriarch = sheet.createDrawingPatriarch();
    441. XSSFClientAnchor anchor = excelImageInput.getAnchorXlsx();
    442. anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
    443. String imagePath = excelImageInput.getImgPath();
    444. ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
    445. bufferImg = ImageIO.read(new File(imagePath));
    446. String imageType = imagePath.substring(imagePath.lastIndexOf(".") + 1, imagePath.length());
    447. ImageIO.write(bufferImg, imageType, byteArrayOut);
    448. patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), 5));
    449. }
    450. }
    451. }
    452. }
    453. private static void addCellRange(HSSFSheet sheet, List<CellRangeAddressEntity> cellRangeAddresses) {
    454. if (!CollectionUtils.isEmpty(cellRangeAddresses)) {
    455. Iterator var2 = cellRangeAddresses.iterator();
    456. while(true) {
    457. CellRangeAddressEntity cellRangeAddressEntity;
    458. CellRangeAddress cellRangeAddress;
    459. do {
    460. if (!var2.hasNext()) {
    461. return;
    462. }
    463. cellRangeAddressEntity = (CellRangeAddressEntity)var2.next();
    464. cellRangeAddress = cellRangeAddressEntity.getCellRangeAddress();
    465. sheet.addMergedRegion(cellRangeAddress);
    466. } while(CollectionUtils.isEmpty(cellRangeAddressEntity.getBorders()));
    467. for(int k = 0; k < cellRangeAddressEntity.getBorders().size(); ++k) {
    468. Border border = (Border)cellRangeAddressEntity.getBorders().get(k);
    469. if (border != null) {
    470. if ("Bottom".equals(border.getPosition())) {
    471. RegionUtil.setBorderBottom(BorderStyle.THIN, cellRangeAddress, sheet);
    472. }
    473. if ("Left".equals(border.getPosition())) {
    474. RegionUtil.setBorderLeft(BorderStyle.THIN, cellRangeAddress, sheet);
    475. }
    476. if ("Right".equals(border.getPosition())) {
    477. RegionUtil.setBorderRight(BorderStyle.THIN, cellRangeAddress, sheet);
    478. }
    479. if ("Top".equals(border.getPosition())) {
    480. RegionUtil.setBorderTop(BorderStyle.THIN, cellRangeAddress, sheet);
    481. }
    482. }
    483. }
    484. }
    485. }
    486. }
    487. private static void addCellRange(XSSFSheet sheet, List<CellRangeAddressEntity> cellRangeAddresses) {
    488. if (!CollectionUtils.isEmpty(cellRangeAddresses)) {
    489. Iterator var2 = cellRangeAddresses.iterator();
    490. while(true) {
    491. CellRangeAddressEntity cellRangeAddressEntity;
    492. CellRangeAddress cellRangeAddress;
    493. do {
    494. if (!var2.hasNext()) {
    495. return;
    496. }
    497. cellRangeAddressEntity = (CellRangeAddressEntity)var2.next();
    498. cellRangeAddress = cellRangeAddressEntity.getCellRangeAddress();
    499. sheet.addMergedRegion(cellRangeAddress);
    500. } while(CollectionUtils.isEmpty(cellRangeAddressEntity.getBorders()));
    501. for(int k = 0; k < cellRangeAddressEntity.getBorders().size(); ++k) {
    502. Border border = (Border)cellRangeAddressEntity.getBorders().get(k);
    503. if (border != null) {
    504. if ("Bottom".equals(border.getPosition())) {
    505. RegionUtil.setBorderBottom(BorderStyle.THIN, cellRangeAddress, sheet);
    506. }
    507. if ("Left".equals(border.getPosition())) {
    508. RegionUtil.setBorderLeft(BorderStyle.THIN, cellRangeAddress, sheet);
    509. }
    510. if ("Right".equals(border.getPosition())) {
    511. RegionUtil.setBorderRight(BorderStyle.THIN, cellRangeAddress, sheet);
    512. }
    513. if ("Top".equals(border.getPosition())) {
    514. RegionUtil.setBorderTop(BorderStyle.THIN, cellRangeAddress, sheet);
    515. }
    516. }
    517. }
    518. }
    519. }
    520. }
    521. private static void setAlignment(Style style, CellStyle dataStyle) {
    522. if (style != null && style.getAlignment() != null) {
    523. String horizontal = style.getAlignment().getHorizontal();
    524. if (!ObjectUtils.isEmpty(horizontal)) {
    525. if ("Left".equals(horizontal)) {
    526. dataStyle.setAlignment(HorizontalAlignment.LEFT);
    527. } else if ("Center".equals(horizontal)) {
    528. dataStyle.setAlignment(HorizontalAlignment.CENTER);
    529. } else {
    530. dataStyle.setAlignment(HorizontalAlignment.RIGHT);
    531. }
    532. }
    533. String vertical = style.getAlignment().getVertical();
    534. if (!ObjectUtils.isEmpty(vertical)) {
    535. if ("Top".equals(vertical)) {
    536. dataStyle.setVerticalAlignment(VerticalAlignment.TOP);
    537. } else if ("Center".equals(vertical)) {
    538. dataStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    539. } else if ("Bottom".equals(vertical)) {
    540. dataStyle.setVerticalAlignment(VerticalAlignment.BOTTOM);
    541. } else if ("JUSTIFY".equals(vertical)) {
    542. dataStyle.setVerticalAlignment(VerticalAlignment.JUSTIFY);
    543. } else {
    544. dataStyle.setVerticalAlignment(VerticalAlignment.DISTRIBUTED);
    545. }
    546. }
    547. String wrapText = style.getAlignment().getWrapText();
    548. if (!ObjectUtils.isEmpty(wrapText)) {
    549. dataStyle.setWrapText(true);
    550. }
    551. }
    552. }
    553. private static void setCellColor(Style style, CellStyle dataStyle) {
    554. if (style != null && style.getInterior() != null) {
    555. String color = style.getInterior().getColor();
    556. if (color == null) {
    557. color = "#FFFFFF";
    558. }
    559. Integer[] rgb = ColorUtil.hex2Rgb(color);
    560. HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
    561. HSSFPalette palette = hssfWorkbook.getCustomPalette();
    562. HSSFColor paletteColor = palette.findSimilarColor(rgb[0], rgb[1], rgb[2]);
    563. dataStyle.setFillForegroundColor(paletteColor.getIndex());
    564. dataStyle.setFillBackgroundColor(paletteColor.getIndex());
    565. if ("Solid".equals(style.getInterior().getPattern())) {
    566. dataStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    567. }
    568. }
    569. }
    570. private static int getCellRanges(int createRowIndex, List<CellRangeAddressEntity> cellRangeAddresses, int startIndex, Cell cellInfo, Style style) {
    571. if (cellInfo.getMergeAcross() != null || cellInfo.getMergeDown() != null) {
    572. CellRangeAddress cellRangeAddress = null;
    573. int length;
    574. int i;
    575. if (cellInfo.getMergeAcross() != null && cellInfo.getMergeDown() != null) {
    576. length = startIndex;
    577. if (cellInfo.getMergeAcross() != 0) {
    578. length = startIndex + cellInfo.getMergeAcross();
    579. }
    580. i = createRowIndex;
    581. if (cellInfo.getMergeDown() != 0) {
    582. i = createRowIndex + cellInfo.getMergeDown();
    583. }
    584. cellRangeAddress = new CellRangeAddress(createRowIndex, i, (short)startIndex, (short)length);
    585. } else if (cellInfo.getMergeAcross() != null && cellInfo.getMergeDown() == null) {
    586. if (cellInfo.getMergeAcross() != 0) {
    587. length = startIndex + cellInfo.getMergeAcross();
    588. cellRangeAddress = new CellRangeAddress(createRowIndex, createRowIndex, (short)startIndex, (short)length);
    589. }
    590. } else if (cellInfo.getMergeDown() != null && cellInfo.getMergeAcross() == null && cellInfo.getMergeDown() != 0) {
    591. length = createRowIndex + cellInfo.getMergeDown();
    592. cellRangeAddress = new CellRangeAddress(createRowIndex, length, (short)startIndex, (short)startIndex);
    593. }
    594. if (cellInfo.getMergeAcross() != null) {
    595. length = cellInfo.getMergeAcross();
    596. for(i = 0; i < length; ++i) {
    597. ++startIndex;
    598. }
    599. }
    600. CellRangeAddressEntity cellRangeAddressEntity = new CellRangeAddressEntity();
    601. cellRangeAddressEntity.setCellRangeAddress(cellRangeAddress);
    602. if (style != null && style.getBorders() != null) {
    603. cellRangeAddressEntity.setBorders(style.getBorders());
    604. }
    605. cellRangeAddresses.add(cellRangeAddressEntity);
    606. }
    607. return startIndex;
    608. }
    609. private static void setValue(XSSFWorkbook wb, Cell cellInfo, XSSFCell cell, Style style, CellStyle dataStyle) {
    610. if (cellInfo.getData() != null) {
    611. XSSFFont font = wb.createFont();
    612. String color;
    613. Integer[] rgb;
    614. HSSFWorkbook hssfWorkbook;
    615. HSSFPalette palette;
    616. HSSFColor paletteColor;
    617. if (style != null && style.getFont() != null) {
    618. color = style.getFont().getColor();
    619. if (color == null) {
    620. color = "#000000";
    621. }
    622. rgb = ColorUtil.hex2Rgb(color);
    623. hssfWorkbook = new HSSFWorkbook();
    624. palette = hssfWorkbook.getCustomPalette();
    625. paletteColor = palette.findSimilarColor(rgb[0], rgb[1], rgb[2]);
    626. font.setColor(paletteColor.getIndex());
    627. }
    628. if (!ObjectUtils.isEmpty(cellInfo.getData().getType()) && "Number".equals(cellInfo.getData().getType())) {
    629. cell.setCellType(CellType.NUMERIC);
    630. }
    631. if (style != null && style.getFont().getBold() > 0) {
    632. font.setBold(true);
    633. }
    634. if (style != null && !ObjectUtils.isEmpty(style.getFont().getFontName())) {
    635. font.setFontName(style.getFont().getFontName());
    636. }
    637. if (style != null && style.getFont().getSize() > 0.0D) {
    638. font.setFontHeightInPoints((short)((int)style.getFont().getSize()));
    639. }
    640. if (cellInfo.getData().getFont() != null) {
    641. if (cellInfo.getData().getFont().getBold() > 0) {
    642. font.setBold(true);
    643. }
    644. if ("Number".equals(cellInfo.getData().getType())) {
    645. cell.setCellValue((double)Float.parseFloat(cellInfo.getData().getFont().getText()));
    646. } else {
    647. cell.setCellValue(cellInfo.getData().getFont().getText());
    648. }
    649. if (!ObjectUtils.isEmpty(cellInfo.getData().getFont().getCharSet())) {
    650. font.setCharSet(Integer.valueOf(cellInfo.getData().getFont().getCharSet()));
    651. }
    652. } else if ("Number".equals(cellInfo.getData().getType())) {
    653. if (!ObjectUtils.isEmpty(cellInfo.getData().getText())) {
    654. cell.setCellValue((double)Float.parseFloat(cellInfo.getData().getText().replaceAll(",", "")));
    655. }
    656. } else {
    657. cell.setCellValue(cellInfo.getData().getText());
    658. }
    659. if (style != null && style.getNumberFormat() != null) {
    660. color = style.getFont().getColor();
    661. if (color == null) {
    662. color = "#000000";
    663. }
    664. rgb = ColorUtil.hex2Rgb(color);
    665. hssfWorkbook = new HSSFWorkbook();
    666. palette = hssfWorkbook.getCustomPalette();
    667. paletteColor = palette.findSimilarColor(rgb[0], rgb[1], rgb[2]);
    668. font.setColor(paletteColor.getIndex());
    669. if ("0%".equals(style.getNumberFormat().getFormat())) {
    670. XSSFDataFormat format = wb.createDataFormat();
    671. dataStyle.setDataFormat(format.getFormat(style.getNumberFormat().getFormat()));
    672. } else {
    673. dataStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
    674. }
    675. }
    676. dataStyle.setFont(font);
    677. }
    678. }
    679. private static void setValue(HSSFWorkbook wb, Cell cellInfo, HSSFCell cell, Style style, CellStyle dataStyle) {
    680. if (cellInfo.getData() != null) {
    681. HSSFFont font = wb.createFont();
    682. String color;
    683. Integer[] rgb;
    684. HSSFWorkbook hssfWorkbook;
    685. HSSFPalette palette;
    686. HSSFColor paletteColor;
    687. if (style != null && style.getFont() != null) {
    688. color = style.getFont().getColor();
    689. if (color == null) {
    690. color = "#000000";
    691. }
    692. rgb = ColorUtil.hex2Rgb(color);
    693. hssfWorkbook = new HSSFWorkbook();
    694. palette = hssfWorkbook.getCustomPalette();
    695. paletteColor = palette.findSimilarColor(rgb[0], rgb[1], rgb[2]);
    696. font.setColor(paletteColor.getIndex());
    697. }
    698. if (!ObjectUtils.isEmpty(cellInfo.getData().getType()) && "Number".equals(cellInfo.getData().getType())) {
    699. cell.setCellType(CellType.NUMERIC);
    700. }
    701. if (style != null && style.getFont().getBold() > 0) {
    702. font.setBold(true);
    703. }
    704. if (style != null && !ObjectUtils.isEmpty(style.getFont().getFontName())) {
    705. font.setFontName(style.getFont().getFontName());
    706. }
    707. if (style != null && style.getFont().getSize() > 0.0D) {
    708. font.setFontHeightInPoints((short)((int)style.getFont().getSize()));
    709. }
    710. if (cellInfo.getData().getFont() != null) {
    711. if (cellInfo.getData().getFont().getBold() > 0) {
    712. font.setBold(true);
    713. }
    714. if ("Number".equals(cellInfo.getData().getType())) {
    715. cell.setCellValue((double)Float.parseFloat(cellInfo.getData().getFont().getText()));
    716. } else {
    717. cell.setCellValue(cellInfo.getData().getFont().getText());
    718. }
    719. if (!ObjectUtils.isEmpty(cellInfo.getData().getFont().getCharSet())) {
    720. font.setCharSet(Integer.valueOf(cellInfo.getData().getFont().getCharSet()));
    721. }
    722. } else if ("Number".equals(cellInfo.getData().getType())) {
    723. if (!ObjectUtils.isEmpty(cellInfo.getData().getText())) {
    724. cell.setCellValue((double)Float.parseFloat(cellInfo.getData().getText().replaceAll(",", "")));
    725. }
    726. } else {
    727. cell.setCellValue(cellInfo.getData().getText());
    728. }
    729. if (style != null && style.getNumberFormat() != null) {
    730. color = style.getFont().getColor();
    731. if (color == null) {
    732. color = "#000000";
    733. }
    734. rgb = ColorUtil.hex2Rgb(color);
    735. hssfWorkbook = new HSSFWorkbook();
    736. palette = hssfWorkbook.getCustomPalette();
    737. paletteColor = palette.findSimilarColor(rgb[0], rgb[1], rgb[2]);
    738. font.setColor(paletteColor.getIndex());
    739. if ("0%".equals(style.getNumberFormat().getFormat())) {
    740. HSSFDataFormat format = wb.createDataFormat();
    741. dataStyle.setDataFormat(format.getFormat(style.getNumberFormat().getFormat()));
    742. } else {
    743. dataStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
    744. }
    745. }
    746. dataStyle.setFont(font);
    747. }
    748. }
    749. }
    1. package com.example.stu1.freemark;
    2. import com.yongjiu.dto.freemarker.input.FreemarkerInput;
    3. import org.springframework.web.bind.annotation.GetMapping;
    4. import org.springframework.web.bind.annotation.RestController;
    5. import javax.servlet.http.HttpServletResponse;
    6. import java.net.URLEncoder;
    7. import java.util.ArrayList;
    8. import java.util.HashMap;
    9. import java.util.List;
    10. import java.util.Map;
    11. /**
    12. * @Author yangcai
    13. * @create 2022/7/1 16:43
    14. */
    15. @RestController
    16. public class UserController1 {
    17. @GetMapping("/index")
    18. public void index(HttpServletResponse response) {
    19. try{
    20. String fileName = URLEncoder.encode("测试导出", "UTF-8");
    21. Map<String,Object> resultMap= getList();
    22. FreemarkerInput freemarkerInput = new FreemarkerInput();
    23. freemarkerInput.setTemplateFilePath("/templates");
    24. freemarkerInput.setTemplateName("test.ftl");
    25. freemarkerInput.setXmlTempFile(System.getProperty("java.io.tmpdir"));
    26. freemarkerInput.setFileName(fileName);
    27. freemarkerInput.setDataMap(resultMap);
    28. FreeMarkerTemplateUtil.exportImageExcelNew(response, freemarkerInput);
    29. } catch (Exception e) {
    30. e.printStackTrace();
    31. }
    32. }
    33. Map<String,Object> getList(){
    34. Map<String,Object> map = new HashMap<>();
    35. List<User> userList = new ArrayList<>();
    36. User user1 = new User();
    37. user1.setAge(26);
    38. user1.setEmail("707656893@qq.com");
    39. user1.setName("张无忌");
    40. userList.add(user1);
    41. User user2 = new User();
    42. user2.setAge(27);
    43. user2.setEmail("111111111@qq.com");
    44. user2.setName("逍遥子");
    45. userList.add(user2);
    46. User user3 = new User();
    47. user3.setAge(28);
    48. user3.setEmail("222222222@qq.com");
    49. user3.setName("乔峰");
    50. userList.add(user3);
    51. map.put("userList",userList);
    52. return map;
    53. }
    54. }

    此时生成的xlsx文件是真正的excel文件,能被office正常的打开

    poi解析excel文件

    1. public static Function<UploadExcelObject,List<Map<String, IndexDataPo>>> getExcelDataOne = uploadExcelObject->{
    2. try(FileInputStream fileInputStream = new FileInputStream(uploadExcelObject.getFileUrl())) {
    3. Workbook workbook = null;
    4. if (uploadExcelObject.getFileUrl().endsWith(".xls")) {
    5. try {
    6. workbook = new HSSFWorkbook(fileInputStream);
    7. } catch (OfficeXmlFileException e) {
    8. try {
    9. workbook = new XSSFWorkbook(fileInputStream);
    10. } catch (Exception e1) {
    11. log.error(e.getMessage());
    12. }
    13. } catch (IOException e) {
    14. throw new CommonException("109",e.getMessage());
    15. }
    16. } else if (uploadExcelObject.getFileUrl().endsWith(".xlsx")) {
    17. try {
    18. workbook = new XSSFWorkbook(fileInputStream);
    19. } catch (Exception e) {
    20. e.printStackTrace();
    21. throw new CommonException("110",e.getMessage());
    22. }
    23. }
    24. try {
    25. int sheetNo = workbook.getNumberOfSheets();
    26. List<Map<String, IndexDataPo>> list = Lists.newArrayList();
    27. log.info(String.format("此文档共有%d多少页",sheetNo));
    28. for(int i=0 ; i< sheetNo ;i++){
    29. Sheet sheet = workbook.getSheetAt(0);
    30. List<String> headerList = checkAndGetHeader(sheet,TemplateTypeEnum.ONE_DATE.getCode(),uploadExcelObject.getIndexCodeList());
    31. for (int j = 1; j < sheet.getPhysicalNumberOfRows(); j++) {
    32. XSSFRow row = (XSSFRow) sheet.getRow(j);
    33. if(row!=null) {
    34. if(isRowEmpty(row)){
    35. continue;
    36. }
    37. IndexDataPo dto = new IndexDataPo();
    38. for (int k = 0; k < sheet.getRow(1).getPhysicalNumberOfCells(); k++) {
    39. String value = null;
    40. Cell cell = row.getCell(k);
    41. if(k==0){
    42. if("".equals(cell.toString()) || cell.toString() == ""){
    43. throw new CommonException("101","没有输入时间");
    44. }
    45. if(DateUtil.isCellDateFormatted(cell)){
    46. dto.setDataDate(cell.getDateCellValue());
    47. }
    48. }else{
    49. Map<String, IndexDataPo> map = Maps.newHashMap();
    50. if(cell != null){
    51. value = getCellValue(cell);
    52. }
    53. if(StringUtils.isEmpty(value)){
    54. dto.setDataValue(null);
    55. }else{
    56. dto.setDataValue(Double.valueOf(value));
    57. }
    58. dto.setIndexCode(headerList.get(k));
    59. map.put(DateUtils.getDateLong(dto.getDataDate()), dto);
    60. list.add(map);
    61. dto = new IndexDataPo(dto.getDataDate());
    62. }
    63. }
    64. }
    65. }
    66. }
    67. return list;
    68. } catch (Exception e) {
    69. log.error(e.getMessage(),e);
    70. throw new CommonException("解析excel错误:","解析excel错误"+e.getMessage());
    71. }
    72. } catch (IOException e) {
    73. log.error(e.getMessage(),e);
    74. }
    75. return null;
    76. };

     

  • 相关阅读:
    Redis Sentinel集群管理手册
    Linux 学习笔记(8)
    在Linux服务器上部署Tornado项目
    计数排序基础思路
    SpringCloud环境搭建及入门案例
    CodeQL的自动化代码审计之路(上篇)
    c - ar 中的 “rcs“选项有什么作用?
    Ansible中的角色使用
    NPDP为什么越来越受追捧?产品经理你可知道?
    深度估计:SGBM算法应用
  • 原文地址:https://blog.csdn.net/beiduofen2011/article/details/125561027