4

I'm using ClosedXML to generate a report. The data supplied to Excel is from a database which is stored to a DataTable object. The table is displayed fine in the Excel sheet - however, it has a default theme applied on the created table. Below is my sample code:

Dim workbook As XLWorkbook = New XLWorkbook()    
Dim _tempSummary= workbook.AddWorksheet("Summary").Cell(1, 1).InsertTable(tblSummary)

This is the result:

enter image description here

I wanted to remove the bold font styling of the created table. However, when I did this

_tempSummary.AsTable().Ranges("B1:G1,I1:O1,Q1:R1").Style.Font.SetBold(False)

It doesn't seem to work. Please tell me what I'm doing wrong. Thanks in advance.

Hitesh
  • 3,449
  • 8
  • 39
  • 57
saiha
  • 93
  • 1
  • 7

2 Answers2

4

I figured it out today. It was a very obvious mistake. I should have not used AsTable() since the cells I wanted to format are already in a table. This is the result of bad intellisense of VS2010, for some reason Table.Theme() doesn't show up on the context menu. I found the fixed of me own problem. It should have been:

_tempSummary.Theme() = XLTableTheme.None
saiha
  • 93
  • 1
  • 7
3

I was using a DataTable and wanted to remove the blue default style of the table, Only the flowing worked for me :

using (var workbook = new XLWorkbook())
{
    var ws = workbook.Worksheets.Add(productListDataTable, "Product List Sheet");
    ws.Tables.FirstOrDefault().Theme = XLTableTheme.None; //works with manully added tables, datatables
    workbook.SaveAs(diskPath);
}

Other styling options are for ranges / cells are confusing, so if you are applying a style to a "table" you added (not a cell / a range) you will need to select that table and apply "XLTableTheme" on it.

Thanks

Adel Mourad
  • 1,351
  • 16
  • 13