Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.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
F#未定义Excel UsedRange_Excel_F#_Vsto_Office Interop - Fatal编程技术网

F#未定义Excel UsedRange

F#未定义Excel UsedRange,excel,f#,vsto,office-interop,Excel,F#,Vsto,Office Interop,错误:“未定义字段、构造函数或成员“UsedRange” 代码摘录: open Microsoft.Office.Interop.Excel open Microsoft.Office.Tools.Excel // Onorio's excellent suggestion didn't fix code until this line was added. // Once the above line was added, Onorio's suggestion worked, // but

错误:“未定义字段、构造函数或成员“UsedRange”

代码摘录:

open Microsoft.Office.Interop.Excel
open Microsoft.Office.Tools.Excel // Onorio's excellent suggestion didn't fix code until this line was added.
// Once the above line was added, Onorio's suggestion worked,
// but now F# says "The field, constructor or member 'EntireColumn' is not defined".

let xl = ApplicationClass()
xl.Workbooks.OpenText(...
let wb = xl.Workbooks.Item(1)
let ws = wb.ActiveSheet :?> Worksheet // Per Onorio's suggestion.

ws.UsedRange.EntireColumn.AutoFit()
// "The field, constructor or member 'EntireColumn' is not defined".

// Here's another example of UsedRange now working,
// but Properties and Methods of UsedRange not working:
// (uniqueID is simply a Boolean set earlier based on ini file values)
if uniqueID then
   xl.Range("A1").EntireColumn.Insert() |> ignore
   xl.Range("A1").Value <- "UniqueID"
   xl.Range("A2").Value <- 1
   xl.Range("A2").AutoFill(xl.Range("A2:A" + ws.UsedRange.Rows.Count),
                           XlAutoFillType.xlFillSeries) |> ignore
// Here it's "The field, constructor or member 'Rows' is not defined".
打开Microsoft.Office.Interop.Excel
打开Microsoft.Office.Tools.Excel//Onorio的优秀建议在添加这一行之前没有修复代码。
//一旦添加了上述行,Onorio的建议就奏效了,
//但现在F#说“字段、构造函数或成员‘entireclumn’未定义”。
设xl=ApplicationClass()
xl.工作簿.OpenText(。。。
设wb=xl.工作簿.项目(1)
让ws=wb.ActiveSheet:?>工作表//按照Onorio的建议。
ws.UsedRange.entireclumn.AutoFit()
//“未定义字段、构造函数或成员‘entireclumn’。”。
//这是另一个UsedRange正在工作的例子,
//但使用的性质和方法不起作用:
//(uniqueID只是先前基于ini文件值的布尔集合)
如果是唯一的,那么
xl.Range(“A1”).entireclumn.Insert()|>忽略
xl.范围(“A1”).值尝试添加以下内容:

let wb = xl.Workbooks.Item(1)
let actSheet = wb.ActiveSheet :?> Worksheet  //downcast obj to Worksheet
actSheet.UsedRange.EntireColumn.AutoFit()

wb.ActiveSheet
返回一个“obj”你需要把它下放到工作表中,以便
UsedRange
方法正确地解决问题。

我不是想变得暴躁,但如果我的答案是你问题的解决方案,你会接受吗?如果不是,也许你可以扩展你的问题?我不是有意疏忽。我只是没有机会去实现我希望周一早上的第一件事就是证明它是正确的解决方案。一如既往,我感谢你对F#和函数编程的专业知识!谢谢你的建议。如果你是从FSI运行这个,我真的很惊讶你不需要包含对Excel程序集的引用,就像这样:#r“Microsoft.Office.Interop.Excel”如果你还没有这样做,你就需要这样做。如果没有这行代码,其他任何东西在一开始都不会起作用。我不是从FSI运行它,我只是调出FSI来查找F#版本号。我在F#(处理文本文件)中原型化了该应用程序,然后在VB中为用户请求的附加Excel功能重写它,并编译和部署该版本。但是,如果我能克服这些F#绊倒,我想编译和部署F#,而不是。Jeff--那么您正试图在Visual Studio中构建它,对吗?如果是,请确保项目引用Microsoft.Office.Interop.Excel作为组装。(对于VS 2010,但单击顶部的“其他版本”并查找您的版本)。添加此代码没有任何帮助,直到我将open Microsoft.Office.Tools.Excel添加到模块中,但现在我遇到了一个新问题:“未定义字段、构造函数或成员EntireClumn“。排序和行都不是。我真的想用F#而不是VB来做这件事。一如既往,谢谢,Onorio!你用的是哪个版本的F#?哪个版本的Excel?这在我的机器上运行得很好,所以看起来可能是某种基础结构上的差异。哦,我不想听这个。F#2.0交互式构建4.0.40219.1。Excel 2010。”(版本14.0.6123.5001)。我有一个想法,我们公司使用的Office版本是专门为我们公司设计的。如果您没有任何进一步的想法,我会继续将此作为答案,假设它适用于大多数用户。让我知道。再次感谢!我一直在使用Excel 2010和F#2.0进行测试,所以这应该不会有什么区别。编辑问题上,以准确发布您正在使用的更新代码,这样我可以确保我没有遗漏任何内容。也可能与您正在使用的Excel文件有关。请尝试创建一个新的Excel文件,然后在一个全新的文件上尝试该代码,看看会发生什么。