doulongti5932 2018-02-13 08:16
浏览 358

PHPExcel_Reader_Exception被识别为OLE文件

Please help me reading an excel file upload attached. When I attach an XLS format, my PHPExcel reader is not working. Do you think where am I missing?

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

//USAGE: $("#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

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

displayerror

  • 写回答

1条回答 默认 最新

  • dongying7847 2018-02-13 09:00
    关注

    Don't trust the file extension.... that xls file is not a native Excel BIFF-format file, no matter what extension it might claim. It's quite common to find .xls used as an extension for csv files, or files containing html markup.

    Use the IO Factory's identify() method to tell you what reader to use; or just simply use the IO Factory load() method to select the correct reader and load the file for you.

    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来