OO-Snippets: Insert Data Into Cells And Create Chart

Commons

Keywordschart, cell
LanguageooRexx
ApplicationCalc
AuthorsÅsmund Realfsen
Supported Versions2.0.x  1.1.x  1.0.x  
Supported OSAll  
QuestionWho do I insert cells and chreate a chart ?
Answer

Code-Snippet-Listing (snippet-source)

/* get the xComponentLoader interface */
componentLoader = UNO.createDesktop()~XDesktop~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~XSpreadSheetDocument~getSheets~XIndexAccess~getByIndex(0)~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~XPropertySet~setPropertyValue("CellBackColor", box("int", "00 00 77"x ~c2d))
heading~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("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")~xCellRangeAddressable~getRangeAddress

/* Create an array with data to insert into the chart */
CALL UNO.loadClass "com.sun.star.table.CellRangeAddress"
chartAddressArray = bsf.createArray(.UNO~CellRangeAddress, 1)
chartAddressArray[1] = chartCellRange

/* create and show chart */
chart = sheet~xTableChartsSupplier~getCharts
chart~addNewByName("myChart", chartRec, chartAddressArray, .true, .true)



::requires UNO.CLS  -- load support for Open Office


Changelog

DateUserModification
2006-07-08ÅRInitial version

and