i am trying copy cells from one row to the one below. To copy the comments and cellvalues works fine. Now if I set a background-color in Excel and want to just copy it to the new cell, it doesn't work. Either there is just no color after copying or the background is black. I tried that:
我正在尝试将单元格从一行复制到下一行。复制注释和cellvalues工作正常。现在,如果我在Excel中设置背景颜色并想要将其复制到新单元格,则它不起作用。复制后没有颜色或背景为黑色。我试过了:
style2.setFillBackgroundColor(cell_master_alt.getCellStyle().getFillBackgroundColor());
style2.setFillForegroundColor(cell_master_alt.getCellStyle().getFillForegroundColor());
style2.setFillPattern(CellStyle.SOLID_FOREGROUND); or
style2.setFillPattern(cell_master_alt.getCellStyle().getFillPattern());
cell_master_neu.setCellStyle(style2);
After a few hours without any progress, I looked into the foreground- and background-color of the cell I want to copy. There I found RGB values. Now I want to make a new Cellstyle with that values, but that doesn't work as well. First I try this:
几个小时没有任何进展,我查看了我要复制的单元格的前景色和背景色。在那里我找到了RGB值。现在我想制作一个具有该值的新Cellstyle,但这不起作用。首先我试试这个:
style_new.setFillForegroundColor(new XSSFColor(new java.awt.Color(128,128,128)));
but there is an error message:
但是有一条错误消息:
The method setFillForegroundColor(short) in the type CellStyle is not applicable for the arguments (XSSFColor)
What is wrong with that?
这有什么问题?
Thanks
1 个解决方案
#1
3
In Apache POI cell styles can be applied to multiple cells due to the way Excel stores them in the binary format, thus it should suffice to just apply the cell style from one cell onto the other without any copying:
在Apache POI中,单元格样式可以应用于多个单元格,因为Excel以二进制格式存储它们,因此只需将单元格样式从一个单元格应用到另一个单元格而不进行任何复制即可:
cell_master_neu.setCellStyle(cell_master_alt.getCellStyle());
#1
3
In Apache POI cell styles can be applied to multiple cells due to the way Excel stores them in the binary format, thus it should suffice to just apply the cell style from one cell onto the other without any copying:
在Apache POI中,单元格样式可以应用于多个单元格,因为Excel以二进制格式存储它们,因此只需将单元格样式从一个单元格应用到另一个单元格而不进行任何复制即可:
cell_master_neu.setCellStyle(cell_master_alt.getCellStyle());