addCell
addCell
BASIC / ADVANCED / PREMIUM
Adds cell contents into the Excel spreadsheet.
Description
public addCell($contents, $position, $cellStyles = array(), $options = array())
This method allows adding contents into cells setting a position.
Parameters
contents
This could be:
- a string
- an array with the following keys and values:
Key | Type | Description |
---|---|---|
text | string | The content to be inserted. |
bold | bool | If true the content will be shown in bold characters. |
color | string | Hexadecimal color value: 'FF0000', '000000'... |
font | string | Font family: 'Arial', 'Calibri'... |
fontSize | int | Font size in points. |
italic | bool | If true displays the content in italics. |
strikethrough | bool | If true displays text in strikethrough. |
subscript | bool | If true displays text in subscript. |
superscript | bool | If true displays text in superscript. |
underline | string | Underlines text: single, double. |
- a multidimensional array to add rich text contents
position
Cell position in the active sheet: A1, C3, AB7...
cellStyles
Key | Type | Description |
---|---|---|
backgroundColor | string | Hexadecimal color value: 'FFFF00', 'CCCCCC'... |
border | string | Border type: thin, thick, dashed, double, mediumDashDotDot, hair... This value can be overridden for each side with 'borderTop', 'borderRight', 'borderBottom', 'borderLeft' and 'borderDiagonal' properties. |
borderColor | string | Hexadecimal color value: 'FFFF00', 'CCCCCC'... This value can be overridden for each side with 'borderColorTop', 'borderColorRight', 'borderColorBottom', 'borderColorLeft' and 'borderColorDiagonal' properties. |
cellStyleName | string | Cell style name.
|
horizontalAlign | string | left, center, right. |
indent | int | Indent value. |
isFunction | bool | Set the content as function. Default as false. If not set, if the content starts with = , isFunction is set as true (set isFunction as false to avoid this). |
locked | bool | Locked property. |
rotation | int | Orientation degrees. |
shrinkToFit | bool | If true enables shrink to fit. |
textDirection | string | context, ltr, rtl. |
type | string | Cell type: general (default), number, currency, accounting, date, time, percentage, fraction, scientific, text, special, boolean. |
typeOptions | array | Keys and values:
|
verticalAlign | string | top, center, bottom. |
wrapText | bool | If true enables wrap text. |
options
Key | Type | Description |
---|---|---|
insertMode | string | Insert mode if the position contains an existing content: 'replace', 'ignore'. Default as replace. |
raw | bool | Add the raw content if true. Default as false. |
useCellStyles | bool | Use existing cell styles. Default as false. |
Code samples
Release notes
- phpxlsx 4.0:
- clean calcChain values of the chosen position automatically.
- phpxlsx 1.0:
- new method.