user3130959
user3130959

Reputation: 31

ClosedXML: remove/change alternating row color?

Here's my code so far (VB):

Dim wb As New ClosedXML.Excel.XLWorkbook()
wb.Worksheets.Add(dTable, "export")
wb.SaveAs(location)

How can I remove just styling of the alternate rows (defaults to light blue)

Upvotes: 1

Views: 3805

Answers (2)

Hakan Usakli
Hakan Usakli

Reputation: 592

While the answer from @JimHewitt is correct, it is a brute force way and looping over all rows, which is waste of time for a large table. The more elegant way is to remove the Theme

dim ws As ClosedXML.Excel.IXLWorksheet = wb.Worksheets.Add(dTable, "export")
ws.Tables.FirstOrDefault().Theme = New ClosedXML.Excel.XLTableTheme("None")

See Project Documentation for all other available Themes https://github.com/ClosedXML/ClosedXML/blob/78150efbbd4a36d65e95ef3c793f12feb12c1a9c/ClosedXML/Excel/Tables/XLTableTheme.cs

Upvotes: 2

Jim Hewitt
Jim Hewitt

Reputation: 1792

Assuming you want to skip the header row, something like this should work before the save.

For i As Integer = 2 To wb.Worksheets.Worksheet("export").Rows.Count
     wb.Worksheets.Worksheet("export").Row(i).Style.Fill.SetBackgroundColor(XLColor.White)     
Next

Upvotes: 1

Related Questions