gpt4 book ai didi

c# - Microsoft Excel Interop 检查 excel 工作表是否支持 Autofit

转载 作者:太空宇宙 更新时间:2023-11-03 11:13:02 25 4
gpt4 key购买 nike

在使用 Excel Interop 时,我遇到了一个问题。在保存之前,我使用以下代码自动调整工作表的列。

Excel.Worksheet curSheet = (Excel.Worksheet)wsEnumerator.Current;
curSheet.UsedRange.EntireColumn.AutoFit();

而且对我来说效果很好。然后我遇到了一些特定 Excel 工作表的问题。如果我自动调整,它会显示 Range 类的 AutoFit 方法失败

导致问题的 excel 表可用 here

现在我想知道的是,是否有一些方法可以检查 excel 表是否支持自动调整。有点像

if(sheet.CanAutoFit())
curSheet.UsedRange.EntireColumn.AutoFit();

如有任何帮助,我们将不胜感激。

最佳答案

如果没有 sheet.CanAutoFit() 那么你总是可以这样做:

try {
curSheet.UsedRange.EntireColumn.AutoFit();
} catch (TheSpecificExcelException exc)
{ ... }

关于c# - Microsoft Excel Interop 检查 excel 工作表是否支持 Autofit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13417190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com