转:

下面是文件内具体内容,文件下载:

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

java里poi操作excel的工具类(兼容各版本)的更多相关文章

  1. java里poi操作Excel工具类【我改】

    参考原文: https://www.cnblogs.com/yizhang/p/7244917.html 我改: package test; import java.io.File; import j ...

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

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

  3. Java POI操作Excel注意点

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

  4. Excel导入工具类兼容xls和xlsx

    package com.bj58.finance.platform.operation.provider.util; import org.apache.log4j.Logger; import or ...

  5. JAVA的POI操作Excel

    1.1Excel简介 一个excel文件就是一个工作簿workbook,一个工作簿中可以创建多张工作表sheet,而一个工作表中包含多个单元格Cell,这些单元格都是由列(Column)行(Row)组 ...

  6. java用POI操作excel——随便写一下,最基础的东西

    前两天部门实施在做一个东西,需要把客户放在Excel中的数据导入到Oracle数据库中,我就想着直接写一个模板,必要的时候改一下实体类应该可以解放实施同事的双手,不过在实际写的过程中,还是碰到很多问题 ...

  7. Java使用 POI 操作Excel

    Java中常见的用来操作 Excel 的方式有2种:JXL和POI.JXL只能对 Excel进行操作,且只支持到 Excel 95-2000的版本.而POI是Apache 的开源项目,由Java编写的 ...

  8. poi读取excel内容工具类

    该工具类可以读取excel2007,excel2003等格式的文件,xls.xlsx文件格式 package com.visolink; import org.apache.poi.hssf.user ...

  9. Java使用POI操作Excel文件

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

随机推荐

  1. Django 数据库模块 单独使用

    pip install django pip install psycopg2 pip install mysqlclient Entity.py from django.db import mode ...

  2. h5转pb的两个坑

    1.需要加上如下设置,否则转换前后输出可能不一致,这个主要针对dropout.BN层训练测试不一致 from keras import backend as K K.set_learning_phas ...

  3. 解决 Maven项目进行编译( mvn compile )时出现的错误

    错误信息: 在 pom.xml 文件 设置一下Maven的属性 <!--Maven 属性--> <properties> <!--项目的编码格式--> <pr ...

  4. hive判断数据一个表是否在另一个表中(二)

    1.一个表中的数据不存在另一个表中 2.一个表中的数据 存在另一个表中:

  5. "main" java.io.IOException: Mkdirs failed to create /user/centos/hbase-staging (exists=false, cwd=file:/home/centos)

    Exception in thread "main" java.io.IOException: Mkdirs failed to create /user/centos/hbase ...

  6. windows笔记本命令行方式建立wifi热点

    建立热点: @echo off netsh wlan set hostednetwork mode=allow netsh wlan set hostednetwork ssid=热点名 key=密码 ...

  7. qt类表

  8. python插入mysql数据(2)

    python插入mysql数据(2) """插入操作""" import pymysql import datetime from pymy ...

  9. webpack打包,同时将ES6转为ES5,初探

    webpack打包,同时将ES6转为ES5,第一次尝试搞了一下午才弄好,所有的问题均来自ES6转es5上面,可能天分不够把,但愿各大浏览器快点支持ES6吧!忽略nodejs安装. 第一,新建一个项目文 ...

  10. IDEA 配置热更新