Let's say I've some data in cells A1-Ax from which I should get this data, process and write the result to the B1-Bx, C1-Cx and D1-Dx cells. Preferably using PHP.
You may want to look at PHPExcel.
(PHPExcel) provides a set of classes
for the PHP programming language,
which allow you to write to and read
from different file formats, like
Excel 2007, PDF, HTML, ... This
project is built around Microsoft's
OpenXML standard and PHP.
I think this is best when you have a large application written in PHP which handles excel files. I think this is not the best for very small changes.
Hope that helps.
PHPExcel is really good for reading/writing excel documents (and csv files).
Used it in a lot of projects, works really well.
Related
I need to export data to an Excel template that contains VBA code and data validation in PHP.
I tried using PHPExcel library but it is removing the VBA code and data validations from the template.
I tried using PHPReport library, didn't get proper solution.
The template contains multiple worksheets and they are interdependent.
E.g.: Worksheet 1 contains employee data, then worksheet 2 contains salary with respect to employee name.
I have spent a great deal of time working on this problem, and the problem of memory consumption for large data sets. All of the PHP libs I have found keep all of the cells in memory, which is not viable for anything more than a small sheet.
What I ended up doing was writing a set of Java utilities using Apache POI and packaged them with PHP/Java Bridge so I can call them from PHP. This will allow you to create a new workbook based upon a template, keeping the macros intact. You can also use POI's streaming API, so you can handle massive data sets without crashing your server.
If you have Java chops, I highly recommend going this route, it's really the only way to do brain surgery on Excel files from PHP.
If you have any questions about how to do this or would like some example code, I'll be glad to help.
I am using php-excel-reader, but got error on reading .xlsx file. So does this support xlsx format. Or what is other solution available.
My requirement is just to read the file(xls, xlsx and ods) and render on html page.
PHPExcel seems too much as there is no requirement for editing the excel file.
Yes php support to read .xlsx file.
For that you have to use PHPExcel library.
I have created script to read excle file, You can download script from : https://www.dropbox.com/s/oao0eskflu8nyz1/PHPExcleReader.zip?dl=0
Judging from this issue it doesn't seem to work. They referr you to PHPExcel if you want to use xlsl files. From a first look, this seems like a better alternative anyways.
As far as I know php-excel-reader doesn't support xlsx. PHPExcel would be the way to go. That being said it might be better to store whatever is in your xslx files in a less proprietary way. Taking a long shot I would assume your xslx doesn't contain calculations which do belong in xlsx files but rather table data which would be better stored in some database (txt, csv, sqlite, a database server).
I need to read many excel sheets and for that, i'm using php.
My question is where can I get this read.php and where should I save it?
also, where should I put my excel sheets ? I never saw path for excel sheets given in codes on the web.
PHPExcel is a free full-featured PHP library for reading and writing Excel spreadsheets (xls & xlsx too).
http://phpexcel.codeplex.com/
Almost anything can be done with this, that an average user does with Excel, but it's usage needs OOP skills and some higher level practice at PHP.
I'm creating Excel files in a PHP project. Those files aren't just CSV data... They are multiple tabs spreadsheets with functions and formatting.
So far I'm using the Spreadsheet_Excel_Writer class that is provided with Pear.
Everything is fine but our users don't like 2 things:
When they open those files generated by PHP, modify them with Excel and save those changes, Excel ask to upgrade the file format because it was saved to version 5.0/95.
Files are way too large because of the embedded images. As far as I know the only way to add images with Spreadsheet_Excel_Writer is with insertBitmap which add 24 bit bitmaps to the document.
I would like to address those issues. I'm pretty sure #1 can't be done as you can see there. But is there a way to add compressed images (jpeg) to the document?
If it's not possible to modify Spreadsheet_Excel_Writer to meet my needs, what are your class recommendations for this? Searching questions here leaded me to PHPExcel. Are there any other good alternatives out there?
If possible I would like to stick with Spreadsheet_Excel_Writer because changing to another class would be much more work (those generated spreadsheets are quite complex).
I'm using PHP 5.2.9.
I ended up using PHPExcel. With this class I can avoid point #1 since I can save in may formats (including Excel 2003/2007). For point #2 it's possible and PHPExcel do this already. When you chose the old Excel format, PHPExcel extends Spreadsheet_Excel_Writer in order to save the file.
It was a pain to rewrite my the code to use the new class but it was worth it since PHPExcel is really nice.
I've done this with PHP using XML for the spreadsheets. Check out this link for the XML spreadsheet: http://msdn.microsoft.com/en-us/library/aa140066(office.10).aspx and http://blogs.msdn.com/dmahugh/archive/2006/12/10/images-in-open-xml-documents.aspx for inserting images.
I have tabulated data in an Excel spreadsheet (file size will likely never be larger than 1 mb). I want to use PHP to parse the data and insert in to a MySQL database.
Is there any advantage to keeping the file as an .xls/.xlsx and parsing it using a PHP Excel Parsing Library? If so, what are some good libraries to use?
Obviuously, I can save the .xls/.xlsx as a CSV and handle the file that way.
Thanks!
If you are just after the values, I would save it as a CSV. This is much easier to parse programatically, especially if you are trying to do this on a non-windows box.
That being said, there will be information lost in the export to CSV. It will only save the values of the cells - not their formatting information, formulas, etc. If you need to use that information, you're better off doing this straight from Excel.
Here is a PHP Excel Reading library. If you decide to read Excel files directly, this may help get you started.
If your excel files contain strictly data and contain no formulas, scripts, macros and etc., I would say parsing through Excel will only add development overhead, and will potentially slow down processing. It would probably be best to convert the files to CSV in this case.
Also consider that MySQL's 'LOAD DATA INFILE' command can be used to import entire CSV files into a table, this can potentially further uncomplicate matters for you.
when you provide a way for customers to upload excel/csv files, you should consider that
CSV files will only export one sheet
Having multiline cells will make the CSV parsing complicated
You cannot easily detect corrupted/incomplete CSV files
CSV files do not include formatting
Besides from that, importing CSV is a lot easier than importing XLS.
Remember that if you're importing the csv file directly into Mysql, that you may have problems with the date format (as Mysql uses a different date format to Excel). I find it easier to change the date fields in Excel first (to format yyyy-mm-dd) prior to saving as a csv file.
Edit: Although I've not used it myself, others have recommended Navicat as a very good tool for converting Excel spreadsheets or Access data into Mysql databases. May be worth a look.
With Office 2003 there's an XML format called SpreadsheetML which is a bit in-between XML and Excel. I've considered using this format to import/export data to a web site but the format turns out to be a bit complex. Internally, this format turns all references into relative references. (Relative from the current location.) Worse, some cells have an index, thus you might see a row with only two cells, but the second cell might be 6 columns away from the first cell. (In which case Index=5.) Basically, if you want to use the Excel format, you will need to have a good way to calculate the position of each cell and know how to translate the references in the cells in a proper way.
If you're onlyinterested in the data, CSV would be much, much easier to implement. As an in-between solution, you could define an XML schema and add an XML mapping to your spreadsheet to export the data to an XML file. It's more complex than CSV i9mport/export, but also a bit more robust. But the Excel or Excel XML formats themselves are horrible to implement. (Or just a nice challenge, if you're a real XML expert.)