Пример #1
0
func main() {
	ole.CoInitialize(0)
	unknown, _ := oleutil.CreateObject("Microsoft.XMLHTTP")
	xmlhttp, _ := unknown.QueryInterface(ole.IID_IDispatch)
	oleutil.CallMethod(xmlhttp, "open", "GET", "http://rss.slashdot.org/Slashdot/slashdot", false)
	oleutil.CallMethod(xmlhttp, "send", nil)
	state := -1
	for state != 4 {
		state = int(oleutil.MustGetProperty(xmlhttp, "readyState").Val)
		time.Sleep(10000000)
	}
	responseXml := oleutil.MustGetProperty(xmlhttp, "responseXml").ToIDispatch()
	items := oleutil.MustCallMethod(responseXml, "selectNodes", "rdf:RDF/item").ToIDispatch()
	length := int(oleutil.MustGetProperty(items, "length").Val)

	for n := 0; n < length; n++ {
		item := oleutil.MustGetProperty(items, "item", n).ToIDispatch()

		title := oleutil.MustCallMethod(item, "selectSingleNode", "title").ToIDispatch()
		println(oleutil.MustGetProperty(title, "text").ToString())

		link := oleutil.MustCallMethod(item, "selectSingleNode", "link").ToIDispatch()
		println("  " + oleutil.MustGetProperty(link, "text").ToString())

		title.Release()
		link.Release()
		item.Release()
	}
	items.Release()
	xmlhttp.Release()
}
Пример #2
0
func (pt *PowerPoint) close() {

	if pt.ppt != nil {
		oleutil.MustPutProperty(pt.ppt.ToIDispatch(), "Saved", -1)
		oleutil.MustCallMethod(pt.ppt.ToIDispatch(), "Close")
	}

	if pt.app != nil {
		oleutil.MustCallMethod(pt.app, "Quit")
		pt.app.Release()
	}

	ole.CoUninitialize()
}
Пример #3
0
func (wd *Word) close() {

	if wd.doc != nil {
		oleutil.MustPutProperty(wd.doc.ToIDispatch(), "Saved", true)
	}

	if wd.documents != nil {
		oleutil.MustCallMethod(wd.documents.ToIDispatch(), "Close")
	}

	if wd.app != nil {
		oleutil.MustCallMethod(wd.app, "Quit")
		wd.app.Release()
	}

	ole.CoUninitialize()
}
Пример #4
0
func (this *Excel) Close() (err error) {
	oleutil.PutProperty(this.Excel, "DisplayAlerts", this.DisplayAlerts)
	oleutil.PutProperty(this.Excel, "ScreenUpdating", this.ScreenUpdating)
	if this.Saved {
		oleutil.MustCallMethod(this.Excel, "Save").ToIDispatch()
	}

	oleutil.MustCallMethod(this.Workbooks, "Close").ToIDispatch()
	oleutil.MustCallMethod(this.Excel, "Quit").ToIDispatch()

	if this.Sheets != nil {
		defer this.Sheets.Release()
	}
	defer this.Workbooks.Release()
	defer this.Excel.Release()
	defer this.Excel_obj.Release()

	return err
}
Пример #5
0
func (this *Excel) Sheet(i int) (e *Excel, err error) {
	if this.Count == 0 {
		this.SheetsCount()
	}

	this.Sheets = oleutil.MustGetProperty(this.Excel, "Worksheets", i).ToIDispatch()
	oleutil.MustCallMethod(this.Sheets, "Select").ToIDispatch()

	return this, err
}
Пример #6
0
func main() {
	ole.CoInitialize(0)
	unknown, _ := oleutil.CreateObject("Agent.Control.1")
	agent, _ := unknown.QueryInterface(ole.IID_IDispatch)
	oleutil.PutProperty(agent, "Connected", true)
	characters := oleutil.MustGetProperty(agent, "Characters").ToIDispatch()
	oleutil.CallMethod(characters, "Load", "Merlin", "c:\\windows\\msagent\\chars\\Merlin.acs")
	character := oleutil.MustCallMethod(characters, "Character", "Merlin").ToIDispatch()
	oleutil.CallMethod(character, "Show")
	oleutil.CallMethod(character, "Speak", "こんにちわ世界")

	time.Sleep(4000000000)
}
Пример #7
0
func main() {
	ole.CoInitialize(0)
	unknown, _ := oleutil.CreateObject("InternetExplorer.Application")
	ie, _ := unknown.QueryInterface(ole.IID_IDispatch)
	oleutil.CallMethod(ie, "Navigate", "http://www.google.com")
	oleutil.PutProperty(ie, "Visible", true)
	for {
		if oleutil.MustGetProperty(ie, "Busy").Val == 0 {
			break
		}
	}

	time.Sleep(1e9)

	document := oleutil.MustGetProperty(ie, "document").ToIDispatch()
	window := oleutil.MustGetProperty(document, "parentWindow").ToIDispatch()
	// set 'golang' to text box.
	oleutil.MustCallMethod(window, "eval", "document.getElementsByName('q')[0].value = 'golang'")
	// click btnG.
	btnG := oleutil.MustCallMethod(window, "eval", "document.getElementsByName('btnG')[0]").ToIDispatch()
	oleutil.MustCallMethod(btnG, "click")
}
Пример #8
0
func main() {
	ole.CoInitialize(0)
	unknown, _ := oleutil.CreateObject("Excel.Application")
	excel, _ := unknown.QueryInterface(ole.IID_IDispatch)
	oleutil.PutProperty(excel, "Visible", true)
	workbooks := oleutil.MustGetProperty(excel, "Workbooks").ToIDispatch()
	workbook := oleutil.MustCallMethod(workbooks, "Add", nil).ToIDispatch()
	Worksheets := oleutil.MustGetProperty(workbook, "Worksheets", 1).ToIDispatch()
	cell := oleutil.MustGetProperty(Worksheets, "Cells", 1, 1).ToIDispatch()
	oleutil.PutProperty(cell, "Value", 12345)

	time.Sleep(2000000000)

	oleutil.PutProperty(workbook, "Saved", true)
	oleutil.CallMethod(excel, "Quit")
	excel.Release()
}
Пример #9
0
func main() {
	ole.CoInitialize(0)
	unknown, err := oleutil.CreateObject("WMPlayer.OCX")
	if err != nil {
		log.Fatal(err)
	}
	wmp := unknown.MustQueryInterface(ole.IID_IDispatch)
	collection := oleutil.MustGetProperty(wmp, "MediaCollection").ToIDispatch()
	list := oleutil.MustCallMethod(collection, "getAll").ToIDispatch()
	count := int(oleutil.MustGetProperty(list, "count").Val)
	for i := 0; i < count; i++ {
		item := oleutil.MustGetProperty(list, "item", i).ToIDispatch()
		name := oleutil.MustGetProperty(item, "name").ToString()
		sourceURL := oleutil.MustGetProperty(item, "sourceURL").ToString()
		fmt.Println(name, sourceURL)
	}
}
Пример #10
0
func (this *Excel) SaveAs(filepath string, filetype string) (err error) {
	//Check version
	var typeOf, xlXLS, xlXLSX int
	if this.Version == "12.0" {
		xlXLS = 56
		xlXLSX = 51
	} else {
		xlXLS = -4143
	}
	xlCSV := 6
	xlTXT := -4158
	xlTemplate := 17
	xlHtml := 44

	if filetype == "xls" || filetype == "xlsx" || filetype == "csv" || filetype == "txt" || filetype == "template" || filetype == "html" {
		switch filetype {
		case "xls":
			typeOf = xlXLS
		case "xlsx":
			typeOf = xlXLSX
		case "csv":
			typeOf = xlCSV
		case "txt":
			typeOf = xlTXT
		case "template":
			typeOf = xlTemplate
		case "html":
			typeOf = xlHtml
		default:
			typeOf = 0
		}
	} else {
		err = errors.New("error: Type is error.")
		return err
	}

	//no password
	activeWorkBook := oleutil.MustGetProperty(this.Excel, "ActiveWorkBook").ToIDispatch()
	oleutil.MustCallMethod(activeWorkBook, "SaveAs", filepath, typeOf, nil, nil).ToIDispatch()

	defer activeWorkBook.Release()
	return err
}
Пример #11
0
func (this *Excel) New() (e *Excel, err error) {
	ole.CoInitialize(0)
	this.Excel_obj, _ = oleutil.CreateObject("Excel.Application")
	this.Excel, _ = this.Excel_obj.QueryInterface(ole.IID_IDispatch)
	if this.Excel == nil {
		errors.New("error: Cant't Open excel.")
	}

	version := oleutil.MustGetProperty(this.Excel, "Version").ToString()
	this.Version = version

	oleutil.PutProperty(this.Excel, "Visible", this.Visible)
	oleutil.PutProperty(this.Excel, "DisplayAlerts", this.DisplayAlerts)
	oleutil.PutProperty(this.Excel, "ScreenUpdating", this.ScreenUpdating)

	this.Workbooks = oleutil.MustGetProperty(this.Excel, "WorkBooks").ToIDispatch()
	oleutil.MustCallMethod(this.Workbooks, "Add").ToIDispatch()

	return this, err
}
Пример #12
0
func (this *Excel) Save() (err error) {
	oleutil.MustCallMethod(this.Excel, "Save").ToIDispatch()
	return err
}