Skip to main content

A method to write value and style at same time - Community / GemBox.Spreadsheet Feature Request - GemBox Support Center

A method to save multiple styles in a global variable with name then to apply A style (from many previously stored styles) when writing a value. This would be a huge time saver. Of course this would have to include borders, colors from what ever the other things that are held in a style. Technically this is highly possible with storing styles, but if it applied a value and style at the same time, It could save hundreds of lines of code, because each cell should have at least an value in it even if it is storing a 0 length string balance to a cell. If there was also an optional method for a small enumerated override, we would have many more possibilities too. Also having an overall default style when starting up a sheet would be great too so that would cut down on the amount of other possible cases of styles.  Instead of this: WorkSheet.Cells("A" & 2.ToString).Value = "Start string" & WithVarable How about this: WorkSheet.Cells("A" & 2.ToString).Value("Start string" & WithVarable, StoredStyle)  Scenario is to have 5 or 6 styles saved globally with things like shading, borders, font heights, and alignment to name a few. Then when writing a value which could also be a null value, to a cell would save so much time and incredibly easy to do. This would open more doors for writing shading in line cell and blank in one right beside it very easy.

Comment (1)

Mario - GemBox
Hi,

Note that you can create an extension method that would achieve setting of both Value and Style properties.
With this approach you could customize your extension method to your specific requirements.

Regarding the overall default style, if you want to set a default style for the entire workbook you can use the Normal style from ExcelFile.Styles, for example like the following:

Dim excel As ExcelFile
' ...

Dim normalStyle As CellSt yle = excel.Styles(BuiltInCellStyleName.Normal)
normalStyle.Font.Size = 500
normalStyle.Font.Color = Color.Red

If you want to set a default style for the specific worksheet you can set it on ExcelWorksheet.Cells.Style property, for example like the following:

Dim sheet As ExcelWorksheet
' ...

Dim sheetStyle As New CellStyle()
sheetStyle.Font.Size = 500
sheetStyle.Font.Color = Color.Red

sheet.Cells.St yle = sheetStyle

Also note that you can even use this approach in order to set the style of any selected CellRange.

Regards,

Mario
GemBox d.o.o.