コード例 #1
0
ファイル: INDEX.PHP プロジェクト: helloris25/mvc
 }
 $tbl_SQL = rtrim($tbl_SQL, ',');
 $tbl_SQL .= ") TYPE=MyISAM";
 $fh = @fopen($excel_file, 'rb');
 if (!$fh) {
     fatal("Невозможно загрузить файл");
 }
 if (filesize($excel_file) == 0) {
     fatal("Невозможно загрузить файл");
 }
 $fc = fread($fh, filesize($excel_file));
 @fclose($fh);
 if (strlen($fc) < filesize($excel_file)) {
     fatal("Невозможно считать файл");
 }
 $exc = new ExcelFileParser();
 $res = $exc->ParseFromString($fc);
 switch ($res) {
     case 0:
         break;
     case 1:
         fatal("Невозможно открыть файл");
     case 2:
         fatal("Файл, слишком маленький чтобы быть файлом Excel");
     case 3:
         fatal("Ошибка чтения заголовка файла");
     case 4:
         fatal("Ошибка чтения файла");
     case 5:
         fatal("Это - не файл Excel или файл, сохраненный в Excel < 5.0");
     case 6:
コード例 #2
0
	$excel_file = $_FILES['excel_file'];
	if( $excel_file )
		$excel_file = $_FILES['excel_file']['tmp_name'];

	if( $excel_file == '' ) fatal("No file uploaded");

	$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");

	$exc = new ExcelFileParser;
	//if( $exc->ParseFromFile($excel_file)>0 ) fatal($err_corr);
	$res = $exc->ParseFromString($fc);
	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:
			fatal("Unknown error");
コード例 #3
0
ファイル: readExcel.php プロジェクト: shesai0519/sunshineCRM
 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;
 }
コード例 #4
0
ファイル: sample.php プロジェクト: pthis/software-engineering
		echo ": $msg";
	echo "<br>\nScript terminated<br>\n";
	if( $f_opened) @fclose($fh);
	exit();
};

$err_corr = "Unsupported format or file corrupted";

$excel_file_size;
$excel_file = $_FILES['excel_file'];
if( $excel_file )
	$excel_file = $_FILES['excel_file']['tmp_name'];

if( $excel_file == '' ) fatal("No file uploaded");

$exc = new ExcelFileParser("debug.log", ABC_NO_LOG );//ABC_VAR_DUMP);

$style = $_POST['style'];
if( $style == 'old' )
{
	$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();
コード例 #5
0
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;
    }
}
コード例 #6
0
ファイル: excel_class.php プロジェクト: honj51/taobaocrm
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;
    }
}