Frage

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!

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top