importing the data from XLS file to php with simple coding - php

I have the excel file with the following fields
First Middle Last Email
michael j jackson michael#plantgenomesciences.com
mary j watson mary#microsoft.com
jeff a bridges jeff#rediff.com
nick h gill nick#gill.com
If possible please tell me how can i get the data from Name Box (K8) from the same file
I want to know how can import this data into the php (I m able to upload the excel file on the server)
by using simple code (not any premade script)

Typically for files like spreadsheets, CSV import is most used. You can export excel file to csv. and then import it using PHP.
See http://in.php.net/manual/en/function.fgetcsv.php
But it seems you are looking to read excel files, you may need help of third-party libraries for that. You also have a look at the following article:
http://www.ibm.com/developerworks/opensource/library/os-phpexcel/

You won't be able to write any simple code to read a BIFF file yourself in any reasonable timeframe. Your only quick solution, given an unwillingness to use a library capable of reading BIFF files, is to convert it to a different format (such as CSV) before uploading it.
Alternatively, if you're on a windows server, you could try using PHP's COM extension (as long as you install MS Excel on your server)

Related

How to fill data to template excel by php without api

I have some problem using phpexcel api.
this api is taking to long to fill data to exist template excel.
so, I want to write by pure php without using any api.
I want to know how to fill data to template excel by pure php.
Please give me some advise. Thanks :)
Old xls files were proprietary binary file formats, quite complicated, also known as Excel BIFF, you can find
reverse engineered specification here: http://www.openoffice.org/sc/excelfileformat.pdf
Microsoft's public specification here: [MS-XLS]: Excel Binary File Format (.xls) Structure (PDF) and here: [MS-XLS]: Excel Binary File Format (.xls) Structure (HTML)
New xlsx files are "standardized" open formats. It is basically a zip file (rename it to *.zip and extract) with few xml files inside
Some general information is available at http://en.wikipedia.org/wiki/Office_Open_XML
More detailed documentation is available from
MSDN: Office → Dev Center → Open XML SDK → Understanding the Open XML file formats
and from Ecma International → Ecma Office Open XML File Formats Standard
Still even the new file format is quite complicated if you want to be able to do everything or anything. In that case reusing several man/years of development effort (including debugging) materialized in a form of an existing PHP library as suggested by #mark-baker is reasonable
If you just need to do a specific task, e.g. populate existing xlsx template file with some data then you only need
a PHP functions for copying files
a PHP functions to work with zip files
and a PHP functions to work with xml files
and the documentation (from the links above) or an executable documentation in a form of Excel.exe
EDIT better links to the specification both for the old and for the new Excel file formats were provided by Mark Baker

open and write into xlms-file with PHP

I develop webapp with PHP5 to read or to actualize xlsm files.
I have tried with PHPEXCEL, but this library not supported xlsm-files format.
Everything what I need, is open the file, write the data in there and stores as a xlsm-file.
The macro should not be changed.
It is important that the file returns which contains the macros because this file it is used daily to do several import. I may not change the file-format.
if somebody has tips or tutor's courses for this specific task has, please writes to me.
Thanks 4 your help
If you need to retain macros from an Excel template, then you'll need to use something like COM because there aren't any other libraries that handle macros from PHP
xslm files are actually ZIP files with XML documents and other assets inside them. PHPEXCEL and other similar MS Office file format readers and writers only read the older binary-blob formats, not the newer Office Open XML formats.
Try using ZipArchive to open the file in PHP, and one of the PHP XML libraries to read the xml inside the file. As long as you don't alter the macros, the macros will be preserved.
However, if you actually need to execute the macros, you need a full Office runtime. In this case you must use COM on windows with a copy of Office to run the file.

How to create a MSEXCEL file using PHP

Good day,
How do i create an msexcel file using php script?
I have already prepared my data in a well structured array. I need
to be able to format my array into tables in msexcel.
the server where the WAMP server is running has no MS Office installed, would it
affect my objective to create the msexcel file. do i need to install on msoffice
in the server in case? fyi, i dont actually need to save the excel file in the server
but can be an option too.
thanks.
This is really a spin on DaveRandoms comment.
Make a CSV and set the mimetype to any of the ones in this SO question.
That way Excel (or any equivalent application) will start and show the file.
The PHPExcel library will let you take your data and write it into a valid Excel file, whether you need old-style XLS or new style XLSX format.
You don't need to have Excel installed on the server to use it.

writing to a XLS file using PHP

My application generates some .xls files and until now I was using PHPExcel lib. One of the SO has recommend me to use this approach. The problem is that I have to use some .xls templates and to append some data to them.
Who can help me with some pointers. I don't get how xlsBOF() and xlsEOF() works or have to work in my case.
If the approach you use right now works for you, don't bother with anything else.
PHPExcel writes XML files (or more accurately zip files containing XML files), in the new Excel 2007 format. For this reason, it's not compatible with older office versions (unless you install the compatibility plugin in the older office).
What this code does is write a binary XLS file in Excel 97 (BIFF8) format. It's a bit of a hack though. This won't deal correctly with unicode issues and so on. xlsBOF writes the binary header of the XLS file, and xlsEOF the footer.
If you want to write binary XLS files, you're better off using PEAR Excel Writer. I have mixed experiences with that. It gets the job done, but to use it with unicode you have to look through the bug list for a few patches that fix BIFF8 format bugs (the package is poorly maintained). It's still better than the code you linked to though.
Update: PHPExcel supports export as Excel 97 also. I remember that it used to be limited to the office 2007 file format, but apparently currently it's not. So I would recommend using PHPExcel.

What is the best way to process all versions of MS Excel spreadsheets with php on a non-Windows machine

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).

Categories