LibreOffice Basic - Objecten: verschil tussen versies

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
 
(9 tussenliggende versies door dezelfde gebruiker niet weergegeven)
Regel 1: Regel 1:
 
''Dit artikel is vooral bedoeld als referentie. Daarom bronnen gelijk in de afzonderlijke hoofdstukken opnemen.''
 
''Dit artikel is vooral bedoeld als referentie. Daarom bronnen gelijk in de afzonderlijke hoofdstukken opnemen.''
 +
 +
== collapseToMergedArea() ==
 +
 +
Zie [[CollapseToMergedArea (LibreOffice Basic)]].
  
 
== copyByName() ==
 
== copyByName() ==
Regel 92: Regel 96:
  
 
* https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1sheet_1_1XCellRangeData.html#abde435a89989ab90d13779c1ec49ca00
 
* https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1sheet_1_1XCellRangeData.html#abde435a89989ab90d13779c1ec49ca00
 +
 +
== getRowSpan() ==
 +
 +
The ''XMergeableCell Interface'' provides methods to access information about a cell that is mergeable with other sells. ''getRowSpan'' returns the number of columns this cell spans.
 +
 +
Inheritance diagram:
 +
 +
<pre>
 +
XInterface » XCell » XMergeableCell
 +
</pre>
 +
 +
''' Syntaxis '''
 +
 +
<pre>
 +
long getRowSpan()
 +
</pre>
 +
 +
''' Bronnen '''
 +
 +
* https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1table_1_1XMergeableCell.html
  
 
== gotoEndOfUsedArea() ==
 
== gotoEndOfUsedArea() ==
Regel 147: Regel 171:
 
== hasByName() ==
 
== hasByName() ==
  
Test op het bestaan van een object met de gegeven naam.
+
true if an element with this name is in the container, false otherwise.
  
 
''' Voorbeeld '''
 
''' Voorbeeld '''
Regel 177: Regel 201:
  
 
end function
 
end function
 +
</pre>
 +
 +
''' Opmerkingen '''
 +
 +
Als je gewoon wilt testen wat de naam van een gegeven sheet is, krijg je een foutmelding. Wat dan bv. wel werkt:
 +
 +
<pre>
 +
function test_detect_sheet_by_name()
 +
'
 +
' Loop through all sheets
 +
'''''''''''''''''''''''''''''''''''''
 +
'
 +
for sheet_counter = 0 to ThisComponent.sheets.count-1
 +
 +
if ThisComponent.sheets(sheet_counter).name="Joepie" then
 +
 +
msgbox "Sheet 'Joepie' gevonden bij index " & sheet_counter
 +
 +
end if
 +
 +
next
 +
 +
end function
 +
</pre>
 +
 +
== insertByName ==
 +
 +
inserts the given element at the specified name.
 +
 +
''' Syntaxis '''
 +
 +
<pre>
 +
void insertByName
 +
(
 +
  string aName,
 +
  any    aElement
 +
)
 +
</pre>
 +
 +
Lijkt te werken met allerlei soorten objecten. <code>aElement</code> is waarschijnlijk afhankelijk van het soort object.
 +
 +
''' Voorbeeld '''
 +
 +
<pre>
 +
function insert_sheet_aggregate()
 +
'
 +
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 +
' Insert sheet 'Aggregate' (if not exists)
 +
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 +
'
 +
dim doc as object
 +
dim sheet as object
 +
 +
doc = ThisComponent
 +
 +
if ThisComponent.sheets.hasByName("Aggregate") then
 +
 +
' Do nothing: Sheet "Aggregate" bestaat al
 +
'
 +
' MsgBox "Sheet 'Aggregate' already exists"
 +
 +
else
 +
 +
sheet = doc.createInstance("com.sun.star.sheet.Spreadsheet")
 +
doc.sheets.insertByName("Aggregate",sheet)
 +
 +
end if
 +
 +
end function
 +
</pre>
 +
 +
 +
''' Bronnen '''
 +
 +
* https://www.openoffice.org/api/docs/common/ref/com/sun/star/container/XNameContainer.html
 +
 +
== insertNewByName() ==
 +
 +
Inserts a new sheet into the collection. You can specify its position!
 +
 +
''' Voorbeeld '''
 +
 +
<pre>
 +
function insert_sheet_aggregate()
 +
'
 +
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 +
' Insert sheet 'Aggregate' at first position (if not exists)
 +
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 +
'
 +
if ThisComponent.sheets.hasByName("Aggregate") then
 +
'
 +
' Do nothing: Sheet "Aggregate" bestaat al
 +
'
 +
else
 +
'
 +
ThisComponent.Sheets.insertNewByName("Aggregate", 0)
 +
'
 +
end if
 +
 +
end function
 +
</pre>
 +
 +
''' Bronnen '''
 +
 +
* https://www.openoffice.org/api/docs/common/ref/com/sun/star/sheet/XSpreadsheets.html#insertNewByName
 +
 +
== isMerged() ==
 +
 +
returns true if this cell is merged with another cell.
 +
 +
''' Syntaxis '''
 +
 +
<pre>
 +
boolean isMerged()
 
</pre>
 
</pre>

Huidige versie van 6 nov 2019 om 12:41

Dit artikel is vooral bedoeld als referentie. Daarom bronnen gelijk in de afzonderlijke hoofdstukken opnemen.

collapseToMergedArea()

Zie CollapseToMergedArea (LibreOffice Basic).

copyByName()

copyByName is een method van sheets.

Syntaxis

void copyByName
(
   [in] string aName,
   [in] string aCopy,
   [in] short  nDestination
)

* aName:        Name of the sheet to be copied
* aCopy:        Name of the copied sheet
* nDestination: Numerical index of the new sheet

Voorbeeld

Sub CopySheet
    Dim oCurrentController As Object
    Dim oActiveSheet As Object
    Dim oSheets As Object
    oCurrentController = ThisComponent.getCurrentController()
    oActiveSheet = oCurrentController.getActiveSheet()
    oSheets = ThisComponent.getSheets()
    If oSheets.hasByName( oActiveSheet.Name & "Copy" ) Then
        MsgBox "Sheet name " & oActiveSheet.Name & "Copy, already exists"
    Else
        oSheets.copyByName(oActiveSheet.Name, oActiveSheet.Name & "Copy", oActiveSheet.RangeAddress.Sheet + 1)
    End If
End Sub

Bronnen

getCellRangeByPosition()

Kopiëer cellen aan de hand van hun coördinaten - Method van sheets

Syntaxis

data_array = sheet.getCellRangeByPosition
(
   x_start,
   y_start,
   x_end,
   y_end
)

Voorbeeld

function copy_paste_test()
	'
	''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	' Copy & paste een paar cellen binnen de eerste sheet
	''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	'
	cell_org=ThisComponent.sheets(0).getCellRangeByPosition(0,0,0,2)
	cell_dest=ThisComponent.sheets(0).getCellByPosition(3,3)

	ThisComponent.sheets(0).copyRange _
	( _
		cell_dest.CellAddress, _
		cell_org.RangeAddress _
	)	
	
end function

getDataArray()

Get an array from the contents of the cell range.

Syntaxis

sequence< sequence< any > > getDataArray()

Bronnen

getRowSpan()

The XMergeableCell Interface provides methods to access information about a cell that is mergeable with other sells. getRowSpan returns the number of columns this cell spans.

Inheritance diagram:

XInterface » XCell » XMergeableCell

Syntaxis

long getRowSpan()

Bronnen

gotoEndOfUsedArea()

Ga met de cursor naar de laatste gebruikte cel in betreffende sheet.

Syntaxis

gotoEndOfUserArea
(
   boolean bExpand
)

bExpand: 

* true: Expands the current cursor range
* false: Sets size of the cursor to a single cell

Voorbeeld

function get_used_area_coordinates()
   '
   ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   ' Get used area coordinates
   ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   '
   ' Create a cursor on the first sheet
   ''''''''''''''''''''''''''''''''''''
   '    
   o_cursor = ThisComponent.Sheets(0).createCursor()

   ' Goto end of used are
   ''''''''''''''''''''''''''''''''''''
   '
   o_cursor.gotoEndOfUsedArea(false)

   ' Retrieve number of rows & columns
   ''''''''''''''''''''''''''''''''''''
   '
   i_rows = o_cursor.getRangeAddress().EndRow+1
   i_columns = o_cursor.getRangeAddress().EndColumn+1

   ' Display to user
   ''''''''''''''''''''''''''''''''''''
   '
   msgBox "Rijen: " & i_rows
   msgBox "Kolommen: " & i_columns

end function

hasByName()

true if an element with this name is in the container, false otherwise.

Voorbeeld

function insert_sheet()
	'
	''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	' Insert sheet 'Aggregate' (if not exists)
	''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	'
	dim doc as object
	dim sheet as object
	
	doc = ThisComponent
	
	if ThisComponent.sheets.hasByName("Aggregate") then
	
		' Do nothing: Sheet "Aggregate" bestaat al
		'
		MsgBox "Sheet 'Aggregate' already exists"
		
	else
	
		sheet = doc.createInstance("com.sun.star.sheet.Spreadsheet")
		doc.sheets.insertByName("Aggregate",sheet)	
	
	end if

end function

Opmerkingen

Als je gewoon wilt testen wat de naam van een gegeven sheet is, krijg je een foutmelding. Wat dan bv. wel werkt:

function test_detect_sheet_by_name()
	'
	' Loop through all sheets
	'''''''''''''''''''''''''''''''''''''
	'
	for sheet_counter = 0 to ThisComponent.sheets.count-1

		if ThisComponent.sheets(sheet_counter).name="Joepie" then
		
			msgbox "Sheet 'Joepie' gevonden bij index " & sheet_counter

		end if

	next
	
end function					

insertByName

inserts the given element at the specified name.

Syntaxis

void insertByName
(
   string aName,
   any    aElement
)

Lijkt te werken met allerlei soorten objecten. aElement is waarschijnlijk afhankelijk van het soort object.

Voorbeeld

function insert_sheet_aggregate()
	'
	''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	' Insert sheet 'Aggregate' (if not exists)
	''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	'
	dim doc as object
	dim sheet as object
	
	doc = ThisComponent
	
	if ThisComponent.sheets.hasByName("Aggregate") then
	
		' Do nothing: Sheet "Aggregate" bestaat al
		'
		' MsgBox "Sheet 'Aggregate' already exists"
		
	else
	
		sheet = doc.createInstance("com.sun.star.sheet.Spreadsheet")
		doc.sheets.insertByName("Aggregate",sheet)	
	
	end if

end function


Bronnen

insertNewByName()

Inserts a new sheet into the collection. You can specify its position!

Voorbeeld

function insert_sheet_aggregate()
	'
	''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	' Insert sheet 'Aggregate' at first position (if not exists)
	''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	'
	if ThisComponent.sheets.hasByName("Aggregate") then
		'	
		' Do nothing: Sheet "Aggregate" bestaat al
		'
	else
		'	
		ThisComponent.Sheets.insertNewByName("Aggregate", 0)
		'
	end if

end function

Bronnen

isMerged()

returns true if this cell is merged with another cell.

Syntaxis

boolean isMerged()