1

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)

user3130959
  • 31
  • 1
  • 6

2 Answers2

1

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
Jim Hewitt
  • 1,726
  • 4
  • 24
  • 26
1

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

Hakan Usakli
  • 492
  • 5
  • 11