Skrol29 / opentbs

With OpenTBS you can merge OpenOffice - LibreOffice and Ms Office documents with PHP using the TinyButStrong template engine. Simple use OpenOffice - LibreOffice or Ms Office to edit your templates : DOCX, XLSX, PPTX, ODT, OSD, ODP and other formats. That is the Natural Template philosophy.
http://www.tinybutstrong.com/opentbs.php
70 stars 17 forks source link

Something like "block=tbs:sheet" possible? #14

Open nioate opened 3 years ago

nioate commented 3 years ago

I am not sure if this is the right place to ask, but I could not find another possibility:

I would like to repeat sheets in an ODS file instead of repeating rows in a sheet or cells in a row. However it seems block=tbs:sheet does not exist. And even if something like that is possible, LibreOffice does not allow sheet names including [ ] brackets.

Any way to solve this?

roxblnfk commented 3 years ago

Have you tried using tbs:page?

nioate commented 3 years ago

No, I didn't know that. I suppose I would need then "[tab.name; block=tbs:page]" as table name. However, this is not possible, because LibreOffice does not accept brackets in the table name.

Skrol29 commented 3 years ago

The good place for help and support is https://stackoverflow.com/ using the tag TinyButStrong and OpenTbs.

It is possible to repeat sheets in an ODS file because they are all defined in the same sub-file which is the main file.

Example :

In the ODS template: Choose a sheet in your template, name the sheet « MySheetName » (sheet names cannot have brackets like [ and ]) and put the following fields in a cell : [b;block=table:table], or [b;block=tbs:table].

At the PHP side:

// Include classes
include_once('tbs_class.php'); // Load the TinyButStrong template engine
include_once('tbs_plugin_opentbs.php'); // Load the OpenTBS plugin

// Initialize the TBS instance
$TBS = new clsTinyButStrong; // new instance of TBS
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN); // load the OpenTBS plugin

//load template
$template = 'test.ods';
$TBS->LoadTemplate($template, OPENTBS_ALREADY_UTF8);

// sheets to repeat
$data = array(
    array('title' => "my sheet 1"),
    array('title' => "my sheet 2"),
    array('title' => "my sheet 3"),
);
// rename the tbs fields for the sheet name
$TBS->Source = str_replace('{MySheetName}', '[b.title]', $TBS->Source);
// merge sheets
$TBS->MergeBlock('b', $data);

// Finalize the merging
$output_file_name = 'resultat.ods';
$TBS->Show(OPENTBS_FILE, $output_file_name); // Also merges all [onshow] automatic fields.