programmatically excel cells to be auto fit width & height

ε祈祈猫儿з 提交于 2019-12-05 02:01:17

Try getting the range and then do Autofit

Range.Rows.AutoFit();
Range.Columns.AutoFit();

This questions just helped me to solve part of a problem. I had to copy the data to a secondary, auxiliary sheet, then send it to the datagrid, but when I did, it would display in the datagrid the sequence of ######### for some of my data that was larger than the field itself. So I used **sheets.UsedRange.Columns.AutoFit();** to solve the problem every time a new column is created. Where sheets is my variable who received the **Microsoft.Office.Interop.Excel.Worksheet**.

Thank you guys very much.

I found this on another page:

C#

http://www.spreadsheetgear.com/support/help/spreadsheetgear.net.3.0/SpreadsheetGear~SpreadsheetGear.IRange~AutoFit.html

// Automatically set the width on columns B and C. worksheet.Cells["B:C"].Columns.AutoFit();

// Set the row height to automatic on rows 7 through 9. worksheet.Cells["7:9"].Rows.AutoFit();

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!