使用Apache POI导出Excel小结

关于使用Apache POI导出Excel我大概会分三篇文章去写

导出XLS格式文档

做企业应用项目难免会有数据导出到Excel的需求,最近在使用其,并对导出Excel封装成工具类开放出来供大家参考。关于Apache POI Excel基本的概念与操作我在这里就不啰嗦了。

请大家参考如下:

在使用Apache POI导出Excel有以下限制:

  • Excel <=2003 数据限制,行(65536)*列(256)
  • Excel =2007 数据限制,行(1048576)*列(16384)

POI结构说明

包名称 说明

HSSF提供读写Microsoft Excel XLS格式档案的功能。

XSSF提供读写Microsoft Excel OOXML XLSX格式档案的功能。

SXSSF提供基于流式读写Microsoft Excel OOXML XLSX格式档案的功能(适用于大数据量)。

POI常用类说明

以HSSF为例其他的只是前缀命名变动

  • 如HSSF-->HSSFWorkbook、XSSF-->XSSFWorkbook、SXSSF-->SXSSFWorkbook

类名 说明

HSSFWorkbook Excel的文档对象

HSSFSheet Excel的表单

HSSFRow Excel的行

HSSFCell Excel的格子单元

HSSFFont Excel字体

HSSFDataFormat 格子单元的日期格式

HSSFHeader Excel文档Sheet的页眉

HSSFFooter Excel文档Sheet的页脚

HSSFCellStyle 格子单元样式

HSSFDateUtil 日期

HSSFPrintSetup 打印

HSSFErrorConstants 错误信息表

下来给大家依次展现代码:

Maven依赖配置

使用的Apache POI版本

  1. <poi.version>3.9</poi.version>
  1. <dependency>
  2. <groupId>org.apache.poi</groupId>
  3. <artifactId>poi</artifactId>
  4. <version>${poi.version}</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.apache.poi</groupId>
  8. <artifactId>poi-ooxml</artifactId>
  9. <version>${poi.version}</version>
  10. </dependency>
  11. <dependency>
  12. <groupId>org.apache.poi</groupId>
  13. <artifactId>poi-ooxml-schemas</artifactId>
  14. <version>${poi.version}</version>
  15. </dependency>

生成XLS格式Excel文档

使用于小数据量生成

  • 受Excel XLS格式文档本身限制(XLS格式文档大约处理最大数据行[65536条])
  • 基于Excel模板写入数据会引发内存溢出

注意:

  • 以下代码少ReportInternalException大家可以忽略(我们封装的一个异常类)
  • 导出的Excel同时考虑到数据的本身类型,如整数、小数、日期等
  • 第一种写入数据方式[writeExcel]方法为直接写入数据
  • 第二种写入数据方式需依次调用方法[writeExcelTitle、writeExcelData],先完成写入Excel标题与列名,再完成数据写入(或者说基于模板方式写入数据)
  • 第二种方式有内存溢出的可能性
  • 我们使用[styleMap]方法避免重复创建Excel单元格样式(否则受Excel创建样式数量限制)
  1. import org.apache.poi.hssf.usermodel.*;
  2. import org.apache.poi.hssf.util.HSSFColor;
  3. import org.apache.poi.ss.usermodel.*;
  4. import org.apache.poi.ss.util.CellRangeAddress;
  5. import javax.imageio.ImageIO;
  6. import java.io.*;
  7. import java.text.SimpleDateFormat;
  8. import java.util.Date;
  9. import java.util.LinkedHashMap;
  10. import java.util.List;
  11. import java.util.Map;
  12. /**
  13. * Excel 相关操作类(小数据量写入<=65536)
  14. */
  15. public class Excel2003Utils {
  16. private static final int DEFAULT_COLUMN_SIZE = 30;
  17. /**
  18. * 断言Excel文件写入之前的条件
  19. *
  20. * @param directory 目录
  21. * @param fileName 文件名
  22. * @return file
  23. * @throws IOException
  24. */
  25. private static File assertFile(String directory, String fileName) throws IOException {
  26. File tmpFile = new File(directory + File.separator + fileName + ".xls");
  27. if (tmpFile.exists()) {
  28. if (tmpFile.isDirectory()) {
  29. throw new IOException("File '" + tmpFile + "' exists but is a directory");
  30. }
  31. if (!tmpFile.canWrite()) {
  32. throw new IOException("File '" + tmpFile + "' cannot be written to");
  33. }
  34. } else {
  35. File parent = tmpFile.getParentFile();
  36. if (parent != null) {
  37. if (!parent.mkdirs() && !parent.isDirectory()) {
  38. throw new IOException("Directory '" + parent + "' could not be created");
  39. }
  40. }
  41. }
  42. return tmpFile;
  43. }
  44. /**
  45. * 日期转化为字符串,格式为yyyy-MM-dd HH:mm:ss
  46. */
  47. private static String getCnDate(Date date) {
  48. String format = "yyyy-MM-dd HH:mm:ss";
  49. SimpleDateFormat sdf = new SimpleDateFormat(format);
  50. return sdf.format(date);
  51. }
  52. /**
  53. * Excel 导出,POI实现
  54. *
  55. * @param fileName 文件名
  56. * @param sheetName sheet页名称
  57. * @param columnNames 表头列表名
  58. * @param sheetTitle sheet页Title
  59. * @param objects 目标数据集
  60. */
  61. public static File writeExcel(String directory, String fileName, String sheetName, List<String> columnNames,
  62. String sheetTitle, List<List<Object>> objects, boolean append) throws ReportInternalException, IOException {
  63. File tmpFile = assertFile(directory, fileName);
  64. return exportExcel(tmpFile, sheetName, columnNames, sheetTitle, objects, append);
  65. }
  66. /**
  67. * Excel 导出,POI实现,先写入Excel标题,与writeExcelData配合使用
  68. * 先使用writeExcelTitle再使用writeExcelData
  69. *
  70. * @param directory 目录
  71. * @param fileName 文件名
  72. * @param sheetName sheetName
  73. * @param columnNames 列名集合
  74. * @param sheetTitle 表格标题
  75. * @param append 是否在现有的文件追加
  76. * @return file
  77. * @throws ReportInternalException
  78. * @throws IOException
  79. */
  80. public static File writeExcelTitle(String directory, String fileName, String sheetName, List<String> columnNames,
  81. String sheetTitle, boolean append) throws ReportInternalException, IOException {
  82. File tmpFile = assertFile(directory, fileName);
  83. return exportExcelTitle(tmpFile, sheetName, columnNames, sheetTitle, append);
  84. }
  85. /**
  86. * Excel 导出,POI实现,写入Excel数据行列,与writeExcelTitle配合使用
  87. * 先使用writeExcelTitle再使用writeExcelData
  88. *
  89. * @param directory 目录
  90. * @param fileName 文件名
  91. * @param sheetName sheetName
  92. * @param objects 数据信息
  93. * @return file
  94. * @throws ReportInternalException
  95. * @throws IOException
  96. */
  97. public static File writeExcelData(String directory, String fileName, String sheetName, List<List<Object>> objects)
  98. throws ReportInternalException, IOException {
  99. File tmpFile = assertFile(directory, fileName);
  100. return exportExcelData(tmpFile, sheetName, objects);
  101. }
  102. /**
  103. * 导出字符串数据
  104. *
  105. * @param file 文件名
  106. * @param columnNames 表头
  107. * @param sheetTitle sheet页Title
  108. * @param append 是否追加写文件
  109. * @return file
  110. * @throws ReportInternalException
  111. */
  112. private static File exportExcelTitle(File file, String sheetName, List<String> columnNames,
  113. String sheetTitle, boolean append) throws ReportInternalException, IOException {
  114. // 声明一个工作薄
  115. Workbook workBook;
  116. if (file.exists() && append) {
  117. // 声明一个工作薄
  118. workBook = new HSSFWorkbook(new FileInputStream(file));
  119. } else {
  120. workBook = new HSSFWorkbook();
  121. }
  122. Map<String, CellStyle> cellStyleMap = styleMap(workBook);
  123. // 表头样式
  124. CellStyle headStyle = cellStyleMap.get("head");
  125. // 生成一个表格
  126. Sheet sheet = workBook.getSheet(sheetName);
  127. if (sheet == null) {
  128. sheet = workBook.createSheet(sheetName);
  129. }
  130. //最新Excel列索引,从0开始
  131. int lastRowIndex = sheet.getLastRowNum();
  132. if (lastRowIndex > 0) {
  133. lastRowIndex++;
  134. }
  135. // 设置表格默认列宽度
  136. sheet.setDefaultColumnWidth(DEFAULT_COLUMN_SIZE);
  137. // 合并单元格
  138. sheet.addMergedRegion(new CellRangeAddress(lastRowIndex, lastRowIndex, 0, columnNames.size() - 1));
  139. // 产生表格标题行
  140. Row rowMerged = sheet.createRow(lastRowIndex);
  141. lastRowIndex++;
  142. Cell mergedCell = rowMerged.createCell(0);
  143. mergedCell.setCellStyle(headStyle);
  144. mergedCell.setCellValue(new HSSFRichTextString(sheetTitle));
  145. // 产生表格表头列标题行
  146. Row row = sheet.createRow(lastRowIndex);
  147. for (int i = 0; i < columnNames.size(); i++) {
  148. Cell cell = row.createCell(i);
  149. cell.setCellStyle(headStyle);
  150. RichTextString text = new HSSFRichTextString(columnNames.get(i));
  151. cell.setCellValue(text);
  152. }
  153. try {
  154. OutputStream ops = new FileOutputStream(file);
  155. workBook.write(ops);
  156. ops.flush();
  157. ops.close();
  158. } catch (IOException e) {
  159. throw new ReportInternalException(e);
  160. }
  161. return file;
  162. }
  163. /**
  164. * 导出字符串数据
  165. *
  166. * @param file 文件名
  167. * @param objects 目标数据
  168. * @return
  169. * @throws ReportInternalException
  170. */
  171. private static File exportExcelData(File file, String sheetName, List<List<Object>> objects) throws ReportInternalException, IOException {
  172. // 声明一个工作薄
  173. Workbook workBook;
  174. if (file.exists()) {
  175. // 声明一个工作薄
  176. workBook = new HSSFWorkbook(new FileInputStream(file));
  177. } else {
  178. workBook = new HSSFWorkbook();
  179. }
  180. Map<String, CellStyle> cellStyleMap = styleMap(workBook);
  181. // 正文样式
  182. CellStyle contentStyle = cellStyleMap.get("content");
  183. //正文整数样式
  184. CellStyle contentIntegerStyle = cellStyleMap.get("integer");
  185. //正文带小数整数样式
  186. CellStyle contentDoubleStyle = cellStyleMap.get("double");
  187. // 生成一个表格
  188. Sheet sheet = workBook.getSheet(sheetName);
  189. if (sheet == null) {
  190. sheet = workBook.createSheet(sheetName);
  191. }
  192. //最新Excel列索引,从0开始
  193. int lastRowIndex = sheet.getLastRowNum();
  194. if (lastRowIndex > 0) {
  195. lastRowIndex++;
  196. }
  197. // 设置表格默认列宽度
  198. sheet.setDefaultColumnWidth(DEFAULT_COLUMN_SIZE);
  199. // 遍历集合数据,产生数据行,前两行为标题行与表头行
  200. for (List<Object> dataRow : objects) {
  201. Row row = sheet.createRow(lastRowIndex);
  202. lastRowIndex++;
  203. for (int j = 0; j < dataRow.size(); j++) {
  204. Cell contentCell = row.createCell(j);
  205. Object dataObject = dataRow.get(j);
  206. if (dataObject != null) {
  207. if (dataObject instanceof Integer) {
  208. contentCell.setCellStyle(contentIntegerStyle);
  209. contentCell.setCellValue(Integer.parseInt(dataObject.toString()));
  210. } else if (dataObject instanceof Double) {
  211. contentCell.setCellStyle(contentDoubleStyle);
  212. contentCell.setCellValue(Double.parseDouble(dataObject.toString()));
  213. } else if (dataObject instanceof Long && dataObject.toString().length() == 13) {
  214. contentCell.setCellStyle(contentStyle);
  215. contentCell.setCellValue(getCnDate(new Date(Long.parseLong(dataObject.toString()))));
  216. } else if (dataObject instanceof Date) {
  217. contentCell.setCellStyle(contentStyle);
  218. contentCell.setCellValue(getCnDate((Date) dataObject));
  219. } else {
  220. contentCell.setCellStyle(contentStyle);
  221. contentCell.setCellValue(dataObject.toString());
  222. }
  223. } else {
  224. contentCell.setCellStyle(contentStyle);
  225. // 设置单元格内容为字符型
  226. contentCell.setCellValue("");
  227. }
  228. }
  229. }
  230. try {
  231. OutputStream ops = new FileOutputStream(file);
  232. workBook.write(ops);
  233. ops.flush();
  234. ops.close();
  235. } catch (IOException e) {
  236. throw new ReportInternalException(e);
  237. }
  238. return file;
  239. }
  240. /**
  241. * 导出字符串数据
  242. *
  243. * @param file 文件名
  244. * @param columnNames 表头
  245. * @param sheetTitle sheet页Title
  246. * @param objects 目标数据
  247. * @param append 是否追加写文件
  248. * @return
  249. * @throws ReportInternalException
  250. */
  251. private static File exportExcel(File file, String sheetName, List<String> columnNames,
  252. String sheetTitle, List<List<Object>> objects, boolean append) throws ReportInternalException, IOException {
  253. // 声明一个工作薄
  254. Workbook workBook;
  255. if (file.exists() && append) {
  256. // 声明一个工作薄
  257. workBook = new HSSFWorkbook(new FileInputStream(file));
  258. } else {
  259. workBook = new HSSFWorkbook();
  260. }
  261. Map<String, CellStyle> cellStyleMap = styleMap(workBook);
  262. // 表头样式
  263. CellStyle headStyle = cellStyleMap.get("head");
  264. // 正文样式
  265. CellStyle contentStyle = cellStyleMap.get("content");
  266. //正文整数样式
  267. CellStyle contentIntegerStyle = cellStyleMap.get("integer");
  268. //正文带小数整数样式
  269. CellStyle contentDoubleStyle = cellStyleMap.get("double");
  270. // 生成一个表格
  271. Sheet sheet = workBook.getSheet(sheetName);
  272. if (sheet == null) {
  273. sheet = workBook.createSheet(sheetName);
  274. }
  275. //最新Excel列索引,从0开始
  276. int lastRowIndex = sheet.getLastRowNum();
  277. if (lastRowIndex > 0) {
  278. lastRowIndex++;
  279. }
  280. // 设置表格默认列宽度
  281. sheet.setDefaultColumnWidth(DEFAULT_COLUMN_SIZE);
  282. // 合并单元格
  283. sheet.addMergedRegion(new CellRangeAddress(lastRowIndex, lastRowIndex, 0, columnNames.size() - 1));
  284. // 产生表格标题行
  285. Row rowMerged = sheet.createRow(lastRowIndex);
  286. lastRowIndex++;
  287. Cell mergedCell = rowMerged.createCell(0);
  288. mergedCell.setCellStyle(headStyle);
  289. mergedCell.setCellValue(new HSSFRichTextString(sheetTitle));
  290. // 产生表格表头列标题行
  291. Row row = sheet.createRow(lastRowIndex);
  292. lastRowIndex++;
  293. for (int i = 0; i < columnNames.size(); i++) {
  294. Cell cell = row.createCell(i);
  295. cell.setCellStyle(headStyle);
  296. RichTextString text = new HSSFRichTextString(columnNames.get(i));
  297. cell.setCellValue(text);
  298. }
  299. // 遍历集合数据,产生数据行,前两行为标题行与表头行
  300. for (List<Object> dataRow : objects) {
  301. row = sheet.createRow(lastRowIndex);
  302. lastRowIndex++;
  303. for (int j = 0; j < dataRow.size(); j++) {
  304. Cell contentCell = row.createCell(j);
  305. Object dataObject = dataRow.get(j);
  306. if (dataObject != null) {
  307. if (dataObject instanceof Integer) {
  308. contentCell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
  309. contentCell.setCellStyle(contentIntegerStyle);
  310. contentCell.setCellValue(Integer.parseInt(dataObject.toString()));
  311. } else if (dataObject instanceof Double) {
  312. contentCell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
  313. contentCell.setCellStyle(contentDoubleStyle);
  314. contentCell.setCellValue(Double.parseDouble(dataObject.toString()));
  315. } else if (dataObject instanceof Long && dataObject.toString().length() == 13) {
  316. contentCell.setCellType(HSSFCell.CELL_TYPE_STRING);
  317. contentCell.setCellStyle(contentStyle);
  318. contentCell.setCellValue(getCnDate(new Date(Long.parseLong(dataObject.toString()))));
  319. } else if (dataObject instanceof Date) {
  320. contentCell.setCellType(HSSFCell.CELL_TYPE_STRING);
  321. contentCell.setCellStyle(contentStyle);
  322. contentCell.setCellValue(getCnDate((Date) dataObject));
  323. } else {
  324. contentCell.setCellType(HSSFCell.CELL_TYPE_STRING);
  325. contentCell.setCellStyle(contentStyle);
  326. contentCell.setCellValue(dataObject.toString());
  327. }
  328. } else {
  329. contentCell.setCellStyle(contentStyle);
  330. // 设置单元格内容为字符型
  331. contentCell.setCellValue("");
  332. }
  333. }
  334. }
  335. try {
  336. OutputStream ops = new FileOutputStream(file);
  337. workBook.write(ops);
  338. ops.flush();
  339. ops.close();
  340. } catch (IOException e) {
  341. throw new ReportInternalException(e);
  342. }
  343. return file;
  344. }
  345. /**
  346. * 创建单元格表头样式
  347. *
  348. * @param workbook 工作薄
  349. */
  350. private static CellStyle createCellHeadStyle(Workbook workbook) {
  351. CellStyle style = workbook.createCellStyle();
  352. // 设置边框样式
  353. style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  354. style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
  355. style.setBorderRight(HSSFCellStyle.BORDER_THIN);
  356. style.setBorderTop(HSSFCellStyle.BORDER_THIN);
  357. //设置对齐样式
  358. style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  359. // 生成字体
  360. Font font = workbook.createFont();
  361. // 表头样式
  362. style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
  363. style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
  364. font.setFontHeightInPoints((short) 12);
  365. font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  366. // 把字体应用到当前的样式
  367. style.setFont(font);
  368. return style;
  369. }
  370. /**
  371. * 创建单元格正文样式
  372. *
  373. * @param workbook 工作薄
  374. */
  375. private static CellStyle createCellContentStyle(Workbook workbook) {
  376. CellStyle style = workbook.createCellStyle();
  377. // 设置边框样式
  378. style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  379. style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
  380. style.setBorderRight(HSSFCellStyle.BORDER_THIN);
  381. style.setBorderTop(HSSFCellStyle.BORDER_THIN);
  382. //设置对齐样式
  383. style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  384. // 生成字体
  385. Font font = workbook.createFont();
  386. // 正文样式
  387. style.setFillPattern(HSSFCellStyle.NO_FILL);
  388. style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
  389. font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
  390. // 把字体应用到当前的样式
  391. style.setFont(font);
  392. return style;
  393. }
  394. /**
  395. * 单元格样式(Integer)列表
  396. */
  397. private static CellStyle createCellContent4IntegerStyle(Workbook workbook) {
  398. CellStyle style = workbook.createCellStyle();
  399. // 设置边框样式
  400. style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  401. style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
  402. style.setBorderRight(HSSFCellStyle.BORDER_THIN);
  403. style.setBorderTop(HSSFCellStyle.BORDER_THIN);
  404. //设置对齐样式
  405. style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  406. // 生成字体
  407. Font font = workbook.createFont();
  408. // 正文样式
  409. style.setFillPattern(HSSFCellStyle.NO_FILL);
  410. style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
  411. font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
  412. // 把字体应用到当前的样式
  413. style.setFont(font);
  414. style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));//数据格式只显示整数
  415. return style;
  416. }
  417. /**
  418. * 单元格样式(Double)列表
  419. */
  420. private static CellStyle createCellContent4DoubleStyle(Workbook workbook) {
  421. CellStyle style = workbook.createCellStyle();
  422. // 设置边框样式
  423. style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  424. style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
  425. style.setBorderRight(HSSFCellStyle.BORDER_THIN);
  426. style.setBorderTop(HSSFCellStyle.BORDER_THIN);
  427. //设置对齐样式
  428. style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  429. // 生成字体
  430. Font font = workbook.createFont();
  431. // 正文样式
  432. style.setFillPattern(HSSFCellStyle.NO_FILL);
  433. style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
  434. font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
  435. // 把字体应用到当前的样式
  436. style.setFont(font);
  437. style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//保留两位小数点
  438. return style;
  439. }
  440. /**
  441. * 单元格样式列表
  442. */
  443. private static Map<String, CellStyle> styleMap(Workbook workbook) {
  444. Map<String, CellStyle> styleMap = new LinkedHashMap<>();
  445. styleMap.put("head", createCellHeadStyle(workbook));
  446. styleMap.put("content", createCellContentStyle(workbook));
  447. styleMap.put("integer", createCellContent4IntegerStyle(workbook));
  448. styleMap.put("double", createCellContent4DoubleStyle(workbook));
  449. return styleMap;
  450. }
  451. }
使用例子
  1. import java.io.IOException;
  2. import java.sql.Date;
  3. import java.util.LinkedList;
  4. import java.util.List;
  5. /**
  6. * Excel2003Test
  7. * Created by jianwei.zhou on 2016/11/9.
  8. */
  9. public class Excel2003Test {
  10. public static void main(String[] args) throws IOException {
  11. String sheetName = "测试Excel格式";
  12. String sheetTitle = "测试Excel格式";
  13. List<String> columnNames = new LinkedList<>();
  14. columnNames.add("日期-String");
  15. columnNames.add("日期-Date");
  16. columnNames.add("时间戳-Long");
  17. columnNames.add("客户编码");
  18. columnNames.add("整数");
  19. columnNames.add("带小数的正数");
  20. //写入标题--第二种方式
  21. Excel2003Utils.writeExcelTitle("E:\\temp", "a", sheetName, columnNames, sheetTitle, false);
  22. List<List<Object>> objects = new LinkedList<>();
  23. for (int i = 0; i < 1000; i++) {
  24. List<Object> dataA = new LinkedList<>();
  25. dataA.add("2016-09-05 17:27:25");
  26. dataA.add(new Date(1451036631012L));
  27. dataA.add(1451036631012L);
  28. dataA.add("000628");
  29. dataA.add(i);
  30. dataA.add(1.323 + i);
  31. objects.add(dataA);
  32. }
  33. try {
  34. //写入数据--第二种方式
  35. Excel2003Utils.writeExcelData("E:\\temp", "a", sheetName, objects);
  36. //直接写入数据--第一种方式
  37. Excel2003Utils.writeExcel("E:\\temp", "a", sheetName, columnNames, sheetTitle, objects, false);
  38. } catch (Exception e) {
  39. e.printStackTrace();
  40. }
  41. }
  42. }
  43. from: http://www.jianshu.com/p/e5e1d82a3775

使用Apache POI导出Excel小结--导出XLS格式文档的更多相关文章

  1. apache POI 操作excel<导入导出>

    1.首先导入maven依赖 <!-- POI核心依赖 --> <dependency> <groupId>org.apache.poi</groupId> ...

  2. PHP 导出 Excel 兼容 CSV XlS格式

    class ExcelRead { /** * 获取Excel文件内容 * @param $file * @return mixed * @throws PHPExcel_Reader_Excepti ...

  3. 关于poi导出excel方式HSSFWorkbook(xls).XSSFWorkbook(xlsx).SXSSFWorkbook.csv的总结

    1.HSSFWorkbook(xls) import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermo ...

  4. 【原创】POI操作Excel导入导出工具类ExcelUtil

    关于本类线程安全性的解释: 多数工具方法不涉及共享变量问题,至于添加合并单元格方法addMergeArea,使用ThreadLocal变量存储合并数据,ThreadLocal内部借用Thread.Th ...

  5. SpringBoot集成文件 - 集成POI之Excel导入导出

    Apache POI 是用Java编写的免费开源的跨平台的 Java API,Apache POI提供API给Java程序对Microsoft Office格式档案读和写的功能.本文主要介绍通过Spr ...

  6. Java开发小技巧(六):使用Apache POI读取Excel

    前言 在数据仓库中,ETL最基础的步骤就是从数据源抽取所需的数据,这里所说的数据源并非仅仅是指数据库,还包括excel.csv.xml等各种类型的数据接口文件,而这些文件中的数据不一定是结构化存储的, ...

  7. 项目一:第四天 1、快递员的条件分页查询-noSession,条件查询 2、快递员删除(逻辑删除) 3、基于Apache POI实现批量导入区域数据 a)Jquery OCUpload上传文件插件使用 b)Apache POI读取excel文件数据

    1. 快递员的条件分页查询-noSession,条件查询 2. 快递员删除(逻辑删除) 3. 基于Apache POI实现批量导入区域数据 a) Jquery OCUpload上传文件插件使用 b) ...

  8. 利用Apache POI操作Excel

    最近在做接口,有个功能是利用Excel导入汽车发动机所需零件信息到线上系统中.简单回顾一下之前学过的用java操作Excel. 1.maven配置Apache POI pom.xml中配置POIjar ...

  9. 数据库数据怎样导出成Excle表格或Word文档?

    数据导出:将数据库的数据导出成Excel工作表或Word文档 方法:将一个泛型集合导出出去 主要使用: SaveFileDialog StreamWriter 导出代码: private void b ...

随机推荐

  1. 对list对象进行排序

    List<LjlSevOrdersVO> list = ljlSevOrdersService.findSevForOrders(ljlSevOrdersVO); //查出所有是自愿者的订 ...

  2. http通信过程中,Web浏览器与Web服务器之间将完成下列7个步骤

    http通信过程中,Web浏览器与Web服务器之间将完成下列7个步骤: (1)    建立TCP连接 在HTTP工作开始之前,Web浏览器首先要通过网络与Web服务器建立连接,该连接是通过TCP来完成 ...

  3. LockSupport学习

    LockSupport工具类定义了一组的公共静态方法,这些方法提供了最基本的线程阻塞和唤醒功能.Java锁和同步器框架的核心工具类AQS:AbstractQueueSynchronizer,就是通过调 ...

  4. C# Merge into的使用详解

    Merge是一个非常有用的功能,类似于Mysql里的insert into on duplicate key. Oracle在9i引入了merge命令, 通过这个merge你能够在一个SQL语句中对一 ...

  5. Linux下几个命令的技巧

    Ctrl的组合键+a,移动到一行命令的首部+e,移动到一行命令的尾部+左右键,以单词为单位左右移动+u,删除光标之前的所有内容+k,删除光标之后的所有内容Alt+.为引用上一个命令的最后一个参数 还有 ...

  6. vue2.0使用watch监听对象属性

    二话不说直接代码,找了一个百度都没找到.... var head=new Vue({ data:{ checkBoxState:{//监听设置开关勾选状态 notice:true, sound:tru ...

  7. 我一直记不住的vim用法

    一.多行编辑进入visual block模式一般模式下Crtl+v组合键以块的形式选中待编辑的文本 进入visual line模式一般模式下大写V以行的形式选中待编辑的文本 上述两种模式的复制用y,删 ...

  8. 【剑指offer】面试题 11. 旋转数组的最小数字

    面试题 11. 旋转数组的最小数字 题目描述 题目:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4, ...

  9. 转:windbg常用命令

  10. shell 执行结果赋给变量

    #将pwd的执行结果放到变量value中保存, value=$(pwd) 另一种方法: value=`pwd`