Advertisement
siedlerchr

Get content of selected spreadsheet cells

Aug 14th, 2015
2,704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'get the content of the selected spreadsheet cells in open office / libre office
  2. Sub GetSelection()
  3.  
  4.     Dim oDoc, oSel, oCell
  5.  
  6.     oDoc = ThisComponent
  7.     oSel = oDoc.getCurrentSelection()
  8.    
  9.  
  10.     If oSel.supportsService("com.sun.star.sheet.SheetCell") Then
  11.         MsgBox "One Cell selected and it contains: " & oSel.getString()
  12.     Else
  13.         If oSel.supportsService("com.sun.star.sheet.SheetCellRange") Then
  14.             MsgBox "One Cell Range selected " & oSel.AbsoluteName 'Absolute Adresse der Selektion
  15.            
  16.             for i = 0 to oSel.getColumns.getCount - 1
  17.                 for j = 0 to oSel.getRows.getCount - 1
  18.                     oCell = oSel.getCellByPosition(i,j)
  19.                     msgbox "Cell " &i & ","& j & " string value  "  &  oCell.String
  20.                 next
  21.             Next
  22.            
  23.         Else
  24.             If oSel.supportsService("com.sun.star.sheet.SheetCellRanges") Then
  25.                 Msgbox "Multiple Cell Ranges selected. Total=" & oSel.getCount()
  26.             Else
  27.                 Print "Somethine else is selected."
  28.             End If
  29.         End If
  30.     End If 
  31. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement