在这种情况下,我的 Excel Range.OutlineLevel 为 null 或 System.DBNull

本文关键字:null System DBNull OutlineLevel Range 这种情况下 我的 Excel | 更新日期: 2023-09-27 18:36:09

在我的VSTO外接程序代码中,我对工作表行进行了range.outlinelevel检查。根据文档,大纲级别可以是 1 到 8,并且类型为变体/双精度。

  1. 但有时会返回
  2. 和其他时间范围。OutlineLevel.GetType() 返回 DBNull

有人知道为什么/何时会这样吗?


相关帖子:https://stackoverflow.com/questions/27778183/fastest-way-to-get-the-highest-range-outlinelevel-in-an-excel-worksheet

在这种情况下,我的 Excel Range.OutlineLevel 为 null 或 System.DBNull

我仍然没有答案(1.)。但是今天我找到了(2.)的答案:

一个范围。OutlineLevel.GetType() 返回 DBNull,如果给定范围内有多个大纲级别。

请参阅下面的调试器输出:

  • 普通行的标准大纲级别为 1.0:

    range.OutlineLevel  1.0     dynamic {double}
    
  • 对于具有不同大纲级别的多行,结果为:

    range.OutlineLevel  {}      dynamic {System.DBNull}