Reputation: 249
I am writing a C# program that takes information from a database and converts it to an Excel sheet. However, it makes the columns the same default width each time. I know once it's loaded up, you can select all and re-size in a few clicks, but I'm being asked if it's possible to do during its creation while running the C# program. This is using WinForms in Visual Studio 2008.
Thank you!
Upvotes: 2
Views: 133
Reputation: 7830
Use the Range.AutoFit function to make the columns fit automatically to the longest content. MSDN states:
The expression must be a row or a range of rows, or a column or a range of columns.
range.EntireColumn.AutoFit();
range.EntireRow.AutoFit();
Detailed examples could be found in this SO post and in this MSDN forum.
Upvotes: 3