function read() { $reArr = array(); include_once "excelparser/excelparser.php"; $exc = new ExcelFileParser(); $res = $exc->ParseFromFile($this->excfile); $RS = $exc->worksheet['data']; //print_R($RS);exit; for ($she = 0; $she <= count($exc->worksheet['name']); $she++) { for ($col = 0; $col <= $exc->worksheet['data'][0]['max_col']; $col++) { for ($row = 0; $row <= $exc->worksheet['data'][0]['max_row']; $row++) { $data = $exc->worksheet['data'][0]['cell'][$row][$col]; $ind = $data['data']; //print $data['type'].":".$data['data']."<BR>"; switch ($data['type']) { // string case 0: $ind = $data['data']; if ($exc->sst['unicode'][$ind]) { $s = $this->uc2html($exc->sst['data'][$ind]); } else { $s = $exc->sst['data'][$ind]; } if (strlen(trim($s)) == 0) { $reArr[$she][$col][$row] = ""; } else { $reArr[$she][$col][$row] = $s; } break; // integer number // integer number case 1: $s = $data['data']; $reArr[$she][$col][$row] = $s; break; // float number // float number case 2: $s = $data['data']; $reArr[$she][$col][$row] = $s; break; // date // date case 3: $s = $data['data']; $ret = str_replace(" 00:00:00", "", gmdate("Y-m-d H:i:s", $exc->xls2tstamp($s))); $reArr[$she][$col][$row] = $ret; break; default: $ind = $data['data']; if ($exc->sst['unicode'][$ind]) { $s = $this->uc2html($exc->sst['data'][$ind]); } else { $s = $exc->sst['data'][$ind]; } if (strlen(trim($s)) == 0) { $reArr[$she][$col][$row] = ""; } else { $reArr[$she][$col][$row] = $s; } break; } } } } //print_R($reArr);exit; return $reArr; }
function Read_Excel_File($ExcelFile, &$result) { $exc = new ExcelFileParser("", ABC_NO_LOG); $res = $exc->ParseFromFile($ExcelFile); $result = null; switch ($res) { case 0: break; case 1: $err = "�����ļ�"; break; case 2: $err = "�ļ�̫С�����ܲ���Excel�ļ�"; break; case 3: $err = "�ļ�ͷ��ȡ����"; break; case 4: $err = "��ȡ�ļ�ʱ���"; break; case 5: $err = "�ⲻ��һ��Excel�ļ�������Excel5.0��ǰ�汾�ļ�"; break; case 6: $err = "�ļ���"; break; case 7: $err = "���ļ���û�з���Excel���"; break; case 8: $err = "��֧�ֵ��ļ��汾"; break; default: $err = "δ֪����"; break; } for ($ws_num = 0; $ws_num < count($exc->worksheet['name']); $ws_num++) { $Sheetname = $exc->worksheet['name'][$ws_num]; $ws = $exc->worksheet['data'][$ws_num]; for ($j = 0; $j <= $ws['max_row']; $j++) { for ($i = 0; $i <= $ws['max_col']; $i++) { $data = $ws['cell'][$j][$i]; switch ($data['type']) { // string case 0: $ind = $data['data']; if ($exc->sst['unicode'][$ind]) { $s = uc2html($exc->sst['data'][$ind]); } else { $s = $exc->sst['data'][$ind]; } if (strlen(trim($s)) == 0) { $V = ""; } else { $V = $s; } break; // integer number // integer number case 1: $V = (int) $data['data']; break; // float number // float number case 2: $V = (double) $data['data']; break; // date // date case 3: $ret = $exc->getDateArray($data['data']); $V = $ret['year'] . "-" . $ret['month'] . "-" . $ret['day'] . " " . $ret['hour']; break; default: break; } $result[$Sheetname][$j][$i] = $V; } } } if ($err == '') { return 0; } else { return $err; } }
$fh = @fopen ($excel_file,'rb'); if( !$fh ) fatal("No file uploaded"); if( filesize($excel_file)==0 ) fatal("No file uploaded"); $fc = fread( $fh, filesize($excel_file) ); @fclose($fh); if( strlen($fc) < filesize($excel_file) ) fatal("Cannot read file"); $time_start = getmicrotime(); $res = $exc->ParseFromString($fc); $time_end = getmicrotime(); } elseif( $style == 'segment' ) { $time_start = getmicrotime(); $res = $exc->ParseFromFile($excel_file); $time_end = getmicrotime(); } switch ($res) { case 0: break; case 1: fatal("Can't open file"); case 2: fatal("File too small to be an Excel file"); case 3: fatal("Error reading file header"); case 4: fatal("Error reading file"); case 5: fatal("This is not an Excel file or file stored in Excel < 5.0"); case 6: fatal("File corrupted"); case 7: fatal("No Excel data found in file"); case 8: fatal("Unsupported file version"); default:
function Read_Excel_File($ExcelFile, &$result) { $exc = new ExcelFileParser("", ABC_NO_LOG); $res = $exc->ParseFromFile($ExcelFile); $result = null; switch ($res) { case 0: break; case 1: $err = "无法打开文件"; break; case 2: $err = "文件太小,可能不是Excel文件"; break; case 3: $err = "文件头读取错误"; break; case 4: $err = "读取文件时出错"; break; case 5: $err = "这不是一个Excel文件或者是Excel5.0以前版本文件"; break; case 6: $err = "文件损坏"; break; case 7: $err = "在文件中没有发现Excel数据"; break; case 8: $err = "不支持的文件版本"; break; default: $err = "未知错误"; break; } for ($ws_num = 0; $ws_num < count($exc->worksheet['name']); $ws_num++) { $Sheetname = $exc->worksheet['name'][$ws_num]; $ws = $exc->worksheet['data'][$ws_num]; for ($j = 0; $j <= $ws['max_row']; $j++) { for ($i = 0; $i <= $ws['max_col']; $i++) { $data = $ws['cell'][$j][$i]; switch ($data['type']) { // string case 0: $ind = $data['data']; if ($exc->sst['unicode'][$ind]) { //$s = uc2html($exc->sst['data'][$ind]); $s = iconv_ec('utf-16le', 'utf-8', $exc->sst['data'][$ind]); } else { $s = $exc->sst['data'][$ind]; } if (strlen(trim($s)) == 0) { $V = ""; } else { $V = $s; } break; // integer number // integer number case 1: $V = (int) $data['data']; break; // float number // float number case 2: $V = (double) $data['data']; break; // date // date case 3: $ret = $exc->getDateArray($data['data']); $V = $ret['year'] . "-" . $ret['month'] . "-" . $ret['day'] . " " . $ret['hour']; break; default: break; } $result[$Sheetname][$j][$i] = $V; } } } if ($err == '') { return 0; } else { return $err; } }