[eluser]Unknown[/eluser]
Hi,
i'm using Codeigniter 1.7.2 with the PHP Excel Reader found in the Codeigniter Wiki.
The standard use is to provide the filename of the Excel like this:
Code:
$params = array(‘file’ => $pathToFile, ‘store_extended_info’ => true,‘outputEncoding’ => ‘’);
$this->load->library(‘Spreadsheet_Excel_Reader’, $params);
I read the XLS files in a model, but due to that, that i have to read multiple files i cannot assign in the model constructor the filename to be read. I do it later in the specific functions. My constructor looks like this:
Code:
function Chartsofc() {
parent::Model();
$params = array("store_extended_info" => false, "outputEncoding" => "");
$this->load->library("Spreadsheet_Excel_Reader", $params);
}
I provide only store_extended_info false and standard encoding.
Later on in the functions i call the ***read*** method of the php_excel_reader library like this:
Code:
function get_sheet_names($File) {
$pathToFile = $this->xls_dir.$File;
$this->spreadsheet_excel_reader->read($pathToFile);
$sheetcount = $this->spreadsheet_excel_reader->sheetcount();
for($i = 0; $i < $sheetcount; $i++){
$sheet_names[$i] = $this->spreadsheet_excel_reader->boundsheets[$i]['name'];
}
return $sheet_names;
}
I think the problem is that php-excel-reader opens the files but does not close them. There is no method to close them. Also i dont see that php-excel-reader is closing the files automatically.
I got a function which first reads all excels and gets me the sheetnames, but the for reading i need to get the sheet index. i wrote a function for that and i works on lone files, but when i read here more and twice it produces wrong results This is because php-excel-reader's read function is called twice:
in $this->get_sheet_names($files[$index]);
and later in: $this->get_sheet_index_by_name("xls\\" . $fs_arr[$index2][0] , $fs_arr[$index2][1]);
Code:
function get_tags() {
$this->load->helper('directory');
$files = directory_map('./xls/');
$tags = array();
$fs_arr = array();
$init = 0;
for ($index = 0; $index < count($files); $index++) {
$sheets = $this->get_sheet_names($files[$index]);
for ($index1 = $init; $index1 < count($sheets); $index1++) {
$fs_arr[$init][0] = $files[$index];
$fs_arr[$init][1] = $sheets[$index1];
$init++;
}
}
for ($index2 = 0; $index2 < count($fs_arr); $index2++) {
$sheetIndex = $this->get_sheet_index_by_name("xls\\" . $fs_arr[$index2][0] , $fs_arr[$index2][1]);
echo $fs_arr[$index2][1] . ' - ' . $sheetIndex . "\r\n";
}
return $tags;
}
Then i got 4 XLS files and in produces a output of:
Code:
//name - index
1_PKB - 0
2_Inny - 1
3_Tortowy - 2
4_Liniowy - 3
5_test - 4
1_PKBO - 5
2_BZT5 - 6
3_PM10 - 7
1_PKB - 0
2_Inny - 1
Arkusz1 - 10
Arkusz2 - 11
Arkusz3 - 12
Rys_4_2_1 - 13
Instead of getting the right indexes of the sheets
Code:
//name - index
1_PKB - 0
2_Inny - 1
3_Tortowy - 2
4_Liniowy - 3
5_test - 4
1_PKBO - 0
2_BZT5 - 1
3_PM10 - 2
1_PKB - 0
2_Inny - 1
Arkusz1 - 2
Arkusz2 - 3
Arkusz3 - 4
Rys_4_2_1 - 0
Any ideas what to do? Is my seperated providing of the xls filename ok?