poi 合并单元格 无边框问题
2015-07-09 10:51
190 查看
public void merge(int startrow,int endstartrow,int startColumn,int endColumn){ sht.addMergedRegion(new CellRangeAddress(startrow, endstartrow, startColumn, endColumn)); }
合并单元格时候 合并后的单元格部分边框会看不见。从而进行处理。
下面是处理样式的 方法。 单元格设置边框
public void setStyle(int size, int color, boolean isBold, boolean isItalic, int backgroudColor, int align, int valign) { style = wb.createCellStyle(); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBottomBorderColor(HSSFColor.BLACK.index); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setLeftBorderColor(HSSFColor.BLACK.index); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setRightBorderColor(HSSFColor.BLACK.index); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setTopBorderColor(HSSFColor.BLACK.index); HSSFFont font = wb.createFont(); font.setColor((short)color); font.setFontHeightInPoints((short)size); if (isBold) { font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); } else { font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); } font.setItalic(isItalic); style.setFont(font); style.setFillForegroundColor((short)backgroudColor); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setAlignment((short)align); style.setVerticalAlignment((short)valign); }
然而并无卵用,一直出现 单元格无边框。几个单元格都出现相同效果。总结是合并单元格的 最后一个单元格 的边框总是有一边不显示。
最后解决办法是挺简单的,只要给最后那个单元格里面放一个空字符串。问题就解决了。
ew.putData(1, 1, 1, "");
ew是放数据的。
public void putData(int shtidx, int rowidx, int colidx, Object data) { if (rowidx > bounder) { try { wb.getSheetAt(shtidx); } catch (IndexOutOfBoundsException e) { wb.createSheet(); wb.setSheetName(shtidx, "Sheet " + (shtidx + 1)); } sht = wb.getSheetAt(shtidx); } if (sht.getRow(rowidx) == null) { sht.createRow(rowidx); } row = sht.getRow(rowidx); if (row.getCell(colidx) == null) { row.createCell(colidx); } cell = row.getCell(colidx); if (data instanceof Double) { Double d = (Double)data; cell.setCellValue(d); } else if (data instanceof Integer) { Integer i = (Integer)data; cell.setCellValue(i); } else if (data instanceof Date) { Date d = (Date)data; cell.setCellValue(d); } else if (data instanceof String) { String s = (String)data; cell.setCellValue(s); } else { String s; if (data == null) { data = new String(""); } s = data.toString(); cell.setCellValue(s); } cell.setCellStyle(style); }
相关文章推荐
- *Set Matrix Zeroes
- phpcms V9 改造:输出sql语句
- java数据结构之插入排序
- svn服务端搭建与使用
- ExtJS学习笔记一:HelloWorld
- iOS开发UI篇—Quartz2D使用(图形上下文栈)
- tagged initiallization
- Lua脚本之语法基础快速入门
- VC下的Unicode编程
- js日历
- PL/SQL Developer创建Oracle用户
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结
- shell 监控磁盘使用率
- [Objective-C] 重载objectAtIndexedSubscript和objectForKeyedSubscript方法实现subscripting
- 函数
- Discuz Windows 配置 iis7 URL 静态URL
- nyoj 791——Color the fence——————【贪心】
- JDK,JRE,JVM区别与联系-理解与概括
- php+curl 发送图片处理代码分享
- MySQL索引背后的数据结构及算法原理