Write multiple sheet on OpenOffice spreadsheet file - php

I'm trying to solve how to write PHP in order to execute a report with multiple sheets on OpenOffice spreadsheet file (AKA ods). Now I used this code for generate the OpenOffice spreadsheet report but it can display only one sheet:
<?php
// Export Calc SpreadSheet
header("Content-Type: application/vnd.ms-excel");
header('Content-Disposition: attachment; filename="Report.ods"');
?>
How I can solve this problem?

There are many libraries out there that are able to be used within PHP to create, edit, and serve up spreadsheet files, or Workbooks (which are a collection of sheets...actually the spreadsheet file IS a workbook, even if it is just a single sheet). There are very well known ones, and some not-so-well known ones out there.
Most people will point to these:
PHPExcel - https://phpexcel.codeplex.com/
Spreadsheet_Excel_Writer -
http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.intro.php
ods-php - http://sourceforge.net/projects/ods-php/
openTBS -
http://www.tinybutstrong.com/plugins/opentbs/tbs_plugin_opentbs.html
there are a few more answers on questions like this one, but there is a daunting number of libraries and options.
My personal choice for a simple, small, openDocument format editor in PHP was ods-php, which is a single php file you include in your application, and instantiate. My use is not going to be creating ODS documents, but rather editing template files and serving up the edited document. You will have to write your own headers and echo the file contents in your own function in your PHP application, but that is not hard at all.
There is a [very] basic example php file included in the ods-php download that shows some of the functions, but if you can follow basic PHP logic, you can look through the library source and figure out its available functions. I'd say it would do just fine for what you need.
On the other hand, if you would rather have a bigger API at your disposal, and your server is decent enough to handle it, I'd recommend any of the other three. Keep in mind, the other three are rather large by comparison, and each has it's own strong and weak points:
PHPExcel is probably the most used by the free community, and is maintained on github constantly (last messed with 6 days ago), but is quite large. Documentation is available on the github site (I provided their old link, which links to their github).
Spreadsheet_Excel_Writer is tool from Pear, and is just as large, although it is no longer maintained, so what is there is 'as-is'. The Pear team is looking for someone to take over its maintenance, but what is there is as far as I can tell working.
openTBS is a single class library extension of the TBS engine (TinyButStrong). You have to install TBS in order to use openTBS, and it is a very good idea to enable zlib for compression capabilities of your files. If you go with openTBS, you not only get the ability to make xml based documents, but you get the functionality of the entire TBS engine at your disposal, which is quite nice if you would like to merge html source templates with your php scripts (check out the site, it might open some new frontiers for you).
there are definitely more libraries and tools out there, but these are the most notable ones I found in my search. My choice was guided by the driving force to keep my server tiny and standalone (it operates on a raspberry pi). If I were to choose a bulky, production environment API, I would probably choose PHPExcel because it has the support it needs to keep being up-to-date with M$' ever-adapting formats.

Related

Dependencies graph for large PHP application

I've recently inherited a large PHP application with NO objects/modules/namespaces...only a lot of files containing functions.
Of course, there is a LOT of dependencies (and all files and almost always included).
I'm looking for a tool that could analyse the files and generate a dependencies graph. It would then be easier to detect independent files/set of files and re-factor the whole thing.
So far the best solution I've found would be to write a CodeSniffer sniff to detect all functions calls and then use that to generate the graph.
It seems something useful for other, so I'm sure tools already exists for it.
What would you recommend ?
I think that the best solution is use a doc generat + grapviz, PHPDocumentor looks to have a Grapviz extension at https://github.com/phpDocumentor/GraphViz
This is a example made with PHPDocumentor:
http://demo.phpdoc.org/Clean/graphs/classes.svg
Too you can use a hierarchical profiler like xhprof (https://github.com/facebook/xhprof), this can draw a tree of all call to functions from a execution.
A example form xhprof draw done by Graphviz
I could recommend a lightweight project I wrote few days ago. Basically I had a 300+ files PHP project and I wanted to detect what files do these files require/include and vice-versa. Moreover, I wanted to check for each individual file what files does this file requires/includes (directly or indirectly, ie. via file inheritance) and vice-versa: what are the files that include this particular file. For any combination of these I wanted an interactive dependency graph (base on file inclusion and not on class/function calls/usage).
Check out the project's sandbox and its source code.
Note that the whole thing was written in only 2 days so don't judge it
too harsh. What's important is that it's doing its job!

Displaying word documents, excel sheet, power point in browser

Is there is any way to displaying world document,excel sheet and power point in browser with out downloading.
I assume that you are going to use php for this, so you can try checking some libraries such as PHPWord by Microsoft for example.
If you wish to only display the document content, it is possible to do using some scripting language such as php. Basically office 2007+ formats are zipped XML documents with changed extension. Make a simple word 2007+ document, save it and change extension from .docx to .zip, than you can extract it and see what it's made of. You can find a lot of details here. Now displaying content may be a little tricky. As mentioned, there are libraries out there to handle this, but how will they handle the documents, I am not really sure. Most of them are abandoned, PHPword is in beta since 2011.
There are some indications that Apache is working on cloud version of Open office, but there is no release date yet. Once done, you will have a full featured office suite web app.
If you feel really creative you could use cron job (or scheduled task if you like Windows) to open a document, take a screenshot and basically make .jpg or .png version of the document (works fine with short documents, longer ones may be problematic), displaying it in a browser without much complication. It is also possible to schedule export to .pdf - all browsers do have Adobe PDF plugins.
To sum up, using php for parsing simple documents should be fine, but getting complex docs to display properly, may be much more difficult task and possibly not worth your time. I would go for cron export to pdf, to preserve most if not all of the document's structure.

xls to ods conversion with php

Recently for a project i'm working, on i'm stuck between a rock and a hard place.
On one hand i have a third party component that gives me a certain report in .xls format.
This conponent is not controlled by me, so stays this way.
On the other hand i have a ods parser that parses all the data into mysql.
This also cannot be changed as i need the file to actually be ods for further manipulation. Plus it was requested this way by the party that commissioned the project.
Is there a way to convert xls into ods with php? Maybe with another step in the middle. Perhaps XML or anything of the like?
This all runs on LAMP so frankly i would not even mind some command line tool to
The Open Office alternative to COM, called PUNO, is the first option that springs to mind. Effectively, it gives you an interface to a copy of OO itself that needs to be running on your LAMP stack. Calc can read xls, and then "save as" ods.
A second option would be using Ilia Alshanetsky's Excel extension, which is a wrapper around the commercial libxl library (cost about $199).
It won't be an option for PHPExcel until sometime around Q2 2012, though it is on the development roadmap. None of the other PHP Spreadsheet reader/writer libraries offer the ability to write non-Excel formats from Excel document; so if you used any of the existing reader libraries, you'd need to "roll your own" writer.

How to view/convert uploaded file in/to pdf?

i am building a simple system using PHP that allow people to Add, Delete, and View data.
Can anyone tell me how to view the uploaded data in PDF format?
There are a bunch of options. The ones I like are:
wkhtml2pdf - A command-line tool that uses the WebKit HTML rendering engine to generate PDFs from HTML docs. Very easy to use, assuming you're able to get it installed on your server, and your requirements aren't too stringent. You just generate HTML/CSS, and use PHP's shell-exec functions to run it, and voila.
Zend_Pdf - Part of the Zend Framework, but like almost all ZF components, you can use it stand-alone. Programmatically build PDFs.
tcpdf, fpdf (with fpdi if you want to import existing PDFs and write over the top of them) - older, uglier, but effective.
There's also the commercial PDFLib, which used to be the best thing around, but I don't remember much about it. Included for approximate completeness.
Take a look at PDFLib, or its deprecated predecessor.

Open source PHP reporting tool

I am developing web based application, i need php reporting lib/class to make the job easy.
I need PDF/Excel format. The report based on related db tables(member bills, member info) Is there any advanced open source solution ?
Thanks
There are tons of reporting libraries, most of which create Xml or Csv. You would have to give more data about what kind of reporting you need for a recommendation. I haven't used PHPExcel yet, but it is the first attempt I have seen to actually create Excel documents rather than creating CSV's that will load in Excel. PDF creation is built into PHP with the PDF functions, and is fairly easy to do.
[UPDATE]
PHPExcel is archived now you can use PhpSpreadsheet instead.
A newer library that looks very promising is PHP Reports by jdorn on github.
This is unrelated to the older library by the same name hosted on Sourceforge.
A bit late, but you might want to check out RLib - works with PHP and MySQL and creates multiple different types - PDF, CSV, HTML etc.
http://rlib.sicompos.com/
Unfortunately I don't know of a decent reporting class in PHP.
Do you need a full reporting suite, or do you just need to be able to export data to the pdf and Excel file formats?
If you only need to create these kind of pages, the simplest solution would be to display the data you require and add CutePdf software which installs itself as a printer. Then you can print to pdf from the browser.
If you need to create pdf files on the server side, there is a pdf creation library in the Zend Framework. ZendFramework-1.8.1\library\Zend\Pdf

Categories