I have to code a PHP platform for importing an Excel file (quite heavy) to fill an SQL server database.
To do so I used the library PHP-excel-reader (https://code.google.com/archive/p/php-excel-reader/downloads) to be able recover the value of specific cells (eg $ water = $ data-> val (13, 'A');) everything works fine except that PHP-excel-reader is only compatible with .xls not .xlsx, if I go directly convert my files in excel no problem.
But so that the user does not have to do this operation every time I want automated converting .xls .xlsx has.
I tried to use PHPExcel (http://phpexcel.codeplex.com/) but nothing works all the file converted by the libraries do not work on PHP-excel-reader. Would you have a solution?
If there is no solution do you have knowledge of another library that allows like PHP to store the value of an Excel cell in a variable?
I am desperate. Thank you in advance for your help. Sorry for my English I'm french x)
For those interested, I found a solution. It is used the SimpleXLSX library (http://www.spyrozone.net/hacking/2011/05/php-parse-and-retrieve-data-from-xlsx-files.jsp), it will return from to an .xlsx an array of values where it will be to recover each cell value. if you have a problem with date conversion check this ( https://www.ablebits.com/office-addins-blog/2015/07/01/excel-convert-time-decimal/)
Related
Is there any way to format the cells of a csv file with php ? For instance , i have a csv file that i need to format its cell's size before i export it.And another thing is that for numbers with many digits,the excel shows it in another format before i dobule click it and i want to get rid of this too.
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=export.csv');
I know that i have to show what i have already tried,but i couldn't find any information about this,so i have nowhere to begin...
EDIT: The file is csv but i use it as an excel file,and the excel cells are the ones that need to be formated
CSV format consists of nothing more than raw values; there is no way of storing formatting or data type information. Which is why most, if not all, spreadsheet apps let the user manually set column types when importing a CSV file.
If you want to spare your users the hassle of doing that, your best bet would be generating an xls/xlsx rather than CSV. PHPExcel is a popular PHP library for generating Excel files, you might want to give it a try.
Since the accepted answer was written in 2014, the PHPExcel library has been abandoned. It's last version, 1.8.1, was released in 2015. It was officially deprecated in 2017 and permanently archived in 2019. It's direct successor is PhpSpreadsheet.
PHP can parse a CSV string into an array by using str_getcsv (http://php.net/str_getcsv). From there it's simply a matter of editing the values of the array.
As for more advanced features, the CSV format in itself does not support them since it's a pure text format and neither PHP nor the CSV file can decide how Excel should parse the file.
I've had success with exporting Excel XML files (the old, pure text XML files; not the new, zipped ones) and if data presentation is important for you, this might be the way to go.
I have a php script that have to parse an excel file with some date and time to import in my mysql database
Screen of the xlsx file :
I'm using the PHPExcel library to read the file
When I get the cell value with getValue() method, it returns the formula =J4+"01:00:00" as showed in the excel formula field. Ok normal
When I use the the getCalculatedValue() method, it returns "#VALUE!". As excell / Libreoffice don't have any problem to calculate the formulas, I have no idea why the PHPExcel library is not able to calculate this quite simple formulas.
Do anyone had the same issue and know a trick to fix this issue ? Or do I realy have to tell users not use any formulas fort date fields type ?
I found the answer from the PHPExcel support platform.
The only way to manage this kind of formulase (date operation) is to replace my actual formulas by something like =J4+(1/24)
Source : PhpExcel support plateform
I have a problem with my project. i want to import Excel sheet directly into mysql database for PHP language without any conversion of Excel sheet into another format. i am very fed about this from last two weeks. So Please help me How I Do it. any expert please help me
You can refer to this question: Reading an Excel file in PHP
Read the excel file using either PHPExcel or PHPExcel Reader (or any other preferred php lib...)
As you are reading the file, insert the data you read into your database.
There is one excel sheet which contains student name, rollno etc. How can i parse the contents of excel file and store that in my sql database?
You are looking for PHPExcel library i believe.
http://phpexcel.codeplex.com/
use this class to read the excel files
http://sourceforge.net/projects/phpexcelreader
If you want to do it directly from the Excel file, rather than create an intermediate CSV using Excel's "Save As" options, then look at libraries such as PHPExcel that can read the xls binary format and make the data accessible to your PHP script.
I'd recommend to you that you save it as csv, it's much more easier and less hacking to upload it to the database
here is simple a sample
http://www.bradino.com/php/csv-upload-to-database/
PHPExcel is one of the best PHP classes i have ever worked with. In addition to parsing and reading files of all Excel variations (including csv) the output to Excel 2007 + is excellent.
Be sure to look at the documentation and examples...they will get you up to speed very quickly
I need to implement a functionality where a user can upload an Excel file, that is, .xls file and i need to write a function that will read that file and then save the values in a table, compare them to values in another table and then print some kind of billing quotation.
From what I have read, it seems that the best way to do that is to first convert that file to an xml file and then write a function to parse that xml file.
I want to know, is it possible to write a function in php that will convert an xls file to xml. Assuming that the users will save and upload the file as xls.
Thanks.
i often let admin users upload a csv file they exported from an xcel file, its much simpler to parse through using http://php.net/manual/en/function.fgetcsv.php
A quick Google search for "PHP excel parser" turns up PHP Excel Reader, for an open source library to use for reading data from .xls files. There may be others that suit your needs.
I have been successfully using the 'ABC Excel Parser Pro' from Zakkis.
This allows converting from a XLS file directly into a MySQL table.
A few notes on limitations:
column count must match exactly to database columns
Excel 2007 format (xlsx) are not supported