Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/OLE-automation/Go/ole-automation.go
Normal file
30
Task/OLE-automation/Go/ole-automation.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
ole "github.com/go-ole/go-ole"
|
||||
"github.com/go-ole/go-ole/oleutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ole.CoInitialize(0)
|
||||
unknown, _ := oleutil.CreateObject("Word.Application")
|
||||
word, _ := unknown.QueryInterface(ole.IID_IDispatch)
|
||||
oleutil.PutProperty(word, "Visible", true)
|
||||
documents := oleutil.MustGetProperty(word, "Documents").ToIDispatch()
|
||||
document := oleutil.MustCallMethod(documents, "Add").ToIDispatch()
|
||||
content := oleutil.MustGetProperty(document, "Content").ToIDispatch()
|
||||
paragraphs := oleutil.MustGetProperty(content, "Paragraphs").ToIDispatch()
|
||||
paragraph := oleutil.MustCallMethod(paragraphs, "Add").ToIDispatch()
|
||||
rnge := oleutil.MustGetProperty(paragraph, "Range").ToIDispatch()
|
||||
oleutil.PutProperty(rnge, "Text", "This is a Rosetta Code test document.")
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
|
||||
oleutil.PutProperty(document, "Saved", true)
|
||||
oleutil.CallMethod(document, "Close", false)
|
||||
oleutil.CallMethod(word, "Quit")
|
||||
word.Release()
|
||||
|
||||
ole.CoUninitialize()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue