Search code examples
phpsymfonylibreoffice-calcopentbs

Exporting raw data with OpenTBS mergeField method


I'm using OpenTBS to export statistics to a .ods file. I'd like to be able to generate graphs in the generated document. Problem is that each piece of data exported is escaped with a single quote (') in the generated document. I can't generate graphs without removing it.

Is there a way to specify raw data with OpenTBS mergeField() method ?

Here's a peak at the code :

$model = __DIR__ . "/../../Resources/public/models/Stats/Stats_mensuelles_template.ods";

$targetDir = __DIR__ . self::Z2_DOCGEN_TARGETDIR;

$this->setDocumentName($document, $this->type);

// (...) fetching the data (...)


// each getComptage* method return an integer value
$sm = array(
    "date" => $statistique->getDateFin()->format('M Y'),
    "pn" => $statsCurrentMonth->getComptagePaliersNormaux(),
    "pe" => $statsCurrentMonth->getComptagePaliersExceptionnels(),
    "cu" => $statsCurrentMonth->getComptagePaliersUrgents(),
    "pb" => $statsCurrentMonth->getComptagePatchesBIRDe(),
);

//Chargement de la page principale
$this->tbsManager->LoadTemplate($model, OPENTBS_ALREADY_UTF8);
$this->tbsManager->MergeField('sm', $sm);
$this->tbsManager->Show(OPENTBS_FILE, $targetDir . $document->getNom());

Here's what the cells in the .ods template looks like ([sm.*] and labels are in seperate cells):

Statistiques mensuelles [sm.date]
Palier normal             [sm.pn]
Palier exceptionnel               [sm.pe]
Palier urgent             [sm.cu]
Patch BIRDe               [sm.pb]
Autres paliers                [sm.div]

Finally, here's an example of generated cells

Palier normal             '30
Palier exceptionnel               '8
Palier urgent             '15
Patch BIRDe               '41
Autres paliers                '28

Thanks


Solution

  • I eventually found an answer in OpenTBS Documentation - section "create OpenOffice and Ms Office documents with PHP"

    The single quote is added on the document side when filled. And it usually consider every piece of data as a string no matter what is actually sent.

    OpenTBS can handle this snag by explicitely specifying the field type in the template.

    So, if we take my template, here's how we'd deal with the first numeric field :

    [sm.pn;ope=tbs:num]
    

    and so on