// This example creates a new spreadsheet, reads and modifies cell values and style. func main() { ole.CoInitialize(0) unknown, errCreate := oleutil.CreateObject("com.sun.star.ServiceManager") checkError(errCreate, "Couldn't create a OLE connection to LibreOffice") ServiceManager, errSM := unknown.QueryInterface(ole.IID_IDispatch) checkError(errSM, "Couldn't start a LibreOffice instance") desktop := oleutil.MustCallMethod(ServiceManager, "createInstance", "com.sun.star.frame.Desktop").ToIDispatch() document := LONewSpreadsheet(desktop) sheet0 := LOGetWorksheet(document, 0) cell1_1 := LOGetCell(sheet0, 1, 1) // cell B2 cell1_2 := LOGetCell(sheet0, 1, 2) // cell B3 cell1_3 := LOGetCell(sheet0, 1, 3) // cell B4 cell1_4 := LOGetCell(sheet0, 1, 4) // cell B5 LOSetCellString(cell1_1, "Hello World") LOSetCellValue(cell1_2, 33.45) LOSetCellFormula(cell1_3, "=B3+5") b4Value := LOGetCellString(cell1_3) LOSetCellString(cell1_4, b4Value) // set background color yellow: oleutil.MustPutProperty(cell1_1, "cellbackcolor", 0xFFFF00) fmt.Printf("Press [ENTER] to exit") fmt.Scanf("%s") ServiceManager.Release() ole.CoUninitialize() }
func main() { log.SetFlags(log.Flags() | log.Lshortfile) 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() cwd, _ := os.Getwd() writeExample(excel, workbooks, cwd+"\\write.xls") readExample(cwd+"\\excel97-2003.xls", excel, workbooks) showMethodsAndProperties(workbooks) workbooks.Release() // oleutil.CallMethod(excel, "Quit") excel.Release() ole.CoUninitialize() }
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() worksheet := oleutil.MustGetProperty(workbook, "Worksheets", 1).ToIDispatch() cell := oleutil.MustGetProperty(worksheet, "Cells", 1, 1).ToIDispatch() oleutil.PutProperty(cell, "Value", 12345) time.Sleep(2000000000) oleutil.PutProperty(workbook, "Saved", true) oleutil.CallMethod(workbook, "Close", false) oleutil.CallMethod(excel, "Quit") excel.Release() ole.CoUninitialize() }