他のセルの色情報を新しいセルにコピーしたいと思います。Apache POIでCellcolorを変更する方法
これはうまくいきますが、私の新しいCellは毎回ブラックインスタットです。ここでは黄色
は、この私のコードです:私がSS usermodelからの細胞のXSSFCellのINSTATを使用する場合、それは修正する場合
private void cellChange(Cell cell, XSSFCell newCell, XSSFCellStyle newCellStyle) {
try
{
XSSFCell tt = (XSSFCell) cell;
XSSFColor color = tt.getCellStyle().getFillForegroundColorColor();
newCellStyle.setFillForegroundColor(color);
newCellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
newCellStyle.setFont(newFont);
newCell.setCellStyle(newCellStyle);
}
// .. catch omitted
TTは、このケースでテストしました。
この場合、お手伝いできますか?
例
public class ChangeCell{
public ChangeCell(){
try
{
File file = new File("C:\\ENTWICKLUNG\\testfolder\\out\\test.xlsx");
FileInputStream fis = new FileInputStream(file);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFWorkbook newWb = new XSSFWorkbook();
XSSFCell oldCell = wb.getSheetAt(0).getRow(0).getCell(0);
XSSFSheet newSheet = newWb.createSheet("Test");
XSSFRow newRow = newSheet.createRow(0);
XSSFCell newCell = newRow.createCell(0);
newCell.setCellValue("TestForCell");
XSSFCellStyle newCellStyle = newWb.createCellStyle();
cellChange(oldCell, newCell, newCellStyle);
newWb.write(new FileOutputstream("newTest.xlsx");
newWb.close();
}
//.. catch omitted
}
private void cellChange(Cell cell, XSSFCell newCell, XSSFCellStyle newCellStyle)
{
try
{
XSSFCell tt = (XSSFCell) cell;
XSSFColor color = tt.getCellStyle().getFillForegroundColorColor();
newCellStyle.setFillForegroundColor(color);
newCellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
newCell.setCellStyle(newCellStyle);
}
//.. catch omitted
} }
セルA1のtest.xlsxにおける色は赤または黄色であるべきです。
TTは、私は私のポストでそれを固定XSSFCellました。 私のnewStyleはsetfillforgroundcolor(色の色)を持っていないので、セルの中にそのように入れました。私が行って、.indexed()で短い時間で私のColerをtrasformすると、私のセルが黒であるのと同じ理由があります。 私は正しい色がcell.getCellStyle.getFillBackgroundColorColor();でスティッキングしていると思います。 –
はbeforのように動作します、私は私のメインのポストでコードを更新しますが、私は正しい色を得なかった前のような同じ問題があります。 –
またForgroundcolorと私は黄色のcellcolorの黒instatを得る –