Word export

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
ManosP
User
Posts: 10

Word export

Post by ManosP »

Hi. I have the following question.
I am making a project but i can't understand how export in word is working.
I want my row to exported in a custom template word file (.docx).
How can i do that?


digitalphotoworld
User
Posts: 416
Location: Nürnberg/Germany

Post by digitalphotoworld »

Google for "tinybutstrong" and try it. It is a free template engine that is able to generate PDF, Word, Excel and LibreOffice/OpenOffice Documents. With TBS it is possible to create a Officedocument that contains all the formating for your page with styles etc. You only have to place your vars in Brackets like [var.date] and TBS will fill the form.
TBS is much easier and much more powerfull than the build-in custom template that ships with PHPMaker.


mpol_ch
User
Posts: 877
Location: Switzerland

Post by mpol_ch »

Hi digitalphotoworld

Is tinybutstrong supporting PDF?
If yes could you please give a simple example?
I am using it for exporting into Word.
But I do not know how and if it support PDF.

I will appreciate your contribution much, if you can confirm and submit a simple example for tinybutstrong.


ManosP
User
Posts: 10

Post by ManosP »

Hi digitalphotoworld

Please help!! :)
I don't know why i can't see my template.
I put the following code:

// Row Export event
// $this->ExportDoc = export document object
function Row_Export($rs) {

include_once('tbs/tbs_class.php');
include_once('tbs/tbs_plugin_opentbs.php');

$TBS = new clsTinyButStrong;
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);

$TBS->LoadTemplate('tbs/entolh_metakinhshs.docx', OPENTBS_ALREADY_UTF8); // Load the archive and tells that the PHP script and merged data are already UTF8.

$TBS->Show(OPENTBS_FILE, $file_name);
}

I am getting an empty document.

I don't know why is not working?

Could you help.
Also could you tell me the syntax in the word file?
How phpmaker know where to put the cell value?


ManosP
User
Posts: 10

Post by ManosP »

Ok. I did it!!!!
Thanks anyway!!!!


dmichala
User
Posts: 8

Post by dmichala »

Hi ManosP.,

I have a similar issue.

Can you please share how you did it ?

Thanks


ManosP
User
Posts: 10

Post by ManosP »

// Page Exporting event
// $this->ExportDoc = export document object
function Page_Exporting() {
//$this->ExportDoc->Text = "my header"; // Export header
//return FALSE; // Return FALSE to skip default export and use Row_Export event
return FALSE; // Return TRUE to use default export and skip Row_Export event
}


// Row Export event
// $this->ExportDoc = export document object
function Row_Export($rs) {
//$this->ExportDoc->Text .= "my content"; // Build HTML with field value: $rs["MyField"] or $this->MyField->ViewValue

include_once('tbs/tbs_class.php');
include_once('tbs/tbs_plugin_opentbs.php');

$TBS = new clsTinyButStrong;
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);

$template = 'tbs/entolh_metakinhshs.docx';
$TBS->LoadTemplate($template, OPENTBS_ALREADY_UTF8); // Also merge some [onload] automatic fields (depends of the type of document).

$eponymo = ew_ExecuteScalar("SELECT eponymo FROM ypallhloi WHERE id_ypallhlos = ".$rs["id_ypallhlos"]."");
$onoma = ew_ExecuteScalar("SELECT onoma FROM ypallhloi WHERE id_ypallhlos = ".$rs["id_ypallhlos"]."");
$kathgoria = ew_ExecuteScalar("SELECT kathgoria FROM ypallhloi WHERE id_ypallhlos = ".$rs["id_ypallhlos"]."");
$vathmos = ew_ExecuteScalar("SELECT vathmos FROM ypallhloi WHERE id_ypallhlos = ".$rs["id_ypallhlos"]."");
//$synolo_hmeron = ew_ExecuteScalar("SELECT ypoloipo_hmeron_ee FROM ypallhloi WHERE id_ypallhlos = ".$rs["id_ypallhlos"]."");
$prag_hmeres = 60 - $rs['trexon_ypoloipo'];

$TBS->MergeField('entolh',array('eponymo'=>$eponymo, 'onoma'=>$onoma, 'hmeromhnia_prot_taxis'=>$rs['hmeromhnia_prot_taxis'], 'arithmos_prot_taxis'=>$rs['arithmos_prot_taxis'], 'kathgoria'=>$kathgoria, 'vathmos'=>$vathmos, 'topos_metakinhshs'=>$rs['topos_metakinhshs'], 'aitia_metakinhshs'=>$rs['skopos_metakinhshs'], 'tropos_metakinhshs'=>$rs['tropos_metakinhshs'], 'hm_anaxorhshs'=>$rs['hmeromhnia_anaxorisis'], 'hm_epistrofhs'=>$rs['hmeromhnia_epistrofis'], 'hm_enarkshs_ergasion'=>$rs['hmeromhnia_enarxhs'], 'hm_lhxhs_ergasion'=>$rs['hmeromhnia_lhxhs'], 'hmeres_sum'=>$rs['hmeres_sum'], 'hmeres_dian'=>$rs['hmeres_dianyktereushs'], 'hmeres_prag'=>$prag_hmeres, 'hmeres_ypoloipo'=>$rs['trexon_ypoloipo']));

$output_file_name = 'entolh_metakinhshs_XXXXX.docx';
$TBS->Show(OPENTBS_FILE, $output_file_name);

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header('Content-Type: application/vnd.ms-word' . ((EW_CHARSET <> "") ? ";charset=" . EW_CHARSET : ""));
header('Content-Disposition: attachment; filename=' . $output_file_name);

if (@readfile("$output_file_name")) {
unlink("$output_file_name");
}
exit();
}


ManosP
User
Posts: 10

Post by ManosP »

Hello. I need your help.
I am using "tinybutstrong" for exporting my record when i am in "View Page". All working fine!
How can i export in different files when i am in "List Page"?

For example. I have 5 records. I select the 3 of 5, and when i am pressing the export button then i want phpmaker to generate 3 different export files. How can i do that. Bassicaly i want a loop (for) but i don't know the syntax.


digitalphotoworld
User
Posts: 416
Location: Nürnberg/Germany

Post by digitalphotoworld »

It is not possible to create more than one file for download at once. The only workaround I know is to build 3 Files that are stored on the server, than create a zip file that contains the files and send the zip file as single export.


Webmaster
User
Posts: 9427

Post by Webmaster »

Note that Row_Export() is fired for each row, no need to loop yourself, but your code calls exit() after exporting the first row. You should save all files on the server first, and do what digitalphotoworld suggested.


jtandrea
User
Posts: 38

Post by jtandrea »

Hi.
Adopting succesfully this technique for my site,
I'm now encountering an issue migrating from PHPMaker 12.0.4 to version 2019.0.6.

here the code:
function Row_Export($rs) {
include_once('tbs/tbs_class.php');
include_once('tbs/tbs_plugin_opentbs.php');
$TBS = new clsTinyButStrong;
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
...

As soon as user clicks on the Export button
the page displays:

Fatal error:
Class 'PHPMaker2019\pfn\clsTinyButStrong' not found in C:\Users\<username>\Documents\PHPMaker\WebSites\pfn\classes\t_data_list.php on line 2629
(which, btw refers to code: "$TBS = new clsTinyButStrong;")

Is it a problem of namespaces?

How can I resolve the issue?

Thanks and regards
jtandrea


arbei
User
Posts: 9373

Post by arbei »

  1. Include third party packages by Composer, see http://www.hkvforums.com/viewtopic.php?f=4&t=43382
  2. Remove include_once() because Composer helps you autoload third party packages,
  3. Add namespaces for: $TBS = new clsTinyButStrong;

Post Reply