open and write into xlms-file with PHP - php

I develop webapp with PHP5 to read or to actualize xlsm files.
I have tried with PHPEXCEL, but this library not supported xlsm-files format.
Everything what I need, is open the file, write the data in there and stores as a xlsm-file.
The macro should not be changed.
It is important that the file returns which contains the macros because this file it is used daily to do several import. I may not change the file-format.
if somebody has tips or tutor's courses for this specific task has, please writes to me.
Thanks 4 your help

If you need to retain macros from an Excel template, then you'll need to use something like COM because there aren't any other libraries that handle macros from PHP

xslm files are actually ZIP files with XML documents and other assets inside them. PHPEXCEL and other similar MS Office file format readers and writers only read the older binary-blob formats, not the newer Office Open XML formats.
Try using ZipArchive to open the file in PHP, and one of the PHP XML libraries to read the xml inside the file. As long as you don't alter the macros, the macros will be preserved.
However, if you actually need to execute the macros, you need a full Office runtime. In this case you must use COM on windows with a copy of Office to run the file.

Related

How to fill data to template excel by php without api

I have some problem using phpexcel api.
this api is taking to long to fill data to exist template excel.
so, I want to write by pure php without using any api.
I want to know how to fill data to template excel by pure php.
Please give me some advise. Thanks :)
Old xls files were proprietary binary file formats, quite complicated, also known as Excel BIFF, you can find
reverse engineered specification here: http://www.openoffice.org/sc/excelfileformat.pdf
Microsoft's public specification here: [MS-XLS]: Excel Binary File Format (.xls) Structure (PDF) and here: [MS-XLS]: Excel Binary File Format (.xls) Structure (HTML)
New xlsx files are "standardized" open formats. It is basically a zip file (rename it to *.zip and extract) with few xml files inside
Some general information is available at http://en.wikipedia.org/wiki/Office_Open_XML
More detailed documentation is available from
MSDN: Office → Dev Center → Open XML SDK → Understanding the Open XML file formats
and from Ecma International → Ecma Office Open XML File Formats Standard
Still even the new file format is quite complicated if you want to be able to do everything or anything. In that case reusing several man/years of development effort (including debugging) materialized in a form of an existing PHP library as suggested by #mark-baker is reasonable
If you just need to do a specific task, e.g. populate existing xlsx template file with some data then you only need
a PHP functions for copying files
a PHP functions to work with zip files
and a PHP functions to work with xml files
and the documentation (from the links above) or an executable documentation in a form of Excel.exe
EDIT better links to the specification both for the old and for the new Excel file formats were provided by Mark Baker

.docx, .xlsx, .pdf to .pdf using PHP

I have relatively sensitive data in .docx, .xlsx and PDF files that all need to be converted to a single PDF file locally. Sending these files off to phpdocx or Google Docs or anything like this is not an option.
The only other option I am seeing is OpenOffice / LibreOffice but I am not satisfied with how they are converting the documents.
Is there any other alternative anyone is aware of? Thanks!
Definitely a difficult task. The very recent release of LibreOffice 3.6 has fixes to it's docx processing if that might help, but you haven't specified what the actual problems you encountered when you tried OpenOffice.
If you have time to experiment (and bring in any tools/languages you need to get the job done) you could try LibreOffice to produce PDFS, then use one of the many PDF libs to stitch the PDFs into the single file you require.
You could also look at ODFConverter which has traditionally been much better with DOCX than either OpenOffice or LibreOffice. This would allow you docx -> odt -> pdf. I think it can do the xlsx also. Then do the PDF stitching again.
I suggest testing the stages manually at first and if promising, try something like JODConverter (requires Java) to allow you to automate the process via scripts.
Good luck.

Is it possible to output formats other than .docx and .odt with TinyButStrong and OpenTBS plugin

I have a module which merges a document from database records and .docx or .odt document model.
I have to output .docx, .odt or .pdf. For outputting to Microsoft and Open formats, there is no problem, all works properly.
But what I want to know is, can I output to a format (like XML or HTML) which I can use to subsequently build a PDF document?
If I can't, are there any libraries which provide a merge document capability like:
DOCX (or ODT) + database record => PDF
And I don't want to use phplivedocx.
I successfully put a portable version of libreoffice on my host's webserver, which I call with PHP to do a commandline conversion from .docx, etc. to pdf. on the fly. I do not have admin rights on my host's webserver. Here is my blog post of what I did:
http://geekswithblogs.net/robertphyatt/archive/2011/11/19/converting-.docx-to-pdf-or-.doc-to-pdf-or-.doc.aspx
Yay! Convert directly from .docx or .odt to .pdf using PHP with LibreOffice (OpenOffice's successor)!
I don't know any PHP library that does DOCX => PDF. In fact, the DOCX conversion to something else in PHP is an opened problem today. This is independent from how you made the DOCX.
But as you said, they are PHP libraries for HTML => PDF.
Html2Pdf is a well reputed PHP library that does HTML => PDF.
There is also DomPdf.
So if you can found a PHP library for DOCX => HTML, then it would work.
Of course it has some limitations because even if both PDF and DOCX are opened format, they have very specific features, they need huge rendering process, and the editors keep some good tips for them.
Converting DOCX to HTML is theoretically possible. There is a Windows software that does it by EpingSoft. If you need to do it in PHP, some web articles tell you how to make it, but since I cannot found any PHP code doing this, I guess it is more theoretical than practical.
http://www.quepublishing.com/articles/article.aspx?p=691502
How complicated that process would be
depends on how much of Word's native
formatting you need to preserve during
the conversion.
If you want to try this way, it's good to know that OpenTBS enables you to read the XML before and after the merge. It is based on a PHP class names TbsZip that can read any XML file in the DOCX since it's in fact a zip archive.
There is also posible to use PDF files directly in TBS after decompressing:
qpdf --qdf --object-streams=disable in.pdf out.pdf

How do I read Word, Excell, and PDF docs in PHP?

I need to be able to read the text of many different file types in PHP, including .doc, .docx, excel, and PDF files. I found a few methods online that require installing multiple packages but I was wondering if there was a better way to do this?
No matter which way you swing it, there is no way to kill all these birds with one stone.
Word Thread:
Reading/Writing a MS Word file in PHP
Excel Thread:
Reading an Excel file in PHP
PDF Thread:
Read pdf files with php
office 2007 is very easy, just need to unzip them and read the xml files, older versions of office and pdf will need extra packages.
I don't think there is native support for reading documents with PHP. Installing these packages is the only choice. :-)
maybe this URL can help you:
https://github.com/PHPOffice
where have:
-PhPWord,
-PhpSpreadsheet(instead of PhPExcel)
...

Parsing and generating Microsoft Office 2007 files (.docx, .xlsx, .pptx)

I have a web project where I must import text and images from a user-supplied document, and one of the possible formats is Microsoft Office 2007. There's also a need to generate documents in this format.
The server runs CentOS 5.2 and has PHP/Perl/Python installed. I can execute local binaries and shell scripts if I must. We use Apache 2.2 but will be switching over to Nginx once it goes live.
What are my options? Anyone had experience with this?
The Office 2007 file formats are open and well documented. Roughly speaking, all of the new file formats ending in "x" are zip compressed XML documents. For example:
To open a Word 2007 XML file Create a
temporary folder in which to store the
file and its parts.
Save a Word 2007 document, containing
text, pictures, and other elements, as
a .docx file.
Add a .zip extension to the end of the
file name.
Double-click the file. It will open in
the ZIP application. You can see the
parts that comprise the file.
Extract the parts to the folder that
you created previously.
The other file formats are roughly similar. I don't know of any open source libraries for interacting with them as yet - but depending on your exact requirements, it doesn't look too difficult to read and write simple documents. Certainly it should be a lot easier than with the older formats.
If you need to read the older formats, OpenOffice has an API and can read and write Office 2003 and older documents with more or less success.
The python docx module can generate formatted Microsoft office docx files from pure Python. Out of the box, it does headers, paragraphs, tables, and bullets, but the makeelement() module can be extended to do arbitrary elements like images.
from docx import *
document = newdocument()
# This location is where most document content lives
docbody = document.xpath('/w:document/w:body',namespaces=wordnamespaces)[0]
# Append two headings
docbody.append(heading('Heading',1) )
docbody.append(heading('Subheading',2))
docbody.append(paragraph('Some text')
I have successfully used the OpenXML Format SDK in a project to modify an Excel spreadsheet via code. This would require .NET and I'm not sure about how well it would work under Mono.
You can probably check the code for Sphider. They docs and pdfs, so I'm sure they can read them. Might also lead you in the right direction for other Office formats.

Categories