Read excel data Sheet by sheet using codeigniter and mysql and phpexcel

3.9k views Asked by At

I am done with basic import to database. I have explained in the following example where I got stuck up ...

For example,

I have an xls file named project.xls and it has 6 sheets. I have populated all 6 sheet names in dropdown. If I select sheet2 and click button, it should import sheet2 data into db and sheet3 so on.

How can I do this ...? please help me...

1

There are 1 answers

1
Jona On BEST ANSWER

You can access to differents sheets of a file with PHPExcelReader this way:

$filename = "path/to/filename.xls";
$reader = new Spreadsheet_Excel_Reader(); // Your PHPEXCELREDER Class
$reader->setOutputEncoding('UTF8');
// Read XLS File
$reader->read($filename);
$sheet = 2; // Your sheet

// Then walk trough your wanted sheet:

for ($i = 2; $i <= $reader->sheets[$sheet]['numRows']; $i++) {
// Do something
}