0

エラー: 「フィールド、コンストラクター、またはメンバー '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".

ご協力いただきありがとうございます!

4

1 に答える 1

2

これを追加してみてください:

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

wb.ActiveSheetUsedRangeメソッドを正しく解決するには、「obj」をワークシートにダウンキャストする必要があります。

于 2012-10-18T14:48:36.127 に答える