Java操作EXCEL的利器一般都是POI和JXL,鄙人只是POI的忠实粉丝。(其实我是没有用过JXL)。现在大多数的excel都是07以上的版本,所以我一般是用07的基础上使用POI。一、读取单元格单元格有样式和值,以及值得类型。样式复制封装成一个函数:public XSSFC ...
Java操作EXCEL的利器一般都是POI和JXL,鄙人只是POI的忠实粉丝。(其实我是没有用过JXL)。
现在大多数的excel都是07以上的版本,所以我一般是用07的基础上使用POI。
- 一、读取单元格
单元格有样式和值,以及值得类型。
样式复制封装成一个函数:
public XSSFCellStyle cloneAllCellStyle(XSSFCell sourceCell, XSSFWorkbook targetWb){ //创建一个样式 XSSFCellStyle tempStyle = targetWb.createCellStyle(); //样式 //数值格式,创建字符及数字格式 DataFormat format= targetWb.createDataFormat(); //字体 XSSFFont font= targetWb.createFont(); try{ tempStyle.setDataFormat(format.getFormat( sourceCell.getCellStyle().getDataFormatString())); }catch(NullPointerException e){ tempStyle.setDataFormat((short)0); } font.setColor(sourceCell.getCellStyle().getFont().getXSSFColor()); font.setBold(sourceCell.getCellStyle().getFont().getBold()); font.setBoldweight(sourceCell.getCellStyle().getFont().getBoldweight()); try{ font.setCharSet(sourceCell.getCellStyle().getFont().getCharSet()); }catch(POI0); } // font.setCharSet(sourceCell.getCellStyle().getFont().getCharSet()); font.setFamily(sourceCell.getCellStyle().getFont().getFamily()); font.setFontHeight(sourceCell.getCellStyle().getFont().getFontHeight()); font.setFontHeightInPoints(sourceCell.getCellStyle().getFont().getFontHeightInPoints()); font.setFontName(sourceCell.getCellStyle().getFont().getFontName()); font.setItalic(sourceCell.getCellStyle().getFont().getItalic()); font.setStrikeout(sourceCell.getCellStyle().getFont().getStrikeout()); // font.setThemeColor(sourceCell.getCellStyle().getFont().getThemeColor()); font.setTypeOffset(sourceCell.getCellStyle().getFont().getTypeOffset()); font.setUnderline(sourceCell.getCellStyle().getFont().getUnderline()); tempStyle.setAlignment( sourceCell.getCellStyle().getAlignment()); tempStyle.setVerticalAlignment(sourceCell.getCellStyle().getVerticalAlignment()); tempStyle.setBorderBottom(sourceCell.getCellStyle().getBorderBottom()); tempStyle.setBorderLeft(sourceCell.getCellStyle().getBorderLeft()); tempStyle.setBorderRight(sourceCell.getCellStyle().getBorderRight()); tempStyle.setBorderTop(sourceCell.getCellStyle().getBorderTop()); tempStyle.setBottomBorderColor(sourceCell.getCellStyle().getBottomBorderXSSFColor()); tempStyle.setLeftBorderColor(sourceCell.getCellStyle().getLeftBorderXSSFColor()); tempStyle.setRightBorderColor(sourceCell.getCellStyle().getRightBorderXSSFColor()); tempStyle.setTopBorderColor(sourceCell.getCellStyle().getTopBorderXSSFColor()); tempStyle.setFillBackgroundColor(sourceCell.getCellStyle().getFillBackgroundColorColor()); tempStyle.setFont(font); try{ tempStyle.setFillForegroundColor(sourceCell.getCellStyle().getFillForegroundColorColor()); }catch(NullPointerException e){ tempStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex()); } tempStyle.setFillPattern(sourceCell.getCellStyle().getFillPattern()); tempStyle.setRotation(sourceCell.getCellStyle().getRotation()); tempStyle.setHidden(sourceCell.getCellStyle().getHidden()); tempStyle.setWrapText(sourceCell.getCellStyle().getWrapText()); tempStyle.setIndention(sourceCell.getCellStyle().getIndention()); tempStyle.setLocked(sourceCell.getCellStyle().getLocked()); return tempStyle; }
海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com
原标题:POI读取单元格信息及单元格公式
关键词:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。