gpt4 book ai didi

c# - 查找具有常量的所有单元格会使 Excel 崩溃

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

我正在尝试使用 Excel Interop 程序集查找所有具有常量的单元格的计数。

在小文件上效果很好。但是,对于较大的文件,excel 会崩溃。

我在一个包含 206963 行和 9 列的文件上进行了尝试,但 excel 崩溃了。

  1. 有人知道解决方法吗?
  2. 是否有限制的列表SpecialCells功能以及何时不应使用?

以下是我的代码:

public static int getConstantCount(Range myRange) //myRange = myWorksheet.UsedRange
{
try
{
return myRange.SpecialCells(XlCellType.xlCellTypeConstants).Count;
}
catch (System.Runtime.InteropServices.COMException ex)
{
return 0;
}
}

我注意到在不使用任何 Interop 程序集的情况下,这也发生在 excel 本身中。看https://superuser.com/questions/632856/excel-go-to-special-crashes-on-large-file

最佳答案

只是第一个想法...

尝试使用 .CountLarge 属性,而不是您当前使用的 .Count 属性

目前您可能没有超过 .Count 的限制,但我希望它能有所帮助。

MSDN for .Count property (VBA)

关于c# - 查找具有常量的所有单元格会使 Excel 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18281533/

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