linkedinfacebooktwittermenuarrow-up

GemBox Support Forum

Unable To Set Column Width

First, I am new to using this product so there’s a good chance that I’m probably not doing something that I need to do so I’m hoping someone can tell me what I might be doing wrong. I’m using C# in VS2022 .Net Core 6. I installed the GemBox.Spreadsheet component via a NuGet package. I am currently using the free version.

I am trying to create a spreadsheet with data from a database but I am unable to set the column widths. In trying to debug my app I’ve been able to find that for some reason after adding data in 238 cells in row 0 (this would be for column headings), the number of columns returned in worksheet.Columns.Count is always equal to 0. The spreadsheet that gets generated with a total of 6 rows and 238 columns ends up having column widths that are absurdly wide when I open the spreadsheet in Excel.

Thank you in advance for any assistance anyone is able to provide.

Scott

Hi,

Regarding the columns count, don’t use ExcelWorksheet.Columns.Count property for this, use ExcelWorksheet.CalculateMaxUsedColumns() method instead.

Regarding the column width, please send us a small Visual Studio project that reproduces your issue so we can investigate it. You can send it to us via email or support ticket, see our Contact page.

Regards,
Mario

@mario.gembox

Thanks for the help. Using the CalculateMaxUsedColumns() method allow my code to loop through the columns and then use the SetWidth method to properly get things working.

Thanks again!

Scott