//put Property. func PutProperty(idisp *ole.IDispatch, args ...interface{}) (err error) { defer Except("PutProperty", &err) argnum := len(args) if argnum == 1 { oleutil.MustPutProperty(idisp, "Value", args[0]) } else if argnum > 1 { maxi := argnum - 2 for i := 0; i < maxi && err == nil; i++ { idisp = oleutil.MustGetProperty(idisp, args[i].(string)).ToIDispatch() defer DoFuncs(idisp.Release) } //put multi-Property if argv, ok := args[argnum-1].(map[string]interface{}); ok { idisp = oleutil.MustGetProperty(idisp, args[maxi].(string)).ToIDispatch() defer DoFuncs(idisp.Release) for key, val := range argv { oleutil.MustPutProperty(idisp, key, val) } } else { oleutil.MustPutProperty(idisp, args[maxi].(string), args[argnum-1]) } } else { err = errors.New("args is empty") } return }
// 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 (sheet Sheet) Name(args ...string) (name string) { defer Except("", nil) if len(args) == 0 { name = oleutil.MustGetProperty(sheet.Idisp, "Name").ToString() } else { name = args[0] oleutil.MustPutProperty(sheet.Idisp, "Name", name) } return }
// LOSetCellFormulaLocal sets the formula in the user's language (e.g. German =SUMME instead of =SUM) func LOSetCellFormulaLocal(cell *ole.IDispatch, formula string) { oleutil.MustPutProperty(cell, "FormulaLocal", formula) }
// LOSetCellValue sets the numeric value of a cell func LOSetCellValue(cell *ole.IDispatch, value float64) { oleutil.MustPutProperty(cell, "value", value) }
// LOSetCellString sets the text value of a cell func LOSetCellString(cell *ole.IDispatch, text string) { oleutil.MustPutProperty(cell, "string", text) }