HSSFWorkbook outWB = new HSSFWorkbook();
HSSFSheet outSheet = outWB.createSheet("Sheet1");
HSSFRow outFstRow = outSheet.createRow((short)0);
HSSFRow outRow = outSheet.createRow((short)1);
HSSFCellStyle cellStyle = outWB.createCellStyle();
HSSFCellStyle cellStyleclor = outWB.createCellStyle();
Workbook workBook = new Workbook();
HSSFDataFormat hSSFDataFormat = new HSSFDataFormat(workBook);
cellStyleclor.setFillForegroundColor(HSSFColor.RED.index);
cellStyleclor.setFillBackgroundColor(HSSFColor.BLUE.index);
cellStyle.setDataFormat(hSSFDataFormat.getFormat("yy-mmm-d"));
for(int m=0;m<columnList.size();m++){
column =columnList.get(m)+"";
HSSFCell outCell = outFstRow.createCell((short)m);
outCell.setCellValue(column);
outCell.setCellStyle(cellStyleclor); //这段setCellValue后 单元格颜色不变
}
b: for(int n=0;n<columnList.size();n++){
cell = row.getCell((short)n);
if(cell!=null){
if(cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
String data = cell.getStringCellValue();
outRow.createCell((short)n).setCellValue(data);
}else if(HSSFDateUtil.isCellDateFormatted(cell)){
Date data =cell.getDateCellValue();
outRow.createCell((short)n).setCellValue(data);
outRow.createCell((short)n).setCellStyle(cellStyle);
}else if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
double data = cell.getNumericCellValue();
outRow.createCell((short)n).setCellValue(data); // 这段setCellValue后 单元格显示空
}刚开始用POI 按照别人的例子写一个 结果发现 不论是设置日期格式 还是背景颜色 只要我写setCellValue 就不好用。。
我把代码写上衣部分, 大家帮看看阿 先谢谢啦
HSSFSheet outSheet = outWB.createSheet("Sheet1");
HSSFRow outFstRow = outSheet.createRow((short)0);
HSSFRow outRow = outSheet.createRow((short)1);
HSSFCellStyle cellStyle = outWB.createCellStyle();
HSSFCellStyle cellStyleclor = outWB.createCellStyle();
Workbook workBook = new Workbook();
HSSFDataFormat hSSFDataFormat = new HSSFDataFormat(workBook);
cellStyleclor.setFillForegroundColor(HSSFColor.RED.index);
cellStyleclor.setFillBackgroundColor(HSSFColor.BLUE.index);
cellStyle.setDataFormat(hSSFDataFormat.getFormat("yy-mmm-d"));
for(int m=0;m<columnList.size();m++){
column =columnList.get(m)+"";
HSSFCell outCell = outFstRow.createCell((short)m);
outCell.setCellValue(column);
outCell.setCellStyle(cellStyleclor); //这段setCellValue后 单元格颜色不变
}
b: for(int n=0;n<columnList.size();n++){
cell = row.getCell((short)n);
if(cell!=null){
if(cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
String data = cell.getStringCellValue();
outRow.createCell((short)n).setCellValue(data);
}else if(HSSFDateUtil.isCellDateFormatted(cell)){
Date data =cell.getDateCellValue();
outRow.createCell((short)n).setCellValue(data);
outRow.createCell((short)n).setCellStyle(cellStyle);
}else if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
double data = cell.getNumericCellValue();
outRow.createCell((short)n).setCellValue(data); // 这段setCellValue后 单元格显示空
}刚开始用POI 按照别人的例子写一个 结果发现 不论是设置日期格式 还是背景颜色 只要我写setCellValue 就不好用。。
我把代码写上衣部分, 大家帮看看阿 先谢谢啦
解决方案 »
- Java打开txt文件时显示错误
- java类的继承有实例的区别
- 想问一下关于 java和c 之间有没有算法相同的md5加密现在出现一个问题!
- Calendar的问题,大家帮帮忙
- 各位高手请帮忙~统计字母个数
- 组件怎么变成可改变大小的?
- 如何使用JDBC创建存储过程?如何使用JDBC删除存储过程?JDBC如何取得存储过SQL创建脚本?
- 还是有一些问题不太清楚,希望大家能帮忙,关于配置java sdk环境变量后,能编译却不能执行。
- JInternalFrame如何在初始化时最大化?
- 请问有谁写过数学公式解析的Java程序吗???
- 问有关ResultSet的问题,急
- 如何在一个List找到一个最小的大于数?
楼主【adong1423】截止到2008-07-09 10:34:12的历史汇总数据(不包括此帖):
发帖的总数量:0 发帖的总分数:0 每贴平均分数:0
回帖的总数量:0 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:0 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:0 未结的总分数:0
结贴的百分比:---------------------结分的百分比:---------------------
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
着急ING。。
HSSFWorkbook outWB = new HSSFWorkbook();
HSSFSheet outSheet = outWB.createSheet("Sheet1");
HSSFRow outFstRow = outSheet.createRow((short)0);
HSSFRow outRow = outSheet.createRow((short)1);
HSSFCellStyle cellStyle = outWB.createCellStyle();
Workbook workBook = new Workbook();
HSSFDataFormat hSSFDataFormat = new HSSFDataFormat(workBook);
cellStyle.setDataFormat(hSSFDataFormat.getFormat("yy-mmm-d")); 。。
else if(HSSFDateUtil.isCellDateFormatted(cell)){
Date data =cell.getDateCellValue();
outRow.createCell((short)n).setCellValue(data);
outRow.createCell((short)n).setCellStyle(cellStyle); // 这段setCellValue后 单元格显示空
}
这个日期不写 就显示 2008-2-15 00:00:00 写上setCellValue 就显示空! 为什么阿? 我什么地方写错了?????????????????????????????????????????????