Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Excel单元格高度不会增加_C#_Excel - Fatal编程技术网

C# Excel单元格高度不会增加

C# Excel单元格高度不会增加,c#,excel,C#,Excel,我正在使用Microsoft.Office.Interop.Excel将数据写入Excel单元格。单元格有一个特定的初始高度,我正在设置“merge cell=true”和“wrap text=true” 当细胞含量较大时,细胞高度不会增加。我尝试了以下两种方法: _range.entrirerow.autofit() _range.columns.autofit() 这对我没有任何作用,请建议一些解决方案。试试_range.Rows.Autofit() 请注意: COM对象不会以双句点释放

我正在使用Microsoft.Office.Interop.Excel将数据写入Excel单元格。单元格有一个特定的初始高度,我正在设置“merge cell=true”和“wrap text=true”

当细胞含量较大时,细胞高度不会增加。我尝试了以下两种方法:

_range.entrirerow.autofit() 
_range.columns.autofit()
这对我没有任何作用,请建议一些解决方案。

试试_range.Rows.Autofit()

请注意: COM对象不会以双句点释放。它创建了您无法访问的临时变量

因此,我们应该使用:

Range rows = _range.Rows;
rows.Autfit();
if (rows != null)
{
  Marshal.FinalReleaseComObject(rows);
}

您是否将其应用于合并单元格的顶行?