Index
With the Excel plug-in, you can use the TinyButStrong Template Engine to drive the merge of Excel Worksheets based on a template that you can build visually under Microsoft Excel.
This manual assumes that you know merging with TinyButStrong (TBS).
Since Microsoft Excel version 2002 and higher, you can open and save Excel documents in the "XML Spreadsheet" format. Those files are Excel documents saved with an XML source instead of a binary source. The default extension is ".xml", but you can rename the file with an ".xls" extension and they will open like any Excel document. Such Excel documents saved in XML enable nearly all worksheets features (makeup, formats, formulas) but Graphics and Visual Basic Macros are not supported (all differences are documented here).
OpenOffice.org Calc can open those files since version 2.0, but only if the extension is ".xml".
This Excel-XML format is a convenient way to do dynamic Excel files by the template technique.
Example:
You have to install the plugin in manual mode. The plug-in should be installed before to call the LoadTemplate() method.
Example:
The Excel plug-in enables you to retrieve the final result of the merge in several ways. It is done with the method $TBS->Show(). By default this method will produce an Http download with a default file name. Here are the available options:
Output the result as an Http download:
$TBS->Show(TBS_EXCEL_DOWNLOAD, $FileName);
Output the result as a file on the local server:
$TBS->Show(TBS_EXCEL_FILE, $FilePath);
Retrieve the result as a PHP string file:
$TBS->Show(TBS_EXCEL_STRING);
$xml_result = $TBS->Source;
Deprecated since version 1.1.0:
- Change the name of the file for download: $TBS->PlugIn(TBS_EXCEL,TBS_EXCEL_FILENAME,'file.xls');
- Enables the file to be displayed within the browser (old Internet Explorer only): $TBS->PlugIn(TBS_EXCEL,TBS_EXCEL_INLINE);
Parameter | Value forced to | |
ope=xlNum | Numeric | |
ope=xlDT | DateTime |
Current date: | [var..now;ope=xlDT] |
Total amount: | [var.amount;ope=xlNum] |
Within an Excel-XML document, <Table> <Row> and <Cell> elements are used to dispose data into the Worksheets. It is quite similar to the HTML <table><tr> and <td> elements. But a <Table> is really touchy to multiply (see section Debuggin below).
Thus, the more common TBS blocks you'll define will be block=Row when you want to expand rows, or block=Cell when you want to expand columns.
Examples:
Title | Price |
[b1.title;block=Row] | [b1.price;ope=xlNum] |
After a block is merged, Excel formulas (like SUM) over this block may not be what you wanted because cells or rows have been expanded by the block.
• If the formula is placed on the right or bottom of the merged block:A | B | |
1 | [b1.title;block=Row] | [b1.price;ope=xlNum] |
2 | =SUM(B$1:B1) |
A | B | |
1 | =SUM(B2:B2)+N("[b1.#;ope=xlPushRef]") | |
2 | [b1.title;block=Row] | [b1.price;ope=xlNum] |
TBS error messages will cause the result to not be a downloadable file because error messages are prompted before header informations are sent.
Nevertheless, your result may be an invalid
Excel-XML document. XML syntax is less tolerating than HTML. If your document is invalid then Excel will prompt an unhelpful error message when opened. Then you will probably need to look at the source of the merged document to understand what's wrong.
Here is some interesting information about the Excel-XML syntax:
- One document contains one or several <Worksheets> elements.
- One <Worksheet> contains one or several <Table> elements.
- One <Table> contains one or more <Row> elements.
- One <Row> contains one or more <Cell> elements.
Microsoft Excel offers to save XML Spreadsheets as a file with an ".xml" extension (for example: result.xls). Nevertheless, other type of XML files may have the same extension. That's why if you double-click on an XML Spreadsheet file to open it directly, it may or may not open Excel depending to your configuration.
OpenOffice and LibreOffice can open XML Spreadsheet files only if the file has the XML extension.
In order to be sure that the user will be able to open your XML Spreadsheet, you may prefer to save the file with the XLS extension (for example: result.xls). With this extension, the file will be opened by Excel whatever the version of Windows of the version of Excel. Nevertheless, if you open such a file with Excel 2007 and higher, you will have a message box: "the file you are trying to open 'result.xls' is in a different format than specified by the file [...]". If you choose Yes, then the workbook will be opened normally.
So we can say that there is no good solution.
Version 1.1.0: | - Works with TBS version 3.6.2 or higher and with PHP 5. - Possibility to save the result as a file. - Possibility to retrieve the result in a PHP string. - Avoid the output if a TBS error occurs. - Fixed bug: Warning: Parameter 4 to clsTbsExcel::BeforeMergeBlock() expected to be a reference, value given [...] - Fixed bug: Strict Standards: call_user_func() expects parameter 1 to be a valid callback, non-static method clsTbsExcel::f_XmlConv() should not be called statically in [...] |
Version 1.0.3: | Minor fixes in the HTML header which force the file to download. |
Version 1.0.2: | Bug fixed about special sections (like headergrp, when, nodata, ... ) that could be bad placed after a MergeBlock(). |