 | OO-Snippets: Change a text cell to a cell with URL objectCommons| Keywords | insert, replace, URL, content, cell |
|---|
| Language | ooRexx |
|---|
| Application | Calc |
|---|
| Authors | Josef Frysak (initial)
|
|---|
| Supported Versions | 2.4.1 |
|---|
| Supported OS | All |
|---|
| Question | How to insert an URL to a cell?
|
|---|
| Answer | First only one selected cell must be retrieved. Therefore store the old selection into a variable, then create a new cell cursor out of the current selection and then restore the old selection. Now create a new "URL" object and insert it as text content of the cell. For further details see http://wi.wu-wien.ac.at/rgf/diplomarbeiten/BakkStuff/2008/200809_Frysak/200809_Frysak_Automating_OOo_ooRexx_Nutshells.pdf. |
|---|
x_ScriptContext = uno.getScriptContext()
if (x_ScriptContext <> .nil) then
do
x_ComponentContext = x_ScriptContext~getComponentContext
x_Desktop = x_ScriptContext~getDesktop
x_Document = x_ScriptContext~getDocument
end
else
do
x_ComponentContext = UNO.connect()
service = "com.sun.star.frame.Desktop"
s_Desktop = x_ComponentContext~getServiceManager~XMultiServiceFactory~createInstance(service)
x_Desktop = s_Desktop~XDesktop
x_Document = x_Desktop~getCurrentComponent()
end
x_SpreadsheetDocument = x_Document~XSpreadsheetDocument
x_Spreadsheets = x_SpreadsheetDocument~getSheets()
x_SpreadsheetIA = x_Spreadsheets~XIndexAccess
x_Model = x_Document~XModel
currentselection = x_Model~getCurrentSelection()
s_CurrentController = x_Model~getCurrentController()
x_MultiServiceFactory = x_Document~XMultiServiceFactory
newselection = x_MultiServiceFactory~createInstance("com.sun.star.sheet.SheetCellRanges")
x_View = s_CurrentController~XSelectionSupplier
x_View~select(newselection)
noselectioncell = x_Model~getCurrentSelection()
x_CellAddressable = noselectioncell~XCellAddressable
st_CellAddress = x_CellAddressable~getCellAddress()
x_View~select(currentselection)
currentcell.sheet = st_CellAddress~bsf.getFieldValue("Sheet")
currentcell.column = st_CellAddress~bsf.getFieldValue("Column")
currentcell.row = st_CellAddress~bsf.getFieldValue("Row")
s_Spreadsheet = x_SpreadsheetIA~getByIndex(currentcell.sheet)
x_Spreadsheet = s_Spreadsheet~XSpreadsheet
cell = uno.getCell(x_Spreadsheet, currentcell.column, currentcell.row)
x_TextRange = cell~XTextRange
x_Text = x_TextRange~getText()
urlstring = x_Text~getString()
s_urlfield = x_MultiServiceFactory~createInstance("com.sun.star.text.TextField.URL")
urlproperties = s_urlfield~XPropertySet
urlproperties~setPropertyValue("Representation", urlstring)
urlproperties~setPropertyValue("URL", urlstring)
x_TextContent = s_urlfield~XTextContent
x_Text~setString("")
x_Text~insertTextContent(x_Text~createTextCursor(), x_TextContent, .false)
::requires UNO.CLS
|
Changelog| Date | User | Modification |
|---|
| 2008-10-13 | 1 | Initial version |
|