获取第一个excel的单元格的背景(前景)色设置在第二个excel的单元格上

场景:

获取第一个excel的单元格的背景(前景)色设置在第二个excel的单元格上。

在调用第一个excel对象的getFillForegroundColor()获取前景色索引后,调用第二个excel对象的setFillForegroundColor()写入获取到的背景色后,发现写出的第二个excel颜色混乱,发现getFillForegroundColor返回的值都是64。(ps:查看官网api发现调用getFillForegroundColor()方法默认是返回64。)

问题:

workbook在获取excel的时候没有把颜色覆盖到FillForegroundColor上么?为什么获取的还是默认值?

请问有什么方法可以更好的获取一个excel中单元格的颜色后在另一个excel中重现这个颜色呢?
ps:poi3.9,xls与xlsx两种文件都有

以下是我的代码,我将重要的部分给你,你自己看一下,希望能解决到你的问题,其中有些是有其他地方调用传值过来的,自己注意一下,如果不明白的地方可以加我微信:huihui201819

HSSFCell datacell = dataRow.createCell(j);//创建单元格
HSSFCellStyle cellStlye = wb.createCellStyle();//创建样式
//自动换行 上下居中
cellStlye.setWrapText(true);// 设置自动换行
cellStlye.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 创建一个居中格式
cellStlye.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
// 设置边框
cellStlye.setBottomBorderColor(HSSFColor.BLACK.index);
cellStlye.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cellStlye.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cellStlye.setBorderRight(HSSFCellStyle.BORDER_THIN);
cellStlye.setBorderTop(HSSFCellStyle.BORDER_THIN);

//设置背景
if(row.getColor() != null) {
int color = row.getColor();
/*cellStlye.setFillPattern(HSSFCellStyle.BIG_SPOTS);
cellStlye.setFillForegroundColor(HSSFColor.RED.index);
cellStlye.setFillBackgroundColor(HSSFColor.LIGHT_BLUE.index); /
cellStlye.setFillPattern((short)color); //使用传过来的颜色
cellStlye.setFillForegroundColor((short)color);
cellStlye.setFillBackgroundColor((short)color);
}
*
***********其中省略一些多余的代码***************
datacell.setCellStyle(cellStlye);//将上面创建的样式填充到单元格中