5/25/2017

PHP : Export Data To Libreoffice Calc .ods

PHP : Export Data To Libreoffice Calc .ods
1. download และติดตั้ง tbs
http://www.tinybutstrong.com/download.php

2. download plugins และติดตั้ง
http://www.tinybutstrong.com/plugins.php

ไฟล์สำเร็จนำไปแตกไฟล์เรียกใช้ได้เลย


หลักการคือ
ทำ Template และใส่ชื่อ Block ไว้
แล้ว Select ข้อมูลเป็น Array ไปใส่

ตัวอย่าง Code ทำรายงาน
http://www.tinybutstrong.com/opentbs.php?demo
http://www.tinybutstrong.com/examples.php

Example :
  1. include_once('../tbs/tbs_class.php'); // Load the TinyButStrong template engine
  2. include_once('../tbs/plugins/tbs_plugin_opentbs.php'); // Load the OpenTBS plugin
  3.  
  4. // Initialize the TBS instance
  5. $TBS = new clsTinyButStrong; // new instance of TBS
  6. $TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN); // load the OpenTBS plugin
  7.  
  8. $DATA1 = array();
  9.  
  10. $template = 'Report_Template.ods';
  11. $TBS->LoadTemplate($template, OPENTBS_ALREADY_UTF8); // Also merge some [onload] automatic fields (depends of the type of document).
  12. // Merge data in the Workbook (all sheets)
  13. $TBS->MergeBlock('blk1', $DATA1);
  14.  
  15. // -----------------
  16. // Output the result
  17. // -----------------
  18. // Define the name of the output file
  19. $output_file_name = str_replace('.', '_'.date('Y-m-d').'.', $template);
  20.  
  21. // Output the result as a downloadable file (only streaming, no data saved in the server)
  22. $TBS->Show(OPENTBS_DOWNLOAD, $output_file_name); // Also merges all [onshow] automatic fields.
  23. exit();
  24.  
  25.  

No comments:

Post a Comment