I am trying to read an Open Document Spreadsheet (*.ods) file in PHP using 'TinyButStrong template engine' along with the 'OpenTBS' plugin. My target is to convert the spreadsheet's cell data into a PHP array.
Sample ods row data (row #4 of inferno.ods):
Here is my code:
include_once('lib/plugins/tbs_3140/tbs_class.php');
include_once('lib/plugins/tbs_3140/opentbs-master/tbs_plugin_opentbs.php');
$TBS = new clsTinyButStrong;
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
$TBS->LoadTemplate('inferno.ods', OPENTBS_ALREADY_UTF8);
$options= array('noerr'=>true);
$metaOdsObj= $TBS->Plugin(OPENTBS_GET_CELLS, '$A:$B', $options);
//$xml = $TBS->Source;
var_dump($metaOdsObj);
//var_dump($xml);
The output:
array(6) {
...
[3]=>
array(2) {
[0]=>
float(5)
[1]=>
string(4) "THE "
}
...
}
Note that only the first line of the cell data (separated by a new line) is fetched as the cell value. How can I get the complete text (with new lines) of a cell as an array value? Any clues?
$TBS->Source
fetches the contents in XML with each line inside the cells separated by a <text:p>
tag. I tried using PHP SimpleXML and DOMDocument::loadXML with this xml data without the desired outcome.
Thank you for reading this far. And also a ton of thanks for giving it a thought.
This is an OpenTBS bug that limits the string cell reading to the first line.
This bug is fixed as of OpenTBS 1.11.0-beta4. You can patch the function OpenDoc_GetCellValue() using the code available at GitHub.
Thanks for reporting this issue.