Quantcast
Channel: NPOI
Viewing all articles
Browse latest Browse all 1621

Commented Issue: CloneStyleFrom not working as expected [13369]

$
0
0
Hi,
I'm trying to clone a cellstyle using CloneStyleFrom however, it doesn't appear to be working as expected.
When I modify the 'cloned' style, the original cell style is also modified.

FYI - I'm using Version 2.1.3.0

Other than that - excellent work and thanks!

Code snippet...
```
private void Test()
{
IWorkbook workbook = new XSSFWorkbook();
sheet = workbook.CreateSheet("Sheet A1");
ICell cell = sheet.CreateRow(0).CreateCell(0);
cell.SetCellValue(1.00);
ICellStyle cellStyle = workbook.CreateCellStyle();
IDataFormat fmt = workbook.CreateDataFormat();
short xx = fmt.GetFormat("0.00");
cellStyle.DataFormat = xx;
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thick;
cellStyle.BottomBorderColor = 8;
cell.CellStyle = cellStyle;

ICellStyle cellStyle2 = workbook.CreateCellStyle();
cellStyle2.CloneStyleFrom(cellStyle);

//Below change also affects cellStyle...
cellStyle2.BorderBottom = NPOI.SS.UserModel.BorderStyle.None;

FileStream sw = File.Create("cellStyler.xlsx");
workbook.Write(sw);
sw.Close();
}

```
Comments: ** Comment from web user: PETER_DA **

Hey everyone,
after putting in some more effort, we are getting much closer to the root cause of the issue:

Going back to the fill example:
When a style is being edited (e.g. setting the foregroundcolor), the SET method (SetFillForegroundColor) will retrieve a copy of a CT_Fill object by calling GetCTFill(); This in turn will call CT_Fill Copy() in CT_Fill.cs.

However, Copy() will tie the copy to the patternfillfield and gradientfillfield of the source. It will NOT COPY THESE FIELDS! This means, the copy we set the foregroundcolor for will actually edit the original Fill information. I will get back with more information and our workaround. (Workaround: actually copy those fields in the CT_Fill Copy() method)

Peter


Viewing all articles
Browse latest Browse all 1621

Trending Articles