Welcome Guest, Not a member yet? Register   Sign In
How to read data from Excel & insert into table using CI?
#1

[eluser]suba[/eluser]
Hi every one,
I have some data in Excel sheet.
Now I want to upload my excel data into table using CI.
So do you have any idea or any reference manual for CI?
please advice me.
Thanks..
#2

[eluser]richthegeek[/eluser]
It depends...

If the file is in the old (.xls) format, and you have access to the server, and can install packages: install Perl (probably pre-installed) and use http://www.topology.org/linux/xls.html OR just use http://search.cpan.org/dist/Spreadsheet-...el-Simple/

If its in .xls but you can't install packages, you need to have the file exported to .csv and parse using file() and preg_match() (google it!)

If its in the new format (.xlsx), and your server matches the requirements (PECL zip/zlib) you can extract using PHP's zip functions http://www.php.net/manual/en/book.zip.php

The simplest to program is the export to CSV and going from there - the rest is a case of moving the .xls(x) file to CSV first.
#3

[eluser]suba[/eluser]
Hi Thank you so much.

one more question.
Now my xls sheet has saved as to xml format.
So now how to retrieve data from xml format and import into table.

NOTE:
using MS office 2007, I changed xlsx format to xml format.
sample xml file:
<Row ss:AutoFitHeight="0">
<Cell ss:StyleID="s81"><Data ss:Type="String">NAME OF THE PERSON</Data><NamedCell
ss:Name="_FilterDatabase"/></Cell>
<Cell ss:StyleID="s81"><Data ss:Type="String">PERSON ID</Data></Cell>
<Cell ss:StyleID="s81"><Data ss:Type="String">ADDRESS OF PERSON</Data></Cell>
<Cell ss:StyleID="s62"><Data ss:Type="Number">PHONE NUMBER</Data></Cell>
</Row>
#4

[eluser]richthegeek[/eluser]
SimpleXML, PHPQuery, or plain old PXML libaries will all get what you need. If you already know CSS selectors and/or jQuery, PHPQuery will be the easiest to pick up.
#5

[eluser]suba[/eluser]
Thanks..
I got it.
Thanks..
#6

[eluser]umefarooq[/eluser]
better way to import your excel file is first convert it to csv file because csv file has no complex header and really easy to parse, here is csv file reader library for CI and really helpful to import data from csv file just read the comment in lib file you will under stand how to import data to database really easy, find out here.

http://codeigniter.com/wiki/CSVReader/
#7

[eluser]suba[/eluser]
Hi,
Thanks so much..
#8

[eluser]sparky672[/eluser]
[quote author="umefarooq" date="1262071736"].... find out here.

http://codeigniter.com/wiki/CSVReader/[/quote]

The link is dead. Thanks.
#9

[eluser]CroNiX[/eluser]
So just use php. http://php.net/manual/en/function.fgetcsv.php
#10

[eluser]mikemiller[/eluser]
You could try PHPExcel - very capable library that can be used to read excel files (including xlsx)

https://phpexcel.codeplex.com




Theme © iAndrew 2016 - Forum software by © MyBB