Maxscript和Excel:检索/更改单元格';s值

Maxscript和Excel:检索/更改单元格';s值,excel,cell,maxscript,Excel,Cell,Maxscript,我试图通过maxscript访问单个单元格的值,我一直很难弄清楚到底是什么阻止了我这么做。以下是我在maxscript中的内容: -- Startup Ops -- Generate a filename excelFile = "<path string>\testbook.xlsx" -- Start an Excel OLE Object x = CreateOLEObject "Excel.Application" -- Create a new workbook in

我试图通过maxscript访问单个单元格的值,我一直很难弄清楚到底是什么阻止了我这么做。以下是我在maxscript中的内容:

-- Startup Ops
-- Generate a filename
excelFile = "<path string>\testbook.xlsx"

-- Start an Excel OLE Object
x = CreateOLEObject "Excel.Application"

-- Create a new workbook in the new excel document
x.application.Workbooks.open(excelFile)

-- This makes Excel Visible
x.visible = true



--Here's where I'm having trouble
-- Retrieve the contents of Cell A3
contents = x.ActiveSheet.Cells(3, 1).Value

-- Change the contents of Cell A3 to Hello
x.ActiveSheet.Cells(3, 1).Value = "Hello"



-- Cleanup Ops
-- Close the spreadsheet
x.application.ActiveWorkbook.Close

-- quit excel
x.quit()

-- Release the OLE Object
releaseOLEObject x

-- Release ALL OLE Objects, just in case
releaseAllOLEObjects()
——启动操作
--生成文件名
excelFile=“\testbook.xlsx”
--启动Excel OLE对象
x=CreateOLEObject“Excel.Application”
--在新excel文档中创建新工作簿
x、 application.Workbooks.open(Excel文件)
--这使Excel可见
x、 可见=真
--这就是我遇到麻烦的地方
--检索单元格A3的内容
contents=x.ActiveSheet.Cells(3,1).Value
--将单元格A3的内容更改为Hello
x、 ActiveSheet.Cells(3,1).Value=“你好”
--清理行动
--关闭电子表格
x、 application.ActiveWorkbook.Close
--退出excel
x、 退出
--释放OLE对象
释放Olex对象
--释放所有OLE对象,以防万一
releaseAllOLEObjects()

这是我用来做参考的。据我所知,我把所有的事情都做了。如果有人能帮忙,我将非常感激。

我手头没有Excel,但我相信它应该是
(x.ActiveSheet.Cells x Y).Value


或者你可以选择另一种方式,使用.NET和。

我只是想在这里添加一个适合我的解决方案。我知道这是7年前的事了,我相信你解决了这个问题,但你的代码确实帮助了我,我在任何地方都找不到类似的代码,所以这里是:

--Here's where I'm having trouble
-- Retrieve the contents of Cell A3
contents = x.ActiveSheet.Cells(3, 1).Value

-- Change the contents of Cell A3 to Hello
x.ActiveSheet.Cells(3, 1).Value = "Hello"
我用过:

contents = x.application.cells 3 1  
contents.value = "Hello"

再一次,另一个完美的答案。非常感谢你。