POI实现EXCEL单元格合并及边框样式     下面例子为创建产生一个excel,合并单元格,然后为合并后的单元格添加边框 package test; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.ap…
POI对Excel单元格进行颜色设置 学习了:http://www.myexception.cn/program/1932587.html HSSFWorkbook workbook = new HSSFWorkbook(); HSSFCellStyle style = workbook.createCellStyle(); style.setFillForegroundColor(HSSFColor.LIME.index); style.setFillBackgroundColor(HSSFC…
使用Apache POI生成Excel文档时,当进行单元格合并操作后,被合并的单元格边框会消失,使用如下方式可以解决. 创建方法: public void setBorderStyle(int border, CellRangeAddress region, HSSFSheet sheet, HSSFWorkbook wb){ RegionUtil.setBorderBottom(border, region, sheet, wb); //下边框 RegionUtil.setBorderLeft…
如果是Microsoft Excel 97-2003 工作表 (.xls) if(31 == cell.getCellStyle().getFillForegroundColor()) //判断单元格前景色为淡蓝色 if(10 == book.getFontAt(cell.getCellStyle().getFontIndex()).getColor()) //判断单元格字体颜色为红色 如果是Microsoft Excel 工作表 (.xlsx) if(0 == cell.getCellStyl…
使用的是phpexcel,基本用的原生语法,所见即所得,直接复制下面代码,即可: // 引用phpexcel类 $this->load->library('PHPExcel'); // 创建对象 $objPHPExcel = new PHPExcel(); // 显示错误信息 error_reporting(E_ALL); // Set properties $objPHPExcel->getProperties()->setCreator("1245049149@qq.…
当我们通过POI设置了表格的列宽的时候,如果文字过长,希望文字能够自己折行显示. 截取代码如下: Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); Sheet sheet = wb.createSheet(); Row row = sheet.createRow(2); Cell cell = row.createCell(2); cell.setCellValue("Use \n with word wrap on to cr…
解决方法:根据单元格内容长度,设置单元格所在行的行高 public static float getExcelCellAutoHeight(string strtest, float fontCountInline) { float defaultRowHeight = 18.00f;//每一行的高度指定 float defaultCount = 0.00f; for (int i = 0; i <strtest.Length; i++) { float ff = getRegex(strtes…
背景介绍:使用Java开发信息系统项目,项目中往往会涉及到报表管理部分,而Excel表格首当其冲称为最合适的选择,但是对单元格操作时对于设置单元格的背景颜色却很少提及,本文旨在方便单元格背景颜色设计.操作:至于冗长的创建表格表格设置的代码相信大家都已经了解.直接进行单元格背景颜色设计. HSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式 st…
代码: ICellStyle cellStyle = workbook.CreateCellStyle(); cellStyle.BorderBottom = BorderStyle.Thin; cellStyle.BorderLeft = BorderStyle.Thin; cellStyle.BorderRight = BorderStyle.Thin; cellStyle.BorderTop = BorderStyle.Thin; cellStyle.VerticalAlignment =…
以下内容非原创,原文链接http://blog.sina.com.cn/s/blog_4b5bc01101015iuq.html ate String getCellValue(HSSFCell cell) { String cellValue = ""; DecimalFormat df = new DecimalFormat("#"); switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_STRING: c…