|
|
The Cell Object (SACell)
Use Cell to create a Cell object. A Cell object represents a single cell. The following example demonstrates
setting a Cell object, and assigning a value to it.
set cellB26 = ws.cells("B26")
cellB26.value = "Product"
Cell Methods and Properties
*This feature is not
available in ExcelWriterSE, ExcelWriterLE, and ExcelWriterFree.
| Cell Methods and Properties |
| ClearContents* V4 |
The ClearContents method deletes any value
or formula within the specified cell. The following example opens the spreadsheet
clearcell.xls, and deletes the content of cells B4:B8.
Top |
| Col |
Returns the column number of a specified cell. The following example
demonstrates setting a cell object, and retrieving its column number.
set cell = ws.cells("B26")
CellColumn = cell.col
Top |
| Format |
Use Format to create a look for a single cell. Both Format and
Style define the appearance of cells. However, Style is used to define the look
of a set of cells, while Format defines the look of an individual cell.
Define a format for a single cell, rather than create a style, only if it is unlikely
that you will apply the same format to other cells. Whenever you define a format for an
individual cell, you add format information to the spreadsheet, so if you define the same
format repeatedly, the resulting spreadsheet file will be unnecessarily large. When you
apply a single Style object to several cells, the style information is written to the
spreadsheet only once, conserving space.
The properties of Format are, Font,
Hidden, HorizontalAlignment, Locked, Number, Orientation, VerticalAlignment, and WrapText. For definitions
of each of these properties, see Style. The following example demonstrates
defining a format for a cell.
ws.Cells("E6").Format.Font.Name = "Times New Roman"
ws.Cells("E6").Format.Font.Color = 255 '--- RGB Value
ws.Cells("E6").Format.Orientation = saoriClockWise
Top |
| Formula |
Use Formula to add Microsoft Excel formulas to your spreadsheet.
For a complete list of available formulas see Formula Functions.
When applying a formula to a cell, always use an equal sign (=), as you would when creating an Excel spreadsheet.
The following example demonstrates using a formula.
ws.Cells("b6").Formula = "=sum(b2:b3)"
Top |
| Name |
Returns the specified cell's name. A cell name includes
its column letter and row number, for example B5. To retrieve the name of a cell, use,
Top |
| PutValue |
Puts a value in a cell.
cell.PutValue("Grand Total")
is equivalent to,
cell.value = "Grand Total"
Top |
| Row |
Return the row number of a specified cell. The following example
demonstrates setting a cell object, and retrieving its row number.
set cell = ws.cells("B26")
CellRow = cell.row
Top |
| Style |
Use Style to apply a defined Style object to a cell. Both Format and Style
define the look of cells, but a format is created for a single cell, while a style is defined for reuse.
Define a format for a single cell, rather than create a style, only if it is unlikely
that you will apply the same format to other cells. Whenever you define a format for an
individual cell, you add format information to the spreadsheet, so if you define the same
format repeatedly, the resulting spreadsheet file will be unnecessarily large. When you
apply a single Style object to several cells, the style information is written to the
spreadsheet only once, conserving space.
To define a style, first set a Style object, and assign values to any or all of its properties, for example,
Set mystyle = xlw.CreateStyle
mystyle.Font.Name = "Arial"
mystyle.Font.Bold = True
mystyle.HorizontalAlignment = sahaRight
Then, assign your style to individual cells, for example,
ws.cells("A1").style = mystyle
Top |
| Value |
Use Value to assign a value to a cell.
cell.value = "Grand Total"
is equivalent to,
cell.PutValue("Grand Total")
Top |
| *This feature is not
available in ExcelWriterSE, ExcelWriterLE, and ExcelWriterFree. |
Copyright © 2003, SoftArtisans, Inc.
|
|