Improve doc formatting with backticks

This commit is contained in:
Adrien Crivelli 2017-03-13 14:57:37 +09:00
parent fec674e797
commit 8e8d0e4a30
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
11 changed files with 85 additions and 82 deletions

View File

@ -1,21 +1,18 @@
# Frequently asked questions
The up-to-date F.A.Q. page for PHPExcel can be found on
<http://www.codeplex.com/PHPExcel/Wiki/View.aspx?title=FAQ&referringTitle=Requirements>.
## There seems to be a problem with character encoding...
It is necessary to use UTF-8 encoding for all texts in PhpSpreadsheet.
If the script uses different encoding then you can convert those texts
with PHP's iconv() or mb\_convert\_encoding() functions.
with PHP's `iconv()` or `mb_convert_encoding()` functions.
## Fatal error: Allowed memory size of xxx bytes exhausted (tried to allocate yyy bytes) in zzz on line aaa
PhpSpreadsheet holds an "in memory" representation of a spreadsheet, so
it is susceptible to PHP's memory limitations. The memory made available
to PHP can be increased by editing the value of the memory\_limit
directive in your php.ini file, or by using ini\_set('memory\_limit',
'128M') within your code (ISP permitting).
to PHP can be increased by editing the value of the `memory_limit`
directive in your php.ini file, or by using
`ini_set('memory_limit', '128M')` within your code.
Some Readers and Writers are faster than others, and they also use
differing amounts of memory. You can find some indication of the
@ -56,8 +53,8 @@ reference](./references/features-cross-reference.md).
## Formulas don't seem to be calculated in Excel2003 using compatibility pack?
This is normal behaviour of the compatibility pack, Xlsx displays this
correctly. Use \PhpOffice\PhpSpreadsheet\Writer\Xls if you really need
This is normal behaviour of the compatibility pack, `Xlsx` displays this
correctly. Use `\PhpOffice\PhpSpreadsheet\Writer\Xls` if you really need
calculated values, or force recalculation in Excel2003.
## Setting column width is not 100% accurate
@ -66,7 +63,8 @@ Trying to set column width, I experience one problem. When I open the
file in Excel, the actual width is 0.71 less than it should be.
The short answer is that PhpSpreadsheet uses a measure where padding is
included. See section: "Setting a column's width" for more details.
included. See [how to seta column's width](./topics/recipes.md#setting-a-columns-width)
for more details.
## How do I use PhpSpreadsheet with my framework
@ -81,8 +79,8 @@ included. See section: "Setting a column's width" for more details.
within CakePHP
- Integrating [PhpSpreadsheet into Kohana
3](http://www.flynsarmy.com/2010/07/phpexcel-module-for-kohana-3/)
and \[Интеграция PHPExcel и Kohana
Framework\]\[http://szpargalki.blogspot.com/2011/02/phpexcel-kohana-framework.html\]
and [Интеграция PHPExcel и Kohana
Framework](http://szpargalki.blogspot.com/2011/02/phpexcel-kohana-framework.html)
- Using [PhpSpreadsheet with
TYPO3](http://typo3.org/documentation/document-library/extension-manuals/phpexcel_library/1.1.1/view/toc/0/)

View File

@ -26,7 +26,7 @@ $spreadsheet->getActiveSheet()->setCellValue(
```
Alternatively, you can retrieve the cell object, and then call the
cells setValue() method:
cells `setValue()` method:
``` php
$spreadsheet->getActiveSheet()
@ -275,8 +275,8 @@ Setting a cell value by coordinate can be done using the worksheet's
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow(1, 5, 'PhpSpreadsheet');
```
**Note** that column references start with '0' for column 'A', rather
than from '1'.
**Note** that column references start with `0` for column `A`, rather
than from `1`.
## Retrieving a cell value by column and row

View File

@ -142,7 +142,7 @@ $columnFilter->createRule()
```
This creates two filter rules: the column will be filtered by values
that match “France” OR “Germany”. For Simple Filters, you can create as
that match "France" OR "Germany". For Simple Filters, you can create as
many rules as you want
Simple filters are always a comparison match of EQUALS, and multiple
@ -238,7 +238,7 @@ $columnFilter->setFilterType(
And then define our rules.
The following shows a simple wildcard filter to show all column entries
beginning with the letter 'U'.
beginning with the letter `U`.
``` php
$columnFilter->createRule()
@ -487,7 +487,7 @@ saved.
### Applying the Filter
If you wish to execute your filter from within a script, you need to do
this manually. You can do this using the autofilters showHideRows()
this manually. You can do this using the autofilters `showHideRows()`
method.
``` php

View File

@ -11,7 +11,7 @@ which can be evaluated). For example, the formula `=SUM(A1:A10)`
evaluates to the sum of values in A1, A2, ..., A10.
To calculate a formula, you can call the cell containing the formulas
method getCalculatedValue(), for example:
method `getCalculatedValue()`, for example:
``` php
$spreadsheet->getActiveSheet()->getCell('E11')->getCalculatedValue();
@ -57,7 +57,7 @@ Not all functions are supported, for a comprehensive list, read the
#### Operator precedence
In Excel '+' wins over '&', just like '\*' wins over '+' in ordinary
In Excel `+` wins over `&`, just like `*` wins over `+` in ordinary
algebra. The former rule is not what one finds using the calculation
engine shipped with PhpSpreadsheet.
@ -94,14 +94,14 @@ return either an Excel timestamp or a PHP timestamp or date object.
It is possible for scripts to change the data type used for returning
date values by calling the
\PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType()
`\PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType()`
method:
``` php
\PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType($returnDateType);
```
where the following constants can be used for \$returnDateType
where the following constants can be used for `$returnDateType`:
- `\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_PHP_NUMERIC`
- `\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_PHP_OBJECT`
@ -155,7 +155,7 @@ Excel date values by calling the
\PhpOffice\PhpSpreadsheet\Shared\Date::setExcelCalendar($baseDate);
```
where the following constants can be used for \$baseDate
where the following constants can be used for `$baseDate`:
- \PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR\_WINDOWS\_1900
- \PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR\_MAC\_1904
@ -202,9 +202,9 @@ However, if you pass through a value such as '31/12/2008' that would be
considered an error by a US-based server, but which is not ambiguous,
then PhpSpreadsheet will attempt to correct this to 31st December 2008.
If the content of the string doesnt match any of the formats recognised
by the php date/time object implementation of strtotime() (which can
handle a wider range of formats than the normal strtotime() function),
then the function will return a '\#VALUE' error. However, Excel
by the php date/time object implementation of `strtotime()` (which can
handle a wider range of formats than the normal `strtotime()` function),
then the function will return a `#VALUE` error. However, Excel
recommends that you should always use date/timestamps for your date
functions, and the recommendation for PhpSpreadsheet is the same: avoid
strings because the result is not predictable.
@ -238,12 +238,12 @@ rather than converted to Excel date timestamp values.
### Helper Methods
In addition to the setExcelCalendar() and getExcelCalendar() methods, a
In addition to the `setExcelCalendar()` and `getExcelCalendar()` methods, a
number of other methods are available in the
\PhpOffice\PhpSpreadsheet\Shared\Date class that can help when working
with dates:
#### \PhpOffice\PhpSpreadsheet\Shared\Date::ExcelToPHP(\$excelDate)
#### \PhpOffice\PhpSpreadsheet\Shared\Date::ExcelToPHP($excelDate)
Converts a date/time from an Excel date timestamp to return a PHP
serialized date/timestamp.
@ -251,17 +251,17 @@ serialized date/timestamp.
Note that this method does not trap for Excel dates that fall outside of
the valid range for a PHP date timestamp.
#### \PhpOffice\PhpSpreadsheet\Shared\Date::ExcelToPHPObject(\$excelDate)
#### \PhpOffice\PhpSpreadsheet\Shared\Date::ExcelToPHPObject($excelDate)
Converts a date from an Excel date/timestamp to return a PHP DateTime
object.
#### \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel(\$PHPDate)
#### \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($PHPDate)
Converts a PHP serialized date/timestamp or a PHP DateTime object to
return an Excel date timestamp.
#### \PhpOffice\PhpSpreadsheet\Shared\Date::FormattedPHPToExcel(\$year, \$month, \$day, \$hours=0, \$minutes=0, \$seconds=0)
#### \PhpOffice\PhpSpreadsheet\Shared\Date::FormattedPHPToExcel($year, $month, $day, $hours=0, $minutes=0, $seconds=0)
Takes year, month and day values (and optional hour, minute and second
values) and returns an Excel date timestamp value.
@ -1114,7 +1114,7 @@ ym | Months Excluding Years | Complete calendar months between the da
yd | Days Excluding Years | Complete calendar days between the dates as if they were of the same year.
md | Days Excluding Years And Months | Complete calendar days between the dates as if they were of the same month and same year.
The unit value is not case sensitive, and defaults to "d".
The unit value is not case sensitive, and defaults to `d`.
##### Return Value
@ -1290,8 +1290,8 @@ $retVal = call_user_func_array(
##### Notes
DATEVALUE uses the php date/time object implementation of strtotime()
(which can handle a wider range of formats than the normal strtotime()
DATEVALUE uses the php date/time object implementation of `strtotime()`
(which can handle a wider range of formats than the normal `strtotime()`
function), and it is also called for any date parameter passed to other
date functions (such as DATEDIF) when the parameter value is a string.
@ -1449,7 +1449,7 @@ $retVal = call_user_func_array(
when a PHP Boolean is used for the third (optional) parameter (as shown
in the example above), and the writer will generate and error. It will
work if a numeric 0 or 1 is used for the method parameter; or if the
Excel TRUE() and FALSE() functions are used instead.
Excel `TRUE()` and `FALSE()` functions are used instead.
#### EDATE
@ -1824,7 +1824,7 @@ The NOW function returns the current date and time.
##### Parameters
There are now parameters for the NOW() function.
There are no parameters for the `NOW()` function.
##### Return Value

View File

@ -44,13 +44,13 @@ A new workbook will always be created with a single worksheet.
The PhpSpreadsheet object contains cyclic references (e.g. the workbook
is linked to the worksheets, and the worksheets are linked to their
parent workbook) which cause problems when PHP tries to clear the
objects from memory when they are unset(), or at the end of a function
objects from memory when they are `unset()`, or at the end of a function
when they are in local scope. The result of this is "memory leaks",
which can easily use a large amount of PHP's limited memory.
This can only be resolved manually: if you need to unset a workbook,
then you also need to "break" these cyclic references before doing so.
PhpSpreadsheet provides the disconnectWorksheets() method for this
PhpSpreadsheet provides the `disconnectWorksheets()` method for this
purpose.
``` php

View File

@ -78,10 +78,10 @@ library.
Comma Separated Value (CSV) file format is a common structuring strategy
for text format files. In CSV flies, each line in the file represents a
row of data and (within each line of the file) the different data fields
(or columns) are separated from one another using a comma (","). If a
(or columns) are separated from one another using a comma (`,`). If a
data field contains a comma, then it should be enclosed (typically in
quotation marks ("). Sometimes tabs "\t", or the pipe symbol ("|"), or a
semi-colon (";") are used as separators instead of a comma, although
quotation marks (`"`). Sometimes tabs `\t`, or the pipe symbol (`|`), or a
semi-colon (`;`) are used as separators instead of a comma, although
other symbols can be used. Because CSV is a text-only format, it doesn't
support any data formatting options.

View File

@ -435,7 +435,7 @@ $spreadsheet = $reader->load("sample.csv");
#### Setting CSV options
Often, CSV files are not really “comma separated”, or use semicolon (;)
Often, CSV files are not really "comma separated", or use semicolon (;)
as a separator. You can instruct
\PhpOffice\PhpSpreadsheet\Reader\Csv some options before reading a CSV
file.
@ -470,7 +470,7 @@ $reader->setSheetIndex(0);
When working with CSV files, it might occur that you want to import CSV
data into an existing `Spreadsheet` object. The following code loads a
CSV file into an existing \$spreadsheet containing some sheets, and
CSV file into an existing `$spreadsheet` containing some sheets, and
imports onto the 6th sheet:
``` php
@ -496,7 +496,7 @@ $writer->save("05featuredemo.csv");
#### Setting CSV options
Often, CSV files are not really “comma separated”, or use semicolon (;)
Often, CSV files are not really "comma separated", or use semicolon (`;`)
as a separator. You can instruct
\PhpOffice\PhpSpreadsheet\Writer\Csv some options before writing a CSV
file:
@ -672,10 +672,10 @@ you to use these parts in your website.
Supported methods:
- generateHTMLHeader()
- generateStyles()
- generateSheetData()
- generateHTMLFooter()
- `generateHTMLHeader()`
- `generateStyles()`
- `generateSheetData()`
- `generateHTMLFooter()`
Here's an example which retrieves all parts independently and merges
them into a resulting HTML page:

View File

@ -17,8 +17,8 @@ To prevent this, by default every XML-based Reader looks for XML entities declar
## Loading a Spreadsheet File
The simplest way to load a workbook file is to let PhpSpreadsheet's IO
Factory identify the file type and load it, calling the static load()
method of the \PhpOffice\PhpSpreadsheet\IOFactory class.
Factory identify the file type and load it, calling the static `load()`
method of the `\PhpOffice\PhpSpreadsheet\IOFactory` class.
``` php
$inputFileName = './sampleData/example1.xls';
@ -30,7 +30,7 @@ $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
> See Examples/Reader/exampleReader01.php for a working example of this
> code.
The load() method will attempt to identify the file type, and
The `load()` method will attempt to identify the file type, and
instantiate a loader for that file type; using it to load the file and
store the data and any formatting in a `Spreadsheet` object.
@ -51,7 +51,7 @@ actually reading the file into a `Spreadsheet` object.
If you know the file type of the spreadsheet file that you need to load,
you can instantiate a new reader object for that file type, then use the
reader's load() method to read the file to a `Spreadsheet` object. It is
reader's `load()` method to read the file to a `Spreadsheet` object. It is
possible to instantiate the reader objects for each of the different
supported filetype by name. However, you may get unpredictable results
if the file isn't of the right type (e.g. it is a CSV with an extension
@ -75,7 +75,7 @@ $spreadsheet = $reader->load($inputFileName);
> See Examples/Reader/exampleReader02.php for a working example of this
> code.
Alternatively, you can use the IO Factory's createReader() method to
Alternatively, you can use the IO Factory's `createReader()` method to
instantiate the reader object for you, simply telling it the file type
of the reader that you want instantiating.
@ -120,7 +120,7 @@ $spreadsheet = $reader->load($inputFileName);
Once you have created a reader object for the workbook that you want to
load, you have the opportunity to set additional options before
executing the load() method.
executing the `load()` method.
### Reading Only Data from a Spreadsheet File
@ -172,7 +172,7 @@ setLoadSheetsOnly() method to identify those sheets you are interested
in reading.
To read a single sheet, you can pass that sheet name as a parameter to
the setLoadSheetsOnly() method.
the `setLoadSheetsOnly()` method.
``` php
$inputFileType = 'Xls';
@ -191,7 +191,7 @@ $spreadsheet = $reader->load($inputFileName);
> code.
If you want to read more than just a single sheet, you can pass a list
of sheet names as an array parameter to the setLoadSheetsOnly() method.
of sheet names as an array parameter to the `setLoadSheetsOnly()` method.
``` php
$inputFileType = 'Xls';
@ -209,7 +209,7 @@ $spreadsheet = $reader->load($inputFileName);
> See Examples/Reader/exampleReader08.php for a working example of this
> code.
To reset this option to the default, you can call the setLoadAllSheets()
To reset this option to the default, you can call the `setLoadAllSheets()`
method.
``` php
@ -241,8 +241,8 @@ If you are only interested in reading part of a worksheet, then you can
write a filter class that identifies whether or not individual cells
should be read by the loader. A read filter must implement the
\PhpOffice\PhpSpreadsheet\Reader\IReadFilter interface, and contain a
readCell() method that accepts arguments of \$column, \$row and
\$worksheetName, and return a boolean true or false that indicates
readCell() method that accepts arguments of `$column`, `$row` and
`$worksheetName`, and return a boolean true or false that indicates
whether a workbook cell identified by those arguments should be read or
not.
@ -319,7 +319,7 @@ $filterSubset = new MyReadFilter(9,15,range('G','K'));
> code.
This can be particularly useful for conserving memory, by allowing you
to read and process a large workbook in “chunks”: an example of this
to read and process a large workbook in "chunks": an example of this
usage might be when transferring data from an Excel worksheet to a
database.
@ -386,13 +386,13 @@ CSV | YES | HTML | NO | | |
### Combining Multiple Files into a Single Spreadsheet Object
While you can limit the number of worksheets that are read from a
workbook file using the setLoadSheetsOnly() method, certain readers also
workbook file using the `setLoadSheetsOnly()` method, certain readers also
allow you to combine several individual "sheets" from different files
into a single `Spreadsheet` object, where each individual file is a
single worksheet within that workbook. For each file that you read, you
need to indicate which worksheet index it should be loaded into using
the setSheetIndex() method of the \$reader, then use the
loadIntoExisting() method rather than the load() method to actually read
the `setSheetIndex()` method of the `$reader`, then use the
`loadIntoExisting()` method rather than the `load()` method to actually read
the file into that worksheet.
``` php
@ -450,9 +450,9 @@ Xlsx Microsoft Office Open XML SpreadsheetML .xlsx file is limited to
by available disk space. This means that we wouldnt ordinarily be able
to read all the rows from a very large CSV file that exceeded those
limits, and save it as an Xls or Xlsx file. However, by using Read
Filters to read the CSV file in “chunks” (using the chunkReadFilter
Filters to read the CSV file in "chunks" (using the chunkReadFilter
Class that we defined in [the above section](#reading-only-specific-columns-and-rows-from-a-file-read-filters),
and the setSheetIndex() method of the \$reader, we can split the CSV
and the `setSheetIndex()` method of the `$reader`, we can split the CSV
file across several individual worksheets.
``` php
@ -503,7 +503,7 @@ for ($startRow = 2; $startRow <= 1000000; $startRow += $chunkSize) {
This code will read 65,530 rows at a time from the CSV file that were
loading, and store each "chunk" in a new worksheet.
The setContiguous() method for the Reader is important here. It is
The `setContiguous()` method for the Reader is important here. It is
applicable only when working with a Read Filter, and identifies whether
or not the cells should be stored by their position within the CSV file,
or their position relative to the filter.
@ -525,7 +525,7 @@ CSV | YES | HTML | NO
The CSV loader defaults to loading a file where comma is used as the
separator, but you can modify this to load tab- or pipe-separated value
files using the setDelimiter() method.
files using the `setDelimiter()` method.
``` php
$inputFileType = 'Csv';
@ -546,8 +546,11 @@ $spreadsheet = $reader->load($inputFileName);
In addition to the delimiter, you can also use the following methods to
set other attributes for the data load:
setEnclosure() | default is " setLineEnding() | default is PHP\_EOL
setInputEncoding() | default is UTF-8
Method | Default
-------------------|----------
setEnclosure() | `"`
setLineEnding() | `PHP_EOL`
setInputEncoding() | `UTF-8`
Setting CSV delimiter applies to:

View File

@ -141,7 +141,7 @@ $spreadsheet->getActiveSheet()->setCellValue('B8','=IF(C4>500,"profit","loss")')
```
If you want to write a string beginning with an `=` character to a
cell, then you should use the setCellValueExplicit() method.
cell, then you should use the `setCellValueExplicit()` method.
``` php
$spreadsheet->getActiveSheet()
@ -239,7 +239,7 @@ $spreadsheet->getActiveSheet()->getStyle('A1')->getAlignment()->setWrapText(true
**Tip**
Read more about formatting cells using getStyle() elsewhere.
Read more about formatting cells using `getStyle()` elsewhere.
**Tip**
@ -332,7 +332,7 @@ $spreadsheet->getActiveSheet()->getPageSetup()->setFitToHeight(0);
As you can see, it is not necessary to call setFitToPage(TRUE) since
setFitToWidth(...) and setFitToHeight(...) triggers this.
If you use setFitToWidth() you should in general also specify
If you use `setFitToWidth()` you should in general also specify
setFitToHeight() explicitly like in the example. Be careful relying on
the initial values.
@ -474,7 +474,9 @@ $spreadsheet->getActiveSheet()->setBreak( 'D10' , \PhpOffice\PhpSpreadsheet\Work
To show/hide gridlines when printing, use the following code:
\$spreadsheet-&gt;getActiveSheet()-&gt;setShowGridlines(true);
```php
$spreadsheet->getActiveSheet()->setShowGridlines(true);
```
### Setting rows/columns to repeat at top/left
@ -738,7 +740,7 @@ vertical/horizontal, left/right/top/bottom/diagonal.
This border hierarchy can be utilized to achieve various effects in an
easy manner.
### Valid array keys for style applyFromArray()
### Valid array keys for style `applyFromArray()`
The following table lists the valid array keys for
\PhpOffice\PhpSpreadsheet\Style applyFromArray() classes. If the "Maps
@ -1001,15 +1003,15 @@ $validation->setFormula1('"Item A,Item B,Item C"');
```
When using a data validation list like above, make sure you put the list
between " and " and that you split the items with a comma (,).
between `"` and `"` and that you split the items with a comma (`,`).
It is important to remember that any string participating in an Excel
formula is allowed to be maximum 255 characters (not bytes). This sets a
limit on how many items you can have in the string "Item A,Item B,Item
C". Therefore it is normally a better idea to type the item values
directly in some cell range, say A1:A3, and instead use, say,
$validation->setFormula1('Sheet!$A$1:$A\$3');. Another benefit is that
the item values themselves can contain the comma "," character itself.
`$validation->setFormula1('Sheet!$A$1:$A$3')`. Another benefit is that
the item values themselves can contain the comma `,` character itself.
If you need data validation on multiple cells, one can clone the
ruleset:
@ -1493,7 +1495,7 @@ visible via the user interface.
## Right-to-left worksheet
Worksheets can be set individually whether column "A" should start at
Worksheets can be set individually whether column `A` should start at
left or right side. Default is left. Here is how to set columns from
right-to-left.

View File

@ -193,7 +193,7 @@ if (!$validLocale) {
- If Brazilian Portuguese language files aren't available, then Portuguese
will be enabled instead
- If Portuguese language files aren't available,
then the setLocale() method will return an error, and American English
then the `setLocale()` method will return an error, and American English
(en\_us) settings will be used throughout.
More details of the features available once a locale has been set,

View File

@ -92,7 +92,7 @@ new worksheet will be added after the last existing worksheet.
## Copying Worksheets
Sheets within the same workbook can be copied by creating a clone of the
worksheet you wish to copy, and then using the addSheet() method to
worksheet you wish to copy, and then using the `addSheet()` method to
insert the clone into the workbook.
``` php
@ -103,7 +103,7 @@ $spreadsheet->addSheet($clonedWorksheet);
You can also copy worksheets from one workbook to another, though this
is more complex as PhpSpreadsheet also has to replicate the styling
between the two workbooks. The addExternalSheet() method is provided for
between the two workbooks. The `addExternalSheet()` method is provided for
this purpose.
$clonedWorksheet = clone $spreadsheet1->getSheetByName('Worksheet 1');
@ -117,7 +117,7 @@ duplicate name.
## Removing a Worksheet
You can delete a worksheet from a workbook, identified by its index
position, using the removeSheetByIndex() method
position, using the `removeSheetByIndex()` method
``` php
$sheetIndex = $spreadsheet->getIndex(