Read data from xlsx file in php and print as php array - php

I need a php script which can read the data from an uploaded xlsx file. Also I need to print those data in an array format. Please help.

Save as CSV first and after that - parse it with http://gist.github.com/385876

Related

Excel Data is not reading from amazon s3 server

I am uploading the excel file in amazon s3 server and its getting uploaded successfully, but while reading that same excel file in php getting the below data.
����E� �ɂ^R,5��� I
�ҧ���{ߙw�Ig�FS���셄�0b����[�Jb���k�>+��s��Q�z�� ,E�� º
����u��� ����O�DC�pn��Wi�_��p1F�h��axu���\tWW�N�b��~�:� >����*���p�1�ڧ 掓�f��Q����PK)��e�PK�;:K
xl/styles.xml�Y[o�0}߯���R�e
�Z�L���j�4i�&�8�Uǎ�B�| ! ��jT>���%7�l�Q��EA8��A�B���(�xA!�������rF�m�����J�r�"Lq���c�jb.2$UQ$N���B7ʨ�v:GN����&Y���|¤�QA��F
<�A`��<RR�\^]ޜ���9%��Ŝ-x���W<�DIW���rD2� 蘟�ʰ
xl/sharedStrings.xmlPK�;:K)��e��xl/workbook.xmlPK�;:K�,q�^�
Gxl/styles.xmlPK�;:K�!49���docProps/app.xmlPK�;:K�ma�m�docProps/core.xmlPK�;:K�������docProps/custom.xmlPK�;:K�#��C��[Content_Types].xmlPKh
using the below php code to print the data
$s3Client->registerStreamWrapper();
$stream = file_get_contents(utf8_encode($this->stock_catalog_xls_path), 'r');
echo $stream;
so please can you give me any idea how to read this excel data in php.
You are reading Excel as a raw file.
You need to pass the contents to an Excel library, so you can read them with cells, sheets format.
Below is the library that can help you in converting the raw file to excel readable format.
https://github.com/PHPOffice/PHPExcel
Sample implementation on how to read Excel file.
https://github.com/PHPOffice/PHPExcel/blob/1.8/Examples/07reader.php
Hope it helps.

How to convert html into *.xlsx using php?

Good morning.
I have a test.html file. I would like to convert into test.xlsx using php.
Now, I could create test.xls file using php, whereas it is having only html tags due to that this file could not open directly in excel and it shows extension error. so if the file is having test.xlsx format gets opened smoothly.
I did not know that how to proceed further to get an expected results.
Please help if possible.
Thanks in advance.
Best regards,
Balraj
Use PHPExcel_Reader_HTML function of PHPExcel

Change excel file extension from xls to xlsx while uploading with php

Is it possible and if is how can i change excel file extension while uploading or before saving file on server? I am using php and mysql.
Thankyou
You can do something like this.
move_uploaded_file($_FILES['file']['tmp_name'], upload_PATH.'/'.$_FILES['file']['name'].'x');
But that will only change the file name with the xlsx extension. It will not actually convert the file to xlsx format.
As previously mentioned in a different reply, changing the extension won't actually change the format, and it's not a good idea to serve a .xls file as .xlsx, since this will only confuse anyone trying to read it.
What you could do (disregarding potential problems with converting and verification of the file) is read the uploaded file into a library like PHPExcel (http://phpexcel.codeplex.com) and then use the builtin functions to export it as an .xlsx file. Sample below:
// Create a reader to read .xls format
$reader = PHPExcel_IOFactory::createReader('Excel5');
// Read the .xls file from upload storage
$workbook = $reader->load($_FILES['file']['tmp_name']);
// Create a writer to output in .xlsx format
$writer = PHPExcel_IOFactory::createWriter($workbook, 'Excel2007');
// Save file to destination .xlsx path
$writer->save($destination_path);
Keep in mind that although this might work perfectly well, the conversion might mess with the contents of the file. This might not be desirable, as the conversion can cause data loss, formatting changes and all sorts of weirdness.

PHP Parse a PHP file echoing XML data

I have a php file which generates and echo's XML data.
So basically it shows a XML but it's a PHP file.
I need to read and parse this data.
I've seen this: simplexml_load_file('some.xml'); but in this case I cannot do this as I've got the xml as a php file.
How can I do this?
Just the same way, the file extension doesn't matters (.xml or .php) what it really matters is the actual contents of the file, so if your file have a .php extension but its contents are valid xml then you should have no problem:
simplexml_load_file('somepage.php'); //this is fine
Set mime type to xml header('Content-Type:text/xml');

Output Graph, CSV & Excel file from PHP

I have a PHP code which will generate Graph & HTML table which is working fine. - Main_data.php
CSV output PHP is working fine. - CSV.php
Excel output PHP is working fine.
How to output all three reports when running Main_data.php?
I tried to include Csv.php in Main_data.php. I am not able to produce results from main_data.php.
Any suggestions on how to implement that function into my script?
Make functions displayGraph() and displayCSV().
Put them in one file by copying your codes from main_data.php and csv.php, include that file in a file you want to display graph and CSV from and execute the functions.

Categories