简体   繁体   English

PHPExcel_Reader_Exception被识别为OLE文件

[英]PHPExcel_Reader_Exception recognised as an OLE file

Please help me reading an excel file upload attached. 请帮助我阅读附加的excel文件上传。 When I attach an XLS format, my PHPExcel reader is not working. 当我附加XLS格式时,我的PHPExcel阅读器无法正常工作。 Do you think where am I missing? 你以为我在哪里想念?

HTML 的HTML

<form role="form" id="myForm" class="add_customer_form" enctype="multipart/form-data">
    <label for="fileUpload">Upload File *</label>
    <input type="file" id="files" name="file[]" class="form-control"
      accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, text/plain, application/vnd.ms-excel"
    multiple required>
</form>

AJAX AJAX

//USAGE: $("#form").serializefiles(); //用法:$(“#form”)。serializefiles();

(function($) {
    $.fn.serializefiles = function() {
        var obj = $(this);
        /* ADD FILE TO PARAM AJAX */
        var formData = new FormData();
        $.each($(obj).find("input[type='file']"), function(i, tag) {
            $.each($(tag)[0].files, function(i, file) {
                formData.append(tag.name, file);
            });
        });
        var params = $(obj).serializeArray();
        $.each(params, function (i, val) {
            formData.append(val.name, val.value);
        });
        return formData;
    };
})(jQuery);

$.ajax({
    url: base_url+'customer/customer_add',
    type: 'POST',
    data: values,
    cache: false,
    contentType: false,
    processData: false,
    success: function(data){ 
            console.log(data);
    }
});

PHP 的PHP

foreach($_FILES["file"]['name'] as $file => $fname) {
    $file_path  = $_FILES["file"]["tmp_name"][$file];
    $extension = pathinfo($fname);

    if($extension['extension'] == 'xls') {
        $objReader = PHPExcel_IOFactory::createReader('Excel5');    
    }
    else {
        $objReader = PHPExcel_IOFactory::createReader('Excel2007');
    }
    $inputFileType = PHPExcel_IOFactory::identify($file_path);
    $objPHPExcel = $objReader->load($file_path);

    $cell_collection = $objPHPExcel->getActiveSheet()->getCellCollection();
    print_r($cell_collection); die();
}

DISPLAY ERROR 显示错误

显示错误

Don't trust the file extension.... that xls file is not a native Excel BIFF-format file, no matter what extension it might claim. 不要相信文件扩展名。... xls文件不是本机Excel BIFF格式的文件,无论它要求使用什么扩展名。 It's quite common to find .xls used as an extension for csv files, or files containing html markup. 找到.xls作为csv文件或包含html标记的文件的扩展名是很常见的。

Use the IO Factory's identify() method to tell you what reader to use; 使用IO Factory的identify()方法来告诉您使用哪个阅读器; or just simply use the IO Factory load() method to select the correct reader and load the file for you. 或者只是简单地使用IO Factory load()方法来选择正确的阅读器并为您加载文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM