[Solved] Inserting Data from Web Into a Specific Cell

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Mandrake
Posts: 7
Joined: Sun Jun 12, 2016 2:01 am

[Solved] Inserting Data from Web Into a Specific Cell

Post by Mandrake »

Hello there,

I have found the code bellow on this forum. I have been trying to get the link downloaded into a specific cell... without any success. Is there anyway I can get the link downloaded into a specific cell?

Code: Select all

 
Sub InsertWebLinkAtSelection(url As String)
   Dim oDoc As Object
   Dim oSelection
   Dim oAddress As new com.sun.star.table.CellAddress
   
   oDoc = ThisComponent
   oSelection = oDoc.getCurrentController().getSelection()
   if oSelection.supportsService("com.sun.star.sheet.SheetCell") then
      oAddress = oSelection.getCellAddress()
      oDoc.AreaLinks.insertAtPosition(oAddress,url,"HTML_all","calc_HTML_WebQuery","0 0")
   endif

End Sub

Code adapted, but not working:

Code: Select all

Sub InsertWebLinkAtSelection(url As String)
   Dim oDoc As Object
   Dim oSelection
   Dim oAddress As new com.sun.star.table.CellAddress
   
   oDoc = ThisComponent
   oSelection = oDoc.Sheets.getByName("tmp")
   if oSelection.supportsService("com.sun.star.sheet.SheetCell") then
      oAddress = oSelection.getCellRangeByName("A9")
      oDoc.AreaLinks.insertAtPosition(oAddress,url,"HTML_all","calc_HTML_WebQuery","0 0")
   endif

End Sub

Thanks all for any help,

M
Last edited by Mandrake on Wed Jun 15, 2016 6:12 pm, edited 1 time in total.
OpenOffice4 , Yosemite
UnklDonald418
Volunteer
Posts: 1573
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Inserting Data from Web Into a Specific Cell

Post by UnklDonald418 »

Try this version

Code: Select all

Sub InsertWebLinkAtSelection(url As String)
   Dim oDoc As Object
   Dim oSelection
   Dim oAddress  As Object   ' As new com.sun.star.table.CellAddress
   
   oDoc = ThisComponent
   oSelection = oDoc.Sheets.getByName("tmp")
   if oSelection.supportsService("com.sun.star.sheet.SheetCellRange") then
      oAddress = oSelection.getCellRangeByName("A9")      
'      oDoc.AreaLinks.insertAtPosition(oAddress,url,"HTML_all","calc_HTML_WebQuery","0 0")
      oAddress.setString(url)
   endif

End Sub
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Mandrake
Posts: 7
Joined: Sun Jun 12, 2016 2:01 am

Re: Inserting Data from Web Into a Specific Cell

Post by Mandrake »

Hi,

Thanks for the fix. I have also found out that this works too:

Code: Select all

Sub InsertBalanceSheet(url As String)
	Dim oDoc As Object
	Dim oSheet
	Dim oSelection
	Dim oAddress As new com.sun.star.table.CellAddress
   
	oDoc = ThisComponent
	
	oSelection = oDoc.Sheets.getByName("tmp").getCellRangeByName("A9")
	if oSelection.supportsService("com.sun.star.sheet.SheetCell") then
		oAddress = oSelection.getCellAddress()
		oDoc.AreaLinks.insertAtPosition(oAddress,url,"HTML_5","calc_HTML_WebQuery","0 0")
   	endif

End Sub
OpenOffice4 , Yosemite
Post Reply