Categories > OpenTBS with DOCX >

Problem with Merge in excel template

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Lily
Date: 2013-04-04
Time: 16:56

Problem with Merge in excel template

Hi,

I have been using TBS for docx templates, and now I need to use for Excel template. I am getting error when opening the excel file, File type or format not correct.

Here is the php code:
<?php
 
// Display this code source is asked.
if (isset($_GET['source'])) exit('<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>OpenTBS plug-in for TinyButStrong - demo source</title></head><body>'.highlight_file(__FILE__,true).'</body></html>');

// load the TinyButStrong libraries
if (version_compare(PHP_VERSION,'5')<0) {
    include_once('tbs_class_php4.php'); // TinyButStrong template engine for PHP 4
} else {
    include_once('tbs_class_php5.php'); // TinyButStrong template engine
}

// load the OpenTBS plugin
if (file_exists('tbs_plugin_opentbs.php')) {
    include_once('tbs_plugin_opentbs.php');
} else {
    include_once('../tbs_plugin_opentbs.php');
}

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

// Read user choices

$suffix = (isset($_POST['suffix']) && (trim($_POST['suffix'])!=='') && ($_SERVER['SERVER_NAME']=='localhost')) ? trim($_POST['suffix']) : '';
$debug = (isset($_POST['debug'])) ? intval($_POST['debug']) : 0;

    include '../../config/config.php';
    include '../../config/opendb.php';
   $sql = mysql_query('SELECT * FROM claims');
    while ($row=mysql_fetch_array($sql)){
    $data[]= array('claimNumber' => $row['claim_number']);
    }

// Retrieve the template to open
$template = 'Claims template.xlsx';
$template = basename($template);
$x = pathinfo($template);
$template_ext = $x['extension'];

if (!file_exists($template)) exit("File does not exist.");
// Load the template
$TBS->LoadTemplate($template);

if ($debug==2) { // debug mode 2
    $TBS->Plugin(OPENTBS_DEBUG_XML_CURRENT);
    exit;
} elseif ($debug==1) { // debug mode 1
    $TBS->Plugin(OPENTBS_DEBUG_INFO);
    exit;
}

// specific merges depending to the document
if ($template_ext=='xlsx') {
  $TBS->MergeBlock('a', $data);
    // change the current sheet
    $TBS->PlugIn(OPENTBS_SELECT_SHEET, 1);

   
}
// Define the name of the output file
$file_name = str_replace('.','_'.date('Y-m-d').'.',$template);

// Output as a download file (some automatic fields are merged here)
if ($debug==3) { // debug mode 3
    $TBS->Plugin(OPENTBS_DEBUG_XML_SHOW);
} elseif ($suffix=='') {
    // download
    $TBS->Show(OPENTBS_DOWNLOAD, $file_name);
} else {
    // save as file
    $file_name = str_replace('.','_'.$suffix.'.',$file_name);
    $TBS->Show(OPENTBS_FILE+TBS_EXIT, $file_name);
}


In the excel sheet I have added only one field to be populate for now in the field B5:

[a.claimNumber;block=row]

Can you please help me understand what I am doing wrong?

Thanks in advance
Lily
By: Skrol29
Date: 2013-04-05
Time: 00:02

Re: Problem with Merge in excel template

Hi Lily,

The file may be corrupted because yu haven't used parameter "ope=xlsxNum" in order to specify the data type of the cell.
See the XLSX example given in the package, it shows how to use this parameter.

If that does no fix your problem, I need to have the corrupted file in order to understand the problem.
By: Lily
Date: 2013-04-05
Time: 09:33

Re: Problem with Merge in excel template

Thank you Skrol29 for your reply. I have tried with the parametar ope=xlsxNum, it didn't work. However the walue I want to generate in the excel file is Varchar, that's why I didb't use this parametar. I wonder if maybe I am doing something wrong with the db query.
    include '../../config/config.php';
    include '../../config/opendb.php';

   $sql = mysql_query('SELECT * FROM claims');
    while ($row=mysql_fetch_array($sql)){
    $data[]= array('claimNumber' => $row['claim_number']);
    }

By: Skrol29
Date: 2013-04-06
Time: 00:29

Re: Problem with Merge in excel template

You're right, in yur case ope=xlsxNum is not relevant.

Did you tried the debug mode just after $TBS->MergeBlock('a', $data) ?
If there is a problem with some columns then some error message should appear in the debug mode.

$TBS->Plugin(OPENTBS_DEBUG_XML_SHOW);