문제

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!

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top