Advertisement
siedlerchr

GetUnionRange in open office basic calc spreadsheet

Oct 17th, 2015
3,127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Implying Range 1 > Range 2
  2. Function getUnionRange(Byval range1, Byval range2)
  3. Dim rg1Addr, rg2Addr
  4.  rg1Addr = range1.getRangeAddress()
  5.  rg2Addr = range2.getRangeAddress()
  6.  
  7.  rg1Addr.StartRow = rg1Addr.StartRow
  8.  rg1Addr.EndRow =   rg2Addr.EndRow
  9.  rg1Addr.StartColumn = rg1Addr.StartColumn
  10.  rg1Addr.EndColumn =  rg2Addr.EndColumn
  11.  
  12.  getUnionRange = getRangeByAddress(range1.getSpreadsheet(),rg1Addr)
  13.  
  14. End Function
  15.  
  16. 'pass a spreadsheet-document, sheet or range  together with a c.s.s.table.CellRangeAddress
  17. 'return empty if oAddr out of bounds or wrong obj
  18. Function getRangeByAddress(obj, oAddr as com.sun.star.table.CellRangeAddress)
  19. on error goto nullErr:
  20. Dim oSheet
  21.    If obj.supportsService("com.sun.star.sheet.SpreadsheetDocument") then
  22.       REM use the sheet specified by given address
  23.       oSheet = obj.getSheets.getByIndex(oAddr.Sheet)
  24.    else
  25.       REM use given object (range/sheet) as parent range
  26.       oSheet = obj
  27.    endif
  28.    getRangeByAddress = oSheet.getCellRangeByPosition(oAddr.StartColumn,oAddr.StartRow,oAddr.EndColumn,oAddr.EndRow)
  29. exit function
  30. nullErr:
  31.    getRangeByAddress = Null
  32. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement