chart cell Åsmund Realfsen Who do I insert cells and chreate a chart ? /* get the xComponentLoader interface */ componentLoader = UNO.createDesktop()~{%see com.sun.star.frame.XDesktop%XDesktop}~{%see com.sun.star.frame.XComponentLoader%XComponentLoader} /* start OO-Calc with a blank document */ calcComponent = componentLoader~loadComponentFromURL("private:factory/scalc", "_blank", 0, .UNO~noProps) /* get the first sheet in calc */ sheet = calcComponent~{%see com.sun.star.sheet.XSpreadsheetDocument%XSpreadSheetDocument}~getSheets~{%see com.sun.star.container.XIndexAccess%XIndexAccess}~getByIndex(0)~{%see com.sun.star.sheet.XSpreadsheet%XSpreadSheet} /* Use a procedure in uno.cls to write text into a cells */ CALL UNO.setCell sheet, 0, 0, "Number" -- this is the heading of col one CALL UNO.setCell sheet, 1, 0, "SIN(A)" -- this is the heading of col two CALL UNO.setCell sheet, 2, 0, "SIN(A*B)" -- this is the heading of col three /* select the range a1:c1, and apply formating */ heading = sheet~getCellRangeByName("A1:C1") heading~{%see com.sun.star.beans.XPropertySet%XPropertySet}~setPropertyValue("CellBackColor", box("int", "00 00 77"x ~c2d)) heading~{%see com.sun.star.beans.XPropertySet%XPropertySet}~setPropertyValue("CharHeight", box("float", "14.0")) last_value = -1 do i=1 to 30 by 1 /* write content to a cell using a routine from UNO.CLS */ CALL UNO.setCell sheet, 0, i, i/5 /* Write content to a cell without help from UNO.CLS, alternative mehtod */ sheet~getCellByPosition(1,i)~setFormula("=SIN(A"i+1")") sheet~getCellByPosition(2,i)~setFormula("=SIN(A"i+30"-B"i+1")") end /* create dimensions for chart */ chartRec = .bsf~new("{%see com.sun.star.awt.Rectangle}") chartRec~X = 7000 chartRec~Y = 0 chartRec~Width = 20000 chartRec~Height = 10000 /* select cell range for chart */ chartCellRange = sheet~getCellRangeByName("A1:C31")~{%see com.sun.star.sheet.XCellRangeAddressable%xCellRangeAddressable}~getRangeAddress /* Create an array with data to insert into the chart */ CALL UNO.loadClass "{%see com.sun.star.table.CellRangeAddress}" chartAddressArray = bsf.createArray(.UNO~CellRangeAddress, 1) chartAddressArray[1] = chartCellRange /* create and show chart */ chart = sheet~{%see com.sun.star.table.XTableChartsSupplier%xTableChartsSupplier}~getCharts chart~addNewByName("myChart", chartRec, chartAddressArray, .true, .true) ::requires UNO.CLS -- load support for Open Office Initial version