Difference between revisions of "NL/Documentation/BASIC Guide/Editing Spreadsheet Documents"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Created page with "{{NL/Documentation/BASICGuideTOC/v2 |ShowPrevNext=block |ShowPrevPage=block |PrevPage=NL/Documentation/BASIC Guide/Structure of Spreadsheets |NextPage=NL/Documentation/BASIC G..." (tussenstap opslaan))
 
Line 25: Line 25:
 
Een dubbele punt (:) wordt gebruikt om een celbereik in een werkbladdocument te specificeren. Bijvoorbeeld, A1:C15 vertegenwoordigt alle cellen in de rijen 1 tot en met 15 in de kolommen A, B, en C.
 
Een dubbele punt (:) wordt gebruikt om een celbereik in een werkbladdocument te specificeren. Bijvoorbeeld, A1:C15 vertegenwoordigt alle cellen in de rijen 1 tot en met 15 in de kolommen A, B, en C.
  
Als de positie va het celbereik allen tijdens runtime bekend is, gebruik dan de volgende code:
+
Als de positie van het celbereik alleen tijdens runtime bekend is, gebruik dan de volgende code:
  
 
<source lang="oobas">
 
<source lang="oobas">
Line 37: Line 37:
 
</source>
 
</source>
  
The arguments of [http://api.openoffice.org/docs/common/ref/com/sun/star/sheet/XCellRangesAccess.html#getCellRangeByPosition <code>getCellRangeByPosition</code>] are the position of the upper left cell of the range, followed by the position of the bottom right cell of the same range.
+
De argumenten van [http://api.openoffice.org/docs/common/ref/com/sun/star/sheet/XCellRangesAccess.html#getCellRangeByPosition <code>getCellRangeByPosition</code>] zijn de positie van de cel linksboven in het bereik, gevolgd door de positie van de cel rechtsonder van hetzelfde bereik.
  
The location of individual cells in a cell range can be determined using the <tt>getCellByPosition</tt> method, where the coordinates of the top left cell in the cell range is (0, 0). The following example uses this method to create an object of cell C3.
+
De lokatie van individuele cellen in een celbereik kunnen worden bepaald met behulp van de methode <tt>getCellByPosition</tt>, waar de coördinaten van de cel aan de linkerbovenzijde zijn (0, 0). Het volgende voorbeeld gebruikt deze methode om een object te maken van cel C3.
  
 
<source lang="oobas">
 
<source lang="oobas">
 
Dim Doc As Object
 
Dim Doc As Object
Dim Sheet As Object
+
Dim Blad As Object
Dim CellRange As Object
+
Dim CelBereik As Object
Dim Cell As Object
+
Dim Cel As Object
  
 
Doc = ThisComponent
 
Doc = ThisComponent
Sheet = Doc.Sheets.getByName("Sheet 1")
+
Blad = Doc.Sheets.getByName("Blad 1")
CellRange = Sheet.getCellRangeByName("B2:D4")
+
CelBereik = Blad.getCellRangeByName("B2:D4")
Cell = CellRange.GetCellByPosition(1, 1)
+
Cel = CelBereik.GetCellByPosition(1, 1)
 
</source>
 
</source>
  
=== Formatting Cell Ranges ===
+
=== Celbereiken opmaken ===
Just like individual cells, you can apply formatting to cell ranges using the <idl>com.sun.star.table.CellProperties</idl> service. For more information and examples of this service, see [[Documentation/BASIC Guide/Formatting Spreadsheet Documents|Formatting Spreadsheet Documents]].
+
Net als individuele cellen, kunt u opmaak toepassen op celbereiken met behulp van de service <idl>com.sun.star.table.CellProperties</idl>. Bekijk [[Documentation/BASIC Guide/Formatting Spreadsheet Documents|Werkbladdocumenten opmaken]] voor meer informatie en voorbeelden van deze service.
  
 
=== Computing With Cell Ranges ===
 
=== Computing With Cell Ranges ===

Revision as of 13:51, 3 March 2013

Book.png


Waar het voorgaande gedeelte de hoofdstructuur van werkbladdocumenten beschreef, beschrijft dit gedeelte de services die u in staat stellen eenvoudig toegang te krijgen tot individuele cellen of celbereiken.

Celbereiken

In aanvulling op een object voor individuele cellen (service com.sun.star.table.Cell), verschaft Apache OpenOffice ook objecten die celbereiken vertegenwoordigen. Zulke objecten CellRange worden gemaakt met behulp van de aanroep getCellRangeByName van het object werkblad:

Dim Doc As Object
Dim Blad As Object
Dim CelBereik As Object
 
Doc = ThisComponent
Blad = Doc.Sheets.getByName("Blad 1")
CelBereik = Blad.getCellRangeByName("A1:C15")

Een dubbele punt (:) wordt gebruikt om een celbereik in een werkbladdocument te specificeren. Bijvoorbeeld, A1:C15 vertegenwoordigt alle cellen in de rijen 1 tot en met 15 in de kolommen A, B, en C.

Als de positie van het celbereik alleen tijdens runtime bekend is, gebruik dan de volgende code:

Dim Doc As Object
Dim Blad As Object
Dim CelBereik As Object
 
Doc = ThisComponent
Blad = Doc.Sheets.getByName("Blad 1")
CelBereik = Blad.getCellRangeByPosition(0, 0,  2, 14)

De argumenten van getCellRangeByPosition zijn de positie van de cel linksboven in het bereik, gevolgd door de positie van de cel rechtsonder van hetzelfde bereik.

De lokatie van individuele cellen in een celbereik kunnen worden bepaald met behulp van de methode getCellByPosition, waar de coördinaten van de cel aan de linkerbovenzijde zijn (0, 0). Het volgende voorbeeld gebruikt deze methode om een object te maken van cel C3.

Dim Doc As Object
Dim Blad As Object
Dim CelBereik As Object
Dim Cel As Object
 
Doc = ThisComponent
Blad = Doc.Sheets.getByName("Blad 1")
CelBereik = Blad.getCellRangeByName("B2:D4")
Cel = CelBereik.GetCellByPosition(1, 1)

Celbereiken opmaken

Net als individuele cellen, kunt u opmaak toepassen op celbereiken met behulp van de service com.sun.star.table.CellProperties. Bekijk Werkbladdocumenten opmaken voor meer informatie en voorbeelden van deze service.

Computing With Cell Ranges

You can use the computeFunction method to perform mathematical operations on cell ranges. The computeFunction expects a constant as the parameter that describes the mathematical function that you want to use. The associated constants are defined in the com.sun.star.sheet.GeneralFunction enumeration. The following values are available:

SUM
sum of all numerical values
COUNT
total number of all values (including non-numerical values)
COUNTNUMS
total number of all numerical values
AVERAGE
average of all numerical values
MAX
largest numerical value
MIN
smallest numerical value
PRODUCT
product of all numerical values
STDEV
standard deviation
VAR
variance
STDEVP
standard deviation based on the total population
VARP
variance based on the total population

The following example computes the average value of the A1:C3 range and prints the result in a message box:

Dim Doc As Object
Dim Sheet As Object
Dim CellRange As Object
 
Doc = ThisComponent
Sheet = Doc.Sheets.getByName("Sheet 1")
CellRange = Sheet.getCellRangeByName("A1:C3")
 
MsgBox CellRange.computeFunction(com.sun.star.sheet.GeneralFunction.AVERAGE)
Documentation caution.png Functions VAR, VARP, STDVERP return an incorrect value when applied to a properly defined range. See Issue 22625 .

Deleting Cell Contents

The clearContents method simplifies the process of deleting cell contents and cell ranges in that it deletes one specific type of content from a cell range.

The following example removes all the strings and the direct formatting information from the B2:C3 range.

Dim Doc As Object
Dim Sheet As Object
Dim CellRange As Object
Dim Flags As Long
 
Doc = ThisComponent
Sheet = Doc.Sheets(0)
CellRange = Sheet.getCellRangeByName("B2:C3")
 
Flags = com.sun.star.sheet.CellFlags.STRING + _
      com.sun.star.sheet.CellFlags.HARDATTR
 
CellRange.clearContents(Flags)

The flags specified in clearContents come from the com.sun.star.sheet.CellFlags constants list. This list provides the following elements:

VALUE
numerical values that are not formatted as date or time
DATETIME
numerical values that are formatted as date or time
STRING
strings
ANNOTATION
comments that are linked to cells
FORMULA
formulas
HARDATTR
direct formatting of cells
STYLES
indirect formatting
OBJECTS
drawing objects that are connected to cells
EDITATTR
character formatting that only applies to parts of the cells

You can also add the constants together to delete different information using a call from clearContents.

Searching and Replacing Cell Contents

Spreadsheet documents, like text documents, provide a function for searching and replacing.

The descriptor objects for searching and replacing in spreadsheet documents are not created directly through the document object, but rather through the Sheets list. The following is an example of a search and replace process:

Dim Doc As Object
Dim Sheet As Object
Dim ReplaceDescriptor As Object
Dim I As Integer
 
Doc = ThisComponent
Sheet = Doc.Sheets(0)
 
ReplaceDescriptor = Sheet.createReplaceDescriptor()
ReplaceDescriptor.SearchString = "is"
ReplaceDescriptor.ReplaceString = "was"
For I = 0 to Doc.Sheets.Count - 1
   Sheet = Doc.Sheets(I)
   Sheet.ReplaceAll(ReplaceDescriptor) 
Next I

This example uses the first page of the document to create a ReplaceDescriptor and then applies this to all pages in a loop.


Content on this page is licensed under the Public Documentation License (PDL).
Personal tools