Beispiel #1
0
func (this *Excel) SheetsCount() (e *Excel, err error) {
	sheets := oleutil.MustGetProperty(this.Excel, "Sheets").ToIDispatch()
	sheet_number := (int)(oleutil.MustGetProperty(sheets, "Count").Val)
	this.Count = sheet_number

	defer sheets.Release()
	return this, err
}
Beispiel #2
0
func (this *Excel) Cells(row int, column int) (value string, err error) {
	if this.Sheets == nil {
		err = errors.New("error: please use Excel.Sheet(i) to appoint the sheet.")
		return "", err
	}
	cells := oleutil.MustGetProperty(this.Sheets, "Cells", row, column).ToIDispatch()
	value = oleutil.MustGetProperty(cells, "Value").ToString()

	defer cells.Release()
	return value, err
}
Beispiel #3
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()
}
Beispiel #4
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)
	}
}
Beispiel #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
}
Beispiel #6
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
}
Beispiel #7
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()
}
Beispiel #8
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)
}
Beispiel #9
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")
}
Beispiel #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
}