Is there a library extension available for efficiently handling pptx/docx/xlsx files using PHP? As of now I am more interested in PPTX files.
As per what i know, those file formats docx,xlsx,pptx are just zip files. they belong to Office Open XML (OOXML) standard.
In PHP we have this library for manipulating this type of zip documents: http://php.net/manual/en/book.zip.php
You can find all documentation about this ooxml standard here: http://www.ecma-international.org/publications/standards/Ecma-376.htm
The best way to test the structure of these ooxml file is to change the file extension to .zip, and the extract it out to find out what are inside.
If you don't want to build your own library for processing ooxml files, you can refer to a related question here for more info: PHP OOXML Libraries?
As i read from the related stackoverflow question mentioned above, you can use the phpdocx, or somewhat other called PHPWord.
Hope this may clarify some steps to help get your wants done
There is no one library that can handle all three formats, but there are individual libraries that can read and/or write the individual formats.
here is the working example that can read only docx file.
<?php
$filename = "file.docx"; // or /var/www/html/file.docx
$content = read_file_docx($filename);
if($content !== false) {
echo nl2br($content);
}
else {
echo 'Couldn\'t the file. Please check that file.';
}
function read_file_docx($filename){
$striped_content = '';
$content = '';
if(!$filename || !file_exists($filename)) return false;
$zip = zip_open($filename);
if (!$zip || is_numeric($zip)) return false;
while ($zip_entry = zip_read($zip)) {
if (zip_entry_open($zip, $zip_entry) == FALSE) continue;
if (zip_entry_name($zip_entry) != "word/document.xml") continue;
$content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
zip_entry_close($zip_entry);
}// end while
zip_close($zip);
//echo $content;
//file_put_contents('1.xml', $content);
$content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
$content = str_replace('</w:r></w:p>', "\r\n", $content);
$striped_content = strip_tags($content);
return $striped_content;
}
?>
You can build docx/xlsx/pptx documents from templates using the OpenTBS PHP tool.
The version currently in development will improve the support of XLSX.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With