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

Created Unassigned: Applying different style for multiple rows [13302]

$
0
0
Hello,

I have a bit of a problem applying style to cells for multiple rows.

I extracted my method but when I try to do this:

```
ApplyStyleToRow(workbook, sheet.GetRow(11));
ApplyStyleToRow(workbook, sheet.GetRow(13));
```

Even though style should be applied to all cells for given row (1,32),
it's done only for the first row and in the next only to a few cells (the number of cells always stays the same if I change for loop (~35 cells)). I attached a screen.

Also vertical alignment is not working (checked in excel 2013).

Method:

```
///<summary>
///Apply style to row
///</summary>
private static void ApplyStyleToRow(HSSFWorkbook workbook, IRow row)
{
for (int h = 1; h < 32; h++)
{
ICellStyle cellStyle = workbook.CreateCellStyle();

cellStyle.BorderTop = BorderStyle.Thin;
cellStyle.BorderBottom = BorderStyle.Thin;
cellStyle.BorderLeft = BorderStyle.Thin;
cellStyle.BorderRight = BorderStyle.Thin;

if (h == 1)
{
cellStyle.BorderTop = BorderStyle.Medium;
cellStyle.BorderBottom = BorderStyle.Medium;
cellStyle.BorderLeft = BorderStyle.Medium;
cellStyle.BorderRight = BorderStyle.Thin;
}
else if (h == 2)
{

}
else if (h >= 3 && h <= 9)
{
cellStyle.FillForegroundColor = HSSFColor.Orange.Index;
cellStyle.FillPattern = FillPattern.SolidForeground;
}

cellStyle.Alignment = HorizontalAlignment.Center;
cellStyle.VerticalAlignment = VerticalAlignment.Center; //Not working


row.GetCell(h).CellStyle = cellStyle;

}

}
```

Best regards!

Viewing all articles
Browse latest Browse all 1621

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>