参考原文:

https://www.cnblogs.com/yizhang/p/7244917.html

我改:

  1. package test;
  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.io.OutputStream;
  8. import java.text.SimpleDateFormat;
  9. import java.util.ArrayList;
  10. import java.util.Date;
  11. import java.util.List;
  12.  
  13. import org.apache.poi.hssf.usermodel.HSSFCell;
  14. import org.apache.poi.hssf.usermodel.HSSFDateUtil;
  15. import org.apache.poi.hssf.usermodel.HSSFFont;
  16. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  17. import org.apache.poi.ss.usermodel.Cell;
  18. import org.apache.poi.ss.usermodel.CellStyle;
  19. import org.apache.poi.ss.usermodel.DataFormat;
  20. import org.apache.poi.ss.usermodel.Font;
  21. import org.apache.poi.ss.usermodel.Row;
  22. import org.apache.poi.ss.usermodel.Sheet;
  23. import org.apache.poi.ss.usermodel.Workbook;
  24. import org.apache.poi.ss.util.CellRangeAddress;
  25. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  26.  
  27. /**
  28. *
  29. * Excel 工具类
  30. *
  31. * @author zhangyi
  32. * @version 1.0 2016/01/27
  33. *
  34. */
  35. public class ExcelUtil {
  36.  
  37. private Workbook workbook;
  38. private OutputStream os;
  39. private String pattern;// 日期格式
  40.  
  41. public void setPattern(String pattern) {
  42. this.pattern = pattern;
  43. }
  44.  
  45. public ExcelUtil(Workbook workboook) {
  46. this.workbook = workboook;
  47. }
  48.  
  49. public ExcelUtil(InputStream is, String version) throws FileNotFoundException, IOException {
  50. if ("2003".equals(version)) {
  51. workbook = new HSSFWorkbook(is);
  52. } else {
  53. workbook = new XSSFWorkbook(is);
  54. }
  55. }
  56.  
  57. public String toString() {
  58.  
  59. return "共有 " + getSheetCount() + "个sheet 页!";
  60. }
  61.  
  62. public String toString(int sheetIx) throws IOException {
  63.  
  64. return "第 " + (sheetIx + 1) + "个sheet 页,名称: " + getSheetName(sheetIx) + ",共 " + getRowCount(sheetIx) + "行!";
  65. }
  66.  
  67. /**
  68. *
  69. * 根据后缀判断是否为 Excel 文件,后缀匹配xls和xlsx
  70. *
  71. * @param pathname
  72. * @return
  73. *
  74. */
  75. public static boolean isExcel(String pathname) {
  76. if (pathname == null) {
  77. return false;
  78. }
  79. return pathname.endsWith(".xls") || pathname.endsWith(".xlsx");
  80. }
  81.  
  82. /**
  83. *
  84. * 读取 Excel 第一页所有数据
  85. *
  86. * @return
  87. * @throws Exception
  88. *
  89. */
  90. public List<List<String>> read() throws Exception {
  91. return read(0, 0, getRowCount(0) - 1);
  92. }
  93.  
  94. /**
  95. *
  96. * 读取指定sheet 页所有数据
  97. *
  98. * @param sheetIx
  99. * 指定 sheet 页,从 0 开始
  100. * @return
  101. * @throws Exception
  102. */
  103. public List<List<String>> read(int sheetIx) throws Exception {
  104. return read(sheetIx, 0, getRowCount(sheetIx) - 1);
  105. }
  106.  
  107. /**
  108. *
  109. * 读取指定sheet 页指定行数据
  110. *
  111. * @param sheetIx
  112. * 指定 sheet 页,从 0 开始
  113. * @param start
  114. * 指定开始行,从 0 开始
  115. * @param end
  116. * 指定结束行,从 0 开始
  117. * @return
  118. * @throws Exception
  119. */
  120. public List<List<String>> read(int sheetIx, int start, int end) throws Exception {
  121. Sheet sheet = workbook.getSheetAt(sheetIx);
  122. List<List<String>> list = new ArrayList<List<String>>();
  123.  
  124. if (end > getRowCount(sheetIx)) {
  125. end = getRowCount(sheetIx);
  126. }
  127.  
  128. int cols = sheet.getRow(0).getLastCellNum(); // 第一行总列数
  129.  
  130. for (int i = start; i <= end; i++) {
  131. List<String> rowList = new ArrayList<String>();
  132. Row row = sheet.getRow(i);
  133. for (int j = 0; j < cols; j++) {
  134. if (row == null) {
  135. rowList.add(null);
  136. continue;
  137. }
  138. rowList.add(getCellValueToString(row.getCell(j)));
  139. }
  140. list.add(rowList);
  141. }
  142.  
  143. return list;
  144. }
  145.  
  146. /**
  147. *
  148. * 将数据写入到 Excel 默认第一页中,从第1行开始写入
  149. *
  150. * @param rowData
  151. * 数据
  152. * @return
  153. * @throws IOException
  154. *
  155. */
  156. public boolean write(List<List<String>> rowData) throws IOException {
  157. return write(0, rowData, 0);
  158. }
  159.  
  160. /**
  161. *
  162. * 将数据写入到 Excel 新创建的 Sheet 页
  163. *
  164. * @param rowData
  165. * 数据
  166. * @param sheetName
  167. * 长度为1-31,不能包含后面任一字符: :\ / ? * [ ]
  168. * @return
  169. * @throws IOException
  170. */
  171. public boolean write(List<List<String>> rowData, String sheetName, boolean isNewSheet) throws IOException {
  172. Sheet sheet = null;
  173. if (isNewSheet) {
  174. sheet = workbook.createSheet(sheetName);
  175. } else {
  176. sheet = workbook.createSheet();
  177. }
  178. int sheetIx = workbook.getSheetIndex(sheet);
  179. return write(sheetIx, rowData, 0);
  180. }
  181.  
  182. /**
  183. *
  184. * 将数据追加到sheet页最后
  185. *
  186. * @param rowData
  187. * 数据
  188. * @param sheetIx
  189. * 指定 Sheet 页,从 0 开始
  190. * @param isAppend
  191. * 是否追加,true 追加,false 重置sheet再添加
  192. * @return
  193. * @throws IOException
  194. */
  195. public boolean write(int sheetIx, List<List<String>> rowData, boolean isAppend) throws IOException {
  196. if (isAppend) {
  197. return write(sheetIx, rowData, getRowCount(sheetIx));
  198. } else {// 清空再添加
  199. clearSheet(sheetIx);
  200. return write(sheetIx, rowData, 0);
  201. }
  202. }
  203.  
  204. /**
  205. *
  206. * 将数据写入到 Excel 指定 Sheet 页指定开始行中,指定行后面数据向后移动
  207. *
  208. * @param rowData
  209. * 数据
  210. * @param sheetIx
  211. * 指定 Sheet 页,从 0 开始
  212. * @param startRow
  213. * 指定开始行,从 0 开始
  214. * @return
  215. * @throws IOException
  216. */
  217. public boolean write(int sheetIx, List<List<String>> rowData, int startRow) throws IOException {
  218. Sheet sheet = workbook.getSheetAt(sheetIx);
  219. int dataSize = rowData.size();
  220. if (getRowCount(sheetIx) > 0) {// 如果小于等于0,则一行都不存在
  221. sheet.shiftRows(startRow, getRowCount(sheetIx), dataSize);
  222. }
  223. for (int i = 0; i < dataSize; i++) {
  224. Row row = sheet.createRow(i + startRow);
  225. for (int j = 0; j < rowData.get(i).size(); j++) {
  226. Cell cell = row.createCell(j);
  227. cell.setCellValue(rowData.get(i).get(j) + "");
  228. }
  229. }
  230. return true;
  231. }
  232.  
  233. /**
  234. *
  235. * 设置cell 样式
  236. *
  237. * @param sheetIx
  238. * 指定 Sheet 页,从 0 开始
  239. * @param colIndex
  240. * 指定列,从 0 开始
  241. * @return
  242. * @throws IOException
  243. */
  244. public boolean setStyle(int sheetIx, int rowIndex, int colIndex, CellStyle style) throws IOException {
  245. Sheet sheet = workbook.getSheetAt(sheetIx);
  246. // sheet.autoSizeColumn(colIndex, true);// 设置列宽度自适应
  247. sheet.setColumnWidth(colIndex, 4000);
  248.  
  249. Cell cell = sheet.getRow(rowIndex).getCell(colIndex);
  250. cell.setCellStyle(style);
  251.  
  252. return true;
  253. }
  254.  
  255. /**
  256. *
  257. * 设置样式
  258. *
  259. * @param type
  260. * 1:标题 2:第一行
  261. * @return
  262. */
  263. public CellStyle makeStyle(int type) {
  264. CellStyle style = workbook.createCellStyle();
  265.  
  266. DataFormat format = workbook.createDataFormat();
  267. style.setDataFormat(format.getFormat("@"));// // 内容样式 设置单元格内容格式是文本
  268. style.setAlignment(CellStyle.ALIGN_CENTER);// 内容居中
  269.  
  270. // style.setBorderTop(CellStyle.BORDER_THIN);// 边框样式
  271. // style.setBorderRight(CellStyle.BORDER_THIN);
  272. // style.setBorderBottom(CellStyle.BORDER_THIN);
  273. // style.setBorderLeft(CellStyle.BORDER_THIN);
  274.  
  275. Font font = workbook.createFont();// 文字样式
  276.  
  277. if (type == 1) {
  278. // style.setFillForegroundColor(HSSFColor.LIGHT_BLUE.index);//颜色样式
  279. // 前景颜色
  280. // style.setFillBackgroundColor(HSSFColor.LIGHT_BLUE.index);//背景色
  281. // style.setFillPattern(CellStyle.ALIGN_FILL);// 填充方式
  282. // font.setBold(true);
  283. font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
  284. font.setFontHeight((short) 500);
  285. }
  286.  
  287. if (type == 2) {
  288. font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
  289. font.setFontHeight((short) 300);
  290. }
  291.  
  292. style.setFont(font);
  293.  
  294. return style;
  295. }
  296.  
  297. /**
  298. *
  299. * 合并单元格
  300. *
  301. * @param sheetIx
  302. * 指定 Sheet 页,从 0 开始
  303. * @param firstRow
  304. * 开始行
  305. * @param lastRow
  306. * 结束行
  307. * @param firstCol
  308. * 开始列
  309. * @param lastCol
  310. * 结束列
  311. */
  312. public void region(int sheetIx, int firstRow, int lastRow, int firstCol, int lastCol) {
  313. Sheet sheet = workbook.getSheetAt(sheetIx);
  314. sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, firstCol, lastCol));
  315. }
  316.  
  317. /**
  318. *
  319. * 指定行是否为空
  320. *
  321. * @param sheetIx
  322. * 指定 Sheet 页,从 0 开始
  323. * @param rowIndex
  324. * 指定开始行,从 0 开始
  325. * @return true 不为空,false 不行为空
  326. * @throws IOException
  327. */
  328. public boolean isRowNull(int sheetIx, int rowIndex) throws IOException {
  329. Sheet sheet = workbook.getSheetAt(sheetIx);
  330. return sheet.getRow(rowIndex) == null;
  331. }
  332.  
  333. /**
  334. *
  335. * 创建行,若行存在,则清空
  336. *
  337. * @param sheetIx
  338. * 指定 sheet 页,从 0 开始
  339. * @param rownum
  340. * 指定创建行,从 0 开始
  341. * @return
  342. * @throws IOException
  343. */
  344. public boolean createRow(int sheetIx, int rowIndex) throws IOException {
  345. Sheet sheet = workbook.getSheetAt(sheetIx);
  346. sheet.createRow(rowIndex);
  347. return true;
  348. }
  349.  
  350. /**
  351. *
  352. * 指定单元格是否为空
  353. *
  354. * @param sheetIx
  355. * 指定 Sheet 页,从 0 开始
  356. * @param rowIndex
  357. * 指定开始行,从 0 开始
  358. * @param colIndex
  359. * 指定开始列,从 0 开始
  360. * @return true 行不为空,false 行为空
  361. * @throws IOException
  362. */
  363. public boolean isCellNull(int sheetIx, int rowIndex, int colIndex) throws IOException {
  364. Sheet sheet = workbook.getSheetAt(sheetIx);
  365. if (!isRowNull(sheetIx, rowIndex)) {
  366. return false;
  367. }
  368. Row row = sheet.getRow(rowIndex);
  369. return row.getCell(colIndex) == null;
  370. }
  371.  
  372. /**
  373. *
  374. * 创建单元格
  375. *
  376. * @param sheetIx
  377. * 指定 sheet 页,从 0 开始
  378. * @param rowIndex
  379. * 指定行,从 0 开始
  380. * @param colIndex
  381. * 指定创建列,从 0 开始
  382. * @return true 列为空,false 行不为空
  383. * @throws IOException
  384. */
  385. public boolean createCell(int sheetIx, int rowIndex, int colIndex) throws IOException {
  386. Sheet sheet = workbook.getSheetAt(sheetIx);
  387. Row row = sheet.getRow(rowIndex);
  388. row.createCell(colIndex);
  389. return true;
  390. }
  391.  
  392. /**
  393. * 返回sheet 中的行数
  394. *
  395. *
  396. * @param sheetIx
  397. * 指定 Sheet 页,从 0 开始
  398. * @return
  399. */
  400. public int getRowCount(int sheetIx) {
  401. Sheet sheet = workbook.getSheetAt(sheetIx);
  402. if (sheet.getPhysicalNumberOfRows() == 0) {
  403. return 0;
  404. }
  405. return sheet.getLastRowNum() + 1;
  406.  
  407. }
  408.  
  409. /**
  410. *
  411. * 返回所在行的列数
  412. *
  413. * @param sheetIx
  414. * 指定 Sheet 页,从 0 开始
  415. * @param rowIndex
  416. * 指定行,从0开始
  417. * @return 返回-1 表示所在行为空
  418. */
  419. public int getColumnCount(int sheetIx, int rowIndex) {
  420. Sheet sheet = workbook.getSheetAt(sheetIx);
  421. Row row = sheet.getRow(rowIndex);
  422. return row == null ? -1 : row.getLastCellNum();
  423.  
  424. }
  425.  
  426. /**
  427. *
  428. * 设置row 和 column 位置的单元格值
  429. *
  430. * @param sheetIx
  431. * 指定 Sheet 页,从 0 开始
  432. * @param rowIndex
  433. * 指定行,从0开始
  434. * @param colIndex
  435. * 指定列,从0开始
  436. * @param value
  437. * 值
  438. * @return
  439. * @throws IOException
  440. */
  441. public boolean setValueAt(int sheetIx, int rowIndex, int colIndex, String value) throws IOException {
  442. Sheet sheet = workbook.getSheetAt(sheetIx);
  443. sheet.getRow(rowIndex).getCell(colIndex).setCellValue(value);
  444. return true;
  445. }
  446.  
  447. /**
  448. *
  449. * 返回 row 和 column 位置的单元格值
  450. *
  451. * @param sheetIx
  452. * 指定 Sheet 页,从 0 开始
  453. * @param rowIndex
  454. * 指定行,从0开始
  455. * @param colIndex
  456. * 指定列,从0开始
  457. * @return
  458. *
  459. */
  460. public String getValueAt(int sheetIx, int rowIndex, int colIndex) {
  461. Sheet sheet = workbook.getSheetAt(sheetIx);
  462. return getCellValueToString(sheet.getRow(rowIndex).getCell(colIndex));
  463. }
  464.  
  465. /**
  466. *
  467. * 重置指定行的值
  468. *
  469. * @param rowData
  470. * 数据
  471. * @param sheetIx
  472. * 指定 Sheet 页,从 0 开始
  473. * @param rowIndex
  474. * 指定行,从0开始
  475. * @return
  476. * @throws IOException
  477. */
  478. public boolean setRowValue(int sheetIx, List<String> rowData, int rowIndex) throws IOException {
  479. Sheet sheet = workbook.getSheetAt(sheetIx);
  480. Row row = sheet.getRow(rowIndex);
  481. for (int i = 0; i < rowData.size(); i++) {
  482. row.getCell(i).setCellValue(rowData.get(i));
  483. }
  484. return true;
  485. }
  486.  
  487. /**
  488. *
  489. * 返回指定行的值的集合
  490. *
  491. * @param sheetIx
  492. * 指定 Sheet 页,从 0 开始
  493. * @param rowIndex
  494. * 指定行,从0开始
  495. * @return
  496. */
  497. public List<String> getRowValue(int sheetIx, int rowIndex) {
  498. Sheet sheet = workbook.getSheetAt(sheetIx);
  499. Row row = sheet.getRow(rowIndex);
  500. List<String> list = new ArrayList<String>();
  501. if (row == null) {
  502. list.add(null);
  503. } else {
  504. for (int i = 0; i < row.getLastCellNum(); i++) {
  505. list.add(getCellValueToString(row.getCell(i)));
  506. }
  507. }
  508. return list;
  509. }
  510.  
  511. /**
  512. *
  513. * 返回列的值的集合
  514. *
  515. * @param sheetIx
  516. * 指定 Sheet 页,从 0 开始
  517. * @param rowIndex
  518. * 指定行,从0开始
  519. * @param colIndex
  520. * 指定列,从0开始
  521. * @return
  522. */
  523. public List<String> getColumnValue(int sheetIx, int rowIndex, int colIndex) {
  524. Sheet sheet = workbook.getSheetAt(sheetIx);
  525. List<String> list = new ArrayList<String>();
  526. for (int i = rowIndex; i < getRowCount(sheetIx); i++) {
  527. Row row = sheet.getRow(i);
  528. if (row == null) {
  529. list.add(null);
  530. continue;
  531. }
  532. list.add(getCellValueToString(sheet.getRow(i).getCell(colIndex)));
  533. }
  534. return list;
  535. }
  536.  
  537. /**
  538. *
  539. * 获取excel 中sheet 总页数
  540. *
  541. * @return
  542. */
  543. public int getSheetCount() {
  544. return workbook.getNumberOfSheets();
  545. }
  546.  
  547. public void createSheet() {
  548. workbook.createSheet();
  549. }
  550.  
  551. /**
  552. *
  553. * 设置sheet名称,长度为1-31,不能包含后面任一字符: :\ / ? * [ ]
  554. *
  555. * @param sheetIx
  556. * 指定 Sheet 页,从 0 开始,//
  557. * @param name
  558. * @return
  559. * @throws IOException
  560. */
  561. public boolean setSheetName(int sheetIx, String name) throws IOException {
  562. workbook.setSheetName(sheetIx, name);
  563. return true;
  564. }
  565.  
  566. /**
  567. *
  568. * 获取 sheet名称
  569. *
  570. * @param sheetIx
  571. * 指定 Sheet 页,从 0 开始
  572. * @return
  573. * @throws IOException
  574. */
  575. public String getSheetName(int sheetIx) throws IOException {
  576. Sheet sheet = workbook.getSheetAt(sheetIx);
  577. return sheet.getSheetName();
  578. }
  579.  
  580. /**
  581. * 获取sheet的索引,从0开始
  582. *
  583. * @param name
  584. * sheet 名称
  585. * @return -1表示该未找到名称对应的sheet
  586. */
  587. public int getSheetIndex(String name) {
  588. return workbook.getSheetIndex(name);
  589. }
  590.  
  591. /**
  592. *
  593. * 删除指定sheet
  594. *
  595. * @param sheetIx
  596. * 指定 Sheet 页,从 0 开始
  597. * @return
  598. * @throws IOException
  599. */
  600. public boolean removeSheetAt(int sheetIx) throws IOException {
  601. workbook.removeSheetAt(sheetIx);
  602. return true;
  603. }
  604.  
  605. /**
  606. *
  607. * 删除指定sheet中行,改变该行之后行的索引
  608. *
  609. * @param sheetIx
  610. * 指定 Sheet 页,从 0 开始
  611. * @param rowIndex
  612. * 指定行,从0开始
  613. * @return
  614. * @throws IOException
  615. */
  616. public boolean removeRow(int sheetIx, int rowIndex) throws IOException {
  617. Sheet sheet = workbook.getSheetAt(sheetIx);
  618. sheet.shiftRows(rowIndex + 1, getRowCount(sheetIx), -1);
  619. Row row = sheet.getRow(getRowCount(sheetIx) - 1);
  620. sheet.removeRow(row);
  621. return true;
  622. }
  623.  
  624. /**
  625. *
  626. * 设置sheet 页的索引
  627. *
  628. * @param sheetname
  629. * Sheet 名称
  630. * @param pos
  631. * Sheet 索引,从0开始
  632. */
  633. public void setSheetOrder(String sheetname, int sheetIx) {
  634. workbook.setSheetOrder(sheetname, sheetIx);
  635. }
  636.  
  637. /**
  638. *
  639. * 清空指定sheet页(先删除后添加并指定sheetIx)
  640. *
  641. * @param sheetIx
  642. * 指定 Sheet 页,从 0 开始
  643. * @return
  644. * @throws IOException
  645. */
  646. public boolean clearSheet(int sheetIx) throws IOException {
  647. String sheetname = getSheetName(sheetIx);
  648. removeSheetAt(sheetIx);
  649. workbook.createSheet(sheetname);
  650. setSheetOrder(sheetname, sheetIx);
  651. return true;
  652. }
  653.  
  654. public Workbook getWorkbook() {
  655. return workbook;
  656. }
  657.  
  658. /**
  659. *
  660. * 关闭流
  661. *
  662. * @throws IOException
  663. */
  664. public void close() throws IOException {
  665. if (os != null) {
  666. os.close();
  667. }
  668. // workbook.close();
  669. }
  670.  
  671. /**
  672. *
  673. * 转换单元格的类型为String 默认的 <br>
  674. * 默认的数据类型:CELL_TYPE_BLANK(3), CELL_TYPE_BOOLEAN(4),
  675. * CELL_TYPE_ERROR(5),CELL_TYPE_FORMULA(2), CELL_TYPE_NUMERIC(0),
  676. * CELL_TYPE_STRING(1)
  677. *
  678. * @param cell
  679. * @return
  680. *
  681. */
  682. private String getCellValueToString(Cell cell) {
  683. String strCell = "";
  684. if (cell == null) {
  685. return null;
  686. }
  687. switch (cell.getCellType()) {
  688. case Cell.CELL_TYPE_BOOLEAN:
  689. strCell = String.valueOf(cell.getBooleanCellValue());
  690. break;
  691. case Cell.CELL_TYPE_NUMERIC:
  692. if (HSSFDateUtil.isCellDateFormatted(cell)) {
  693. Date date = cell.getDateCellValue();
  694. if (pattern != null) {
  695. SimpleDateFormat sdf = new SimpleDateFormat(pattern);
  696. strCell = sdf.format(date);
  697. } else {
  698. strCell = date.toString();
  699. }
  700. break;
  701. }
  702. // 不是日期格式,则防止当数字过长时以科学计数法显示
  703. cell.setCellType(HSSFCell.CELL_TYPE_STRING);
  704. strCell = cell.toString();
  705. break;
  706. case Cell.CELL_TYPE_STRING:
  707. strCell = cell.getStringCellValue();
  708. break;
  709. default:
  710. break;
  711. }
  712. return strCell;
  713. }
  714.  
  715. public static boolean isExcel2003(String pathname) {
  716.  
  717. return pathname.endsWith(".xls");
  718. }
  719.  
  720. public static void main(String[] args) throws Exception {
  721. String pathName = "D:/a/e/2.xlsx";
  722. File f = new File(pathName);
  723. InputStream in = new FileInputStream(f);
  724. String version = isExcel2003(pathName)?"2003":"2007";
  725. ExcelUtil excelUtil = new ExcelUtil(in, version);
  726. //读取第一个sheet
  727. List<List<String>> read = excelUtil.read(0);
  728. for (int i = 0; i < read.size(); i++) {
  729. List<String> rowList = read.get(i);
  730. for (String s : rowList) {
  731. System.out.println(s);
  732. }
  733. System.out.println();
  734. }
  735. }
  736.  
  737. }

java里poi操作Excel工具类【我改】的更多相关文章

  1. java里poi操作excel的工具类(兼容各版本)

    转: java里poi操作excel的工具类(兼容各版本) 下面是文件内具体内容,文件下载: import java.io.FileNotFoundException; import java.io. ...

  2. 自己封装的poi操作Excel工具类

    自己封装的poi操作Excel工具类 在上一篇文章<使用poi读写Excel>中分享了一下poi操作Excel的简单示例,这次要分享一下我封装的一个Excel操作的工具类. 该工具类主要完 ...

  3. Java 借助poi操作PDF工具类

    ​ 一直以来说写一个关于Java操作PDF的工具类,也没有时间去写,今天抽空写一个简单的工具类,拥有PDF中 换行,字体大小,字体设置,字体颜色,首行缩进,居中,居左,居右,增加新一页等功能,如果需要 ...

  4. java操作excel 工具类

    java操作excel 可参考https://blog.csdn.net/xunwei0303/article/details/53213130 直接上代码: 一.java生成excel文件: pac ...

  5. 自己的包poi操作Excel工具

    在前面的文章<使用poi读写Excel>中分享了一下poi操作Excel的简单演示样例.这次要分享一下我封装的一个Excel操作的工具类. 该工具类主要完毕的功能是:读取Excel.汇总E ...

  6. java使用POI操作excel文件,实现批量导出,和导入

    一.POI的定义 JAVA中操作Excel的有两种比较主流的工具包: JXL 和 POI .jxl 只能操作Excel 95, 97, 2000也即以.xls为后缀的excel.而poi可以操作Exc ...

  7. Java使用POI操作Excel文件

    1.简介 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式文件读和写的功能. 2.依赖的jar包 <!-- ex ...

  8. java中文件操作的工具类

    代码: package com.lky.pojo; import java.io.BufferedReader; import java.io.BufferedWriter; import java. ...

  9. Java POI操作Excel注意点

    excel的行索引和列索引都是从0开始,而行号和列号都是从1开始 POI·操作excel基本上都是使用索引 XSSFRow对象的 row.getLastCellNum() 方法返回的是当前行最后有效列 ...

随机推荐

  1. 谷歌对Intel 10nm进度不满

    Intel 在 10nm 处理器上的节奏可谓是“龟速”,一拖三年,且目前大规模发货的 10nm Ice Lake 处理器仅仅是移动平台低电压,桌面要到明年. 表面波澜不惊,实际上却暗流涌动. 首先是 ...

  2. 七,ingress及ingress cluster

    目录 Service 类型 namespace 名称空间 Ingress Controller Ingress Ingress-nginx 进行测试 创建对应的后端Pod和Service 创建 Ing ...

  3. 牛客小白月赛12 J 月月查华华的手机 (序列自动机模板题)

    链接:https://ac.nowcoder.com/acm/contest/392/J 来源:牛客网 题目描述 月月和华华一起去吃饭了.期间华华有事出去了一会儿,没有带手机.月月出于人类最单纯的好奇 ...

  4. pikachu-file

    1.不安全的文件下载 1.1.概述 文件下载功能在很多web系统上都会出现,一般我们当点击下载链接,便会向后台发送一个下载请求,一般这个请求会包含一个需要下载的文件名称,后台在收到请求后 会开始执行下 ...

  5. 【HDU6635】Nonsense Time

    题目大意:给定一个长度为 N 的序列,开始时所有的位置都不可用,每经过一个时间单位,都会有一个位置被激活.现给定激活顺序的序列,求每次激活之后全局的最长上升子序列的长度,保证数据随机. 题解: 引理: ...

  6. 【CF160E】Buses and People

    题目大意:给定 N 个三元组 (a,b,c),现有 M 个询问,每个询问给定一个三元组 (a',b',c'),求满足 a<a', b'<b, c'<c 的最小 c 对应的元组编号. ...

  7. 2019年11月18日 JAVA期中考试 增删改查

    一.题目 石家庄铁道大学 青年志愿者服务网(20分)   1.项目需求: 为了适应社会主义市场经济发展的需要,推动青年志愿服务体系和多层次社会保障体系的建立和完善,促进青年健康成长,石家庄铁道大学急需 ...

  8. WSL中使用npm install报错

    报错内容类似下面的格式.具体解决方法请看这里:https://github.com/Microsoft/WSL/issues/14 着重关注 https://github.com/Microsoft/ ...

  9. 通俗易懂的例子解释 IAAS、SAAS、PAAS 的区别

    你一定听说过云计算中的三个“高大上”的你一定听说过云计算中的三个“高大上”的概念:IaaS.PaaS和SaaS,这几个术语并不好理解.不过,如果你是个吃货,还喜欢披萨,这个问题就好解决了!好吧,其实你 ...

  10. Spring CommonsMultipartResolver 上传文件

    转:http://yanglei008.iteye.com/blog/246920 ...Controller...{ // 创建一个通用的多部分解析器 CommonsMultipartResolve ...