• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to read data from Excel & insert into table using CI?

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.

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.

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.

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

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.

I got it.

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.


Thanks so much..

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


The link is dead. Thanks.

So just use php. http://php.net/manual/en/function.fgetcsv.php

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.