@@ -8,7 +8,7 @@ topic lists some of the options to access a cell.
88Setting a cell value by coordinate can be done using the worksheet's
99` setCellValue() ` method.
1010
11- ``` php
11+ ``` php
1212// Set cell A1 with a string value
1313$spreadsheet->getActiveSheet()->setCellValue('A1', 'PhpSpreadsheet');
1414
@@ -28,7 +28,7 @@ $spreadsheet->getActiveSheet()->setCellValue(
2828Alternatively, you can retrieve the cell object, and then call the
2929cell’s ` setValue() ` method:
3030
31- ``` php
31+ ``` php
3232$spreadsheet->getActiveSheet()
3333 ->getCell('B8')
3434 ->setValue('Some value');
@@ -56,7 +56,7 @@ the cell object will still retain its data values.
5656
5757What does this mean? Consider the following code:
5858
59- ```
59+ ``` php
6060$spreadSheet = new Spreadsheet();
6161$workSheet = $spreadSheet->getActiveSheet();
6262
@@ -74,7 +74,7 @@ $cellA1 = $workSheet->getCell('A1');
7474echo 'Value: ', $cellA1->getValue(), '; Address: ', $cellA1->getCoordinate(), PHP_EOL;
7575
7676echo 'Value: ', $cellC1->getValue(), '; Address: ', $cellC1->getCoordinate(), PHP_EOL;
77- ```
77+ ```
7878
7979The call to ` getCell('C1') ` returns the cell at ` C1 ` containing its value (` 3 ` ),
8080together with its link to the collection (used to identify its
@@ -153,7 +153,7 @@ was a formula.
153153
154154To do this, you need to "escape" the value by setting it as "quoted text".
155155
156- ```
156+ ``` php
157157// Set cell A4 with a formula
158158$spreadsheet->getActiveSheet()->setCellValue(
159159 'A4',
@@ -175,7 +175,7 @@ point value), and a number format mask is used to show how that value
175175should be formatted; so if we want to store a date in a cell, we need to
176176calculate the correct Excel timestamp, and set a number format mask.
177177
178- ``` php
178+ ``` php
179179// Get the current date/time and convert to an Excel date/time
180180$dateTimeNow = time();
181181$excelDateValue = \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel( $dateTimeNow );
@@ -210,7 +210,7 @@ behaviour.
210210Firstly, you can set the datatype explicitly as a string so that it is
211211not converted to a number.
212212
213- ``` php
213+ ``` php
214214// Set cell A8 with a numeric value, but tell PhpSpreadsheet it should be treated as a string
215215$spreadsheet->getActiveSheet()->setCellValueExplicit(
216216 'A8',
@@ -222,7 +222,7 @@ $spreadsheet->getActiveSheet()->setCellValueExplicit(
222222Alternatively, you can use a number format mask to display the value
223223with leading zeroes.
224224
225- ``` php
225+ ``` php
226226// Set cell A9 with a numeric value
227227$spreadsheet->getActiveSheet()->setCellValue('A9', 1513789642);
228228// Set a number format mask to display the value as 11 digits with leading zeroes
@@ -236,7 +236,7 @@ $spreadsheet->getActiveSheet()->getStyle('A9')
236236With number format masking, you can even break up the digits into groups
237237to make the value more easily readable.
238238
239- ``` php
239+ ``` php
240240// Set cell A10 with a numeric value
241241$spreadsheet->getActiveSheet()->setCellValue('A10', 1513789642);
242242// Set a number format mask to display the value as 11 digits with leading zeroes
@@ -259,7 +259,7 @@ writers (Xlsx and Xls).
259259It is also possible to set a range of cell values in a single call by
260260passing an array of values to the ` fromArray() ` method.
261261
262- ``` php
262+ ``` php
263263$arrayData = [
264264 [NULL, 2010, 2011, 2012],
265265 ['Q1', 12, 15, 21],
@@ -282,7 +282,7 @@ If you pass a 2-d array, then this will be treated as a series of rows
282282and columns. A 1-d array will be treated as a single row, which is
283283particularly useful if you're fetching an array of data from a database.
284284
285- ``` php
285+ ``` php
286286$rowArray = ['Value1', 'Value2', 'Value3', 'Value4'];
287287$spreadsheet->getActiveSheet()
288288 ->fromArray(
@@ -299,7 +299,7 @@ If you have a simple 1-d array, and want to write it as a column, then
299299the following will convert it into an appropriately structured 2-d array
300300that can be fed to the ` fromArray() ` method:
301301
302- ``` php
302+ ``` php
303303$rowArray = ['Value1', 'Value2', 'Value3', 'Value4'];
304304$columnArray = array_chunk($rowArray, 1);
305305$spreadsheet->getActiveSheet()
@@ -319,7 +319,7 @@ To retrieve the value of a cell, the cell should first be retrieved from
319319the worksheet using the ` getCell() ` method. A cell's value can be read
320320using the ` getValue() ` method.
321321
322- ``` php
322+ ``` php
323323// Get the value from cell A1
324324$cellValue = $spreadsheet->getActiveSheet()->getCell('A1')->getValue();
325325```
@@ -331,7 +331,7 @@ value rather than the formula itself, then use the cell's
331331` getCalculatedValue() ` method. This is further explained in
332332[ the calculation engine] ( ./calculation-engine.md ) .
333333
334- ``` php
334+ ``` php
335335// Get the value from cell A4
336336$cellValue = $spreadsheet->getActiveSheet()->getCell('A4')->getCalculatedValue();
337337```
@@ -340,7 +340,7 @@ Alternatively, if you want to see the value with any cell formatting
340340applied (e.g. for a human-readable date or time value), then you can use
341341the cell's ` getFormattedValue() ` method.
342342
343- ``` php
343+ ``` php
344344// Get the value from cell A6
345345$cellValue = $spreadsheet->getActiveSheet()->getCell('A6')->getFormattedValue();
346346```
@@ -350,7 +350,7 @@ $cellValue = $spreadsheet->getActiveSheet()->getCell('A6')->getFormattedValue();
350350Setting a cell value by coordinate can be done using the worksheet's
351351` setCellValueByColumnAndRow() ` method.
352352
353- ``` php
353+ ``` php
354354// Set cell A5 with a string value
355355$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow(1, 5, 'PhpSpreadsheet');
356356```
@@ -363,15 +363,15 @@ To retrieve the value of a cell, the cell should first be retrieved from
363363the worksheet using the ` getCellByColumnAndRow() ` method. A cell’s value can
364364be read again using the following line of code:
365365
366- ``` php
366+ ``` php
367367// Get the value from cell B5
368368$cellValue = $spreadsheet->getActiveSheet()->getCellByColumnAndRow(2, 5)->getValue();
369369```
370370
371371If you need the calculated value of a cell, use the following code. This
372372is further explained in [ the calculation engine] ( ./calculation-engine.md ) .
373373
374- ``` php
374+ ``` php
375375// Get the value from cell A4
376376$cellValue = $spreadsheet->getActiveSheet()->getCellByColumnAndRow(1, 4)->getCalculatedValue();
377377```
@@ -382,7 +382,7 @@ It is also possible to retrieve a range of cell values to an array in a
382382single call using the ` toArray() ` , ` rangeToArray() ` or
383383` namedRangeToArray() ` methods.
384384
385- ``` php
385+ ``` php
386386$dataArray = $spreadsheet->getActiveSheet()
387387 ->rangeToArray(
388388 'C3:E5', // The worksheet range that we want to retrieve
@@ -409,7 +409,7 @@ cells within a row.
409409Below is an example where we read all the values in a worksheet and
410410display them in a table.
411411
412- ``` php
412+ ``` php
413413$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
414414$reader->setReadDataOnly(TRUE);
415415$spreadsheet = $reader->load("test.xlsx");
@@ -456,7 +456,7 @@ loops.
456456Below is an example where we read all the values in a worksheet and
457457display them in a table.
458458
459- ``` php
459+ ``` php
460460$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
461461$reader->setReadDataOnly(TRUE);
462462$spreadsheet = $reader->load("test.xlsx");
@@ -482,7 +482,7 @@ echo '</table>' . PHP_EOL;
482482Alternatively, you can take advantage of PHP's "Perl-style" character
483483incrementors to loop through the cells by coordinate:
484484
485- ``` php
485+ ``` php
486486$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
487487$reader->setReadDataOnly(TRUE);
488488$spreadsheet = $reader->load("test.xlsx");
@@ -528,7 +528,7 @@ dates entered as strings to the correct format, also setting the cell's
528528style information. The following example demonstrates how to set the
529529value binder in PhpSpreadsheet:
530530
531- ``` php
531+ ``` php
532532/** PhpSpreadsheet */
533533require_once 'src/Boostrap.php';
534534
0 commit comments