0

使用 Excel COM 自动化接口,我可以通过以下方式在单元格中设置值:

excel := COMDispatchDriver createObject: 'Excel.Application'.
excel getWorkbooks Add. 
excel setVisible: true.
(excel getRange: 'A1') setValue: 100

有没有办法可以用一个集合来做到这一点,比如:

excel := COMDispatchDriver createObject: 'Excel.Application'.
excel getWorkbooks Add. 
excel setVisible: true.
(excel getRange: 'A1:A4') setValue: #(1 2 3 4)
4

1 回答 1

2
ExcelApplicationController

| cont |
cont := (Examples.Excel97ApplicationController new).
[
  cont addWorkbook.
  cont isVisible: true.

  "Insert the title of our report."
  cont caption: 'First Quarter Results'.

  cont setRange: 'B5:E9'
     to: #( #( 10 20 30 40 ) #( 1 2 3 4 ) #( 101 201 301 401) #( 102 203 305 407 ) ).


] ensure:[
  cont notNil
        ifTrue: [
            cont release.
            cont := nil ]
]
于 2011-02-18T14:32:01.657 回答