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.
Related
I am developing an API, in PHP, hosted on a linux server, that requires me to make jpeg previews for a .pptx powerpoint presentation.
I first convert the file to pdf and then convert the pdf to jpegs.
The second step is easy, with ghostscript, it's the first part that's proving difficult.
I have tried using the libreoffice executable, but pptx isn't completely compatible. Certain backgrounds become invisible.
I have the same problem with many 3rd party APIs (which I suspect also use libreoffice); the ones that do work, are ridiculously expensive.
Installing office on a Linux server and using COM functions seems impossible, or very tedious at best.
I have looked at Aspose.Slides, which also seems rather expensive, and their documentation is filled with errors.
I could use suggestions on how to tackle this problem.
I have tried to find the underlying problem of why LibreOffice and online conversion tools have a problem with the backgrounds of the presentations I need to convert.
The background is a .emf file, which has bad support.
My solution
I've unzipped the presentation, converted the .emf files to png (using ghostscript), changed all mentions of .emf to .png in the XML, and rezipped the altered presentation.
When I now use the LibreOffice headless to convert to pdf, the background shows up.
It might be a bit hacky, but it works for the intent of my program.
ps. I see that my question has gathered a few downvotes. In my opinion it was a valid question, and listed the various solutions that had worked for others, but not for me. If anyone has insights or ways to improve it, feel free to comment.
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.
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.
I have an 'Excel' file (with a .xls extension) which turns out to be a plain text HTML file masquerading as a spreadsheet (if I run 'file [filename]' I get 'HTML document text' as the type). The file comes from a third party supplier and I have no control over the format.
I want to convert the file into Excel 97-2003 format so that I can read it in a PHP library (PHPExcel). I can do this by opening the file in Excel, ignoring the warning message and then explicitly saving it as Excel 97-2003, but I want to automate the whole process from the initial file coming in to extracting the cell data and dumping it into a database.
Ideally I'd like to use a PHP library for the conversion, because that would integrate better with the rest of the codebase, but libraries written in Perl, Java or (at a pinch) C# would also work, provided they don't rely on the server running Windows and Office.
Is there a tool or library available which can provide this functionality?
PhpExcel http://phpexcel.codeplex.com/ is decent but you'll have issues with it gobbling up memory with large sheets. For large sheets or speed I'd recommend perl writeExcel http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.37/lib/Spreadsheet/WriteExcel.pm
The perl writeExcel library is faster and uses less memory than PhpExcel. I then use
<?php
echo passthru('perl filename.pl');
?>
to run the perl script through PHP.
It looks like for the moment the only answer is to manually process the file by opening it in Excel and re-saving it, which does work but doesn't allow for complete automation.
I'll take a look at the new version of PHPExcel with HTML support once it has been released though as that sounds promising.
I am importing data from MS Excel spreadsheets into a php/mySQL application. Several different parties are supplying the spreadsheets and they are in formats ranging from Excel 4.0 to Excel 2007.
The trouble is finding a technique to read ALL versions.
More info:
- I am currently using php-ExcelReader.
- A script in a language other than php that can convert Excel to CSV would be an acceptable solution.
Depending on the nature of your data and the parties that upload the excel files, you might want to consider having them save the data in .csv format. It will be much easier to parse on your end.
Assuming that isn't an option a quick google search turned up http://sourceforge.net/projects/phpexcelreader/ which might suit your needs.
The open-source ETL tool Talend (http://wwww.talend.com) will generate Java or Perl code and package such code with the necessary 3rd party libraries.
Talend should be able to handle all versions of Excel and output the result set in any format you require (including loading it directly into a database if need be).