Page 1 of 1

[Solved] Inserting Data from Web Into a Specific Cell

Posted: Sun Jun 12, 2016 11:50 pm
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

Re: Inserting Data from Web Into a Specific Cell

Posted: Mon Jun 13, 2016 9:50 pm
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

Re: Inserting Data from Web Into a Specific Cell

Posted: Wed Jun 15, 2016 5:27 pm
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