Example #1
0
func (c *AdodbConn) Prepare(query string) (driver.Stmt, error) {
	unknown, err := oleutil.CreateObject("ADODB.Command")
	if err != nil {
		return nil, err
	}
	s, err := unknown.QueryInterface(ole.IID_IDispatch)
	if err != nil {
		return nil, err
	}
	_, err = oleutil.PutProperty(s, "ActiveConnection", c.db)
	if err != nil {
		return nil, err
	}
	_, err = oleutil.PutProperty(s, "CommandText", query)
	if err != nil {
		return nil, err
	}
	_, err = oleutil.PutProperty(s, "CommandType", 1)
	if err != nil {
		return nil, err
	}
	_, err = oleutil.PutProperty(s, "Prepared", true)
	if err != nil {
		return nil, err
	}
	val, err := oleutil.GetProperty(s, "Parameters")
	if err != nil {
		return nil, err
	}
	return &AdodbStmt{c, s, val.ToIDispatch(), nil}, nil
}
func (pt *PowerPoint) open(inFile string) (err error) {

	ole.CoInitialize(0)

	var unknown *ole.IUnknown

	unknown, err = oleutil.CreateObject("PowerPoint.Application")
	if err != nil {
		return
	}

	pt.app, err = unknown.QueryInterface(ole.IID_IDispatch)
	if err != nil {
		return
	}

	_, err = oleutil.PutProperty(pt.app, "DisplayAlerts", 1)
	if err != nil {
		return
	}

	pt.presentations, err = oleutil.GetProperty(pt.app, "Presentations")
	if err != nil {
		return
	}

	pt.ppt, err = oleutil.CallMethod(pt.presentations.ToIDispatch(), "Open", inFile, -1, 0, 0)
	if err != nil {
		return
	}

	return
}
Example #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()
}
Example #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
}
Example #5
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
}
Example #6
0
func (this *Excel) CellsWrite(value string, row int, column int) (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()
	oleutil.PutProperty(cells, "Value", value)

	defer cells.Release()
	return err
}
Example #7
0
func (s *AdodbStmt) bind(args []driver.Value) error {
	if s.b != nil {
		for i, v := range args {
			var b string = "?"
			if len(s.b) < i {
				b = s.b[i]
			}
			unknown, err := oleutil.CallMethod(s.s, "CreateParameter", b, 12, 1)
			if err != nil {
				return err
			}
			param := unknown.ToIDispatch()
			defer param.Release()
			_, err = oleutil.PutProperty(param, "Value", v)
			if err != nil {
				return err
			}
			_, err = oleutil.CallMethod(s.ps, "Append", param)
			if err != nil {
				return err
			}
		}
	} else {
		for i, v := range args {
			var varval ole.VARIANT
			varval.VT = ole.VT_I4
			varval.Val = int64(i)
			val, err := oleutil.CallMethod(s.ps, "Item", &varval)
			if err != nil {
				return err
			}
			item := val.ToIDispatch()
			defer item.Release()
			_, err = oleutil.PutProperty(item, "Value", v)
			if err != nil {
				return err
			}
		}
	}
	return nil
}
Example #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)
}
Example #9
0
func (wd *Word) open(inFile string) (err error) {

	ole.CoInitialize(0)

	var unknown *ole.IUnknown

	unknown, err = oleutil.CreateObject("Word.Application")
	if err != nil {
		return
	}

	wd.app, err = unknown.QueryInterface(ole.IID_IDispatch)
	if err != nil {
		return
	}

	_, err = oleutil.PutProperty(wd.app, "Visible", false)
	if err != nil {
		return
	}

	_, err = oleutil.PutProperty(wd.app, "DisplayAlerts", 0)
	if err != nil {
		return
	}

	wd.documents, err = oleutil.GetProperty(wd.app, "Documents")
	if err != nil {
		return
	}

	wd.doc, err = oleutil.CallMethod(wd.documents.ToIDispatch(), "Open", inFile)
	if err != nil {
		return
	}

	return
}
Example #10
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")
}