【问题标题】:F# Excel Range.AutoFilter() failsF# Excel Range.AutoFilter() 失败
【发布时间】:2012-10-24 21:21:13
【问题描述】:

我正在尝试为将使用数据的用户打开AutoFilter

open Microsoft.Office.Interop.Excel

let xl = ApplicationClass()
xl.Workbooks.OpenText(fileName...)
let wb = xl.Workbooks.Item(1)
let ws = wb.ActiveSheet :?> Worksheet

let rows = string ws.UsedRange.Rows.Count

// AutoFilter method of Range class failed.
ws.Range("A7:I" + rows).AutoFilter() |> ignore

感谢您提供的任何帮助。

【问题讨论】:

  • 没有参数的调用应该只是切换自动筛选下拉箭头的显示,这就是我所追求的。

标签: f# vsto excel-2010 excel-interop


【解决方案1】:

根据the documentation,需要向AutoFilter传递5个参数。

未指定的参数可以用System.Reflection.Missing.Value填充。

有点像

ws.Range("A7:I" + rows).AutoFilter(1, System.Reflection.Missing.Value, 
                                   Excel.XlAutoFilterOperator.xlAnd, 
                                   System.Reflection.Missing.Value, true) 
|> ignore

应该可以。

【讨论】:

  • 公平地说,Intellisense 和文档都表明所有参数都是可选的,文档表明省略所有参数只会切换 AutoFilter 下拉箭头的显示,这就是我在之后。我不得不这么说,所以我不觉得自己像个彻头彻尾的白痴。 :) Type.Missing 在我的机器上不起作用(命名空间或模块“类型”未定义),所以我用"" 替换了它们,并编译了它。不幸的是,它导致整个范围被过滤,没有任何显示。我还根据文档尝试了"<>",结果相同。
  • 对不起;我不熟悉 Excel 互操作。 Type.Missing 应该是 System.Reflection.Missing.Value。我不知道为什么什么都没有显示,最好的办法是更改选项并确保您有真实数据要过滤。
  • 啊!做到了!非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-10
  • 1970-01-01
  • 1970-01-01
  • 2011-03-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多