PHPExcel生成Excel无法读取

PHPExcel生成Excel无法读取,第1张

总结 php导出Excel php导入Excel PhpExcel使用说明 PhpExcel使用手册2009/03/06 上午 02:37方法一:特点,简单,省心,

<php

header("Content-type:application/vndms-excel");

header("Content-Disposition:attachment;filename=test_dataxls");

$tx='表头';

echo $tx"\n\n";

//输出内容如下:

echo "姓名""\t";

echo "年龄""\t";

echo "学历""\t";

echo "\n";

echo "张三""\t";

echo "25""\t";

echo "本科""\t";

>

方法二: 引用google code中推荐的小类库(大体同方法一,比较复杂点)

>

<php

header("Content-Type: text/html; charset=utf-8");

require_once 'dbclassphp';

require_once 'Classes/PHPExcelphp';

$objPHPExcel = new PHPExcel();

$filePath = "emailxlsx";

$arr = array();

$temparr = array();

$PHPExcel = new PHPExcel();

$PHPReader = new PHPExcel_Reader_Excel2007();

$PHPExcel = $PHPReader->load($filePath);

$currentSheet = $PHPExcel->getSheet(0);

/取得一共有多少列/

$allColumn = $currentSheet->getHighestColumn();

/取得一共有多少行/

$allRow = $currentSheet->getHighestRow();

echo $allColumn;

echo '<hr>';

echo $allRow;

echo '<hr>';

for($currentRow = 2;$currentRow<=$allRow;$currentRow++){

$temparr['usernum'] = $currentSheet->getCell('A'$currentRow)->getValue();

$temparr['price'] = $currentSheet->getCell('B'$currentRow)->getValue();

$temparr['rongliang'] = $currentSheet->getCell('C'$currentRow)->getValue();

$temparr['fujian'] = $currentSheet->getCell('D'$currentRow)->getValue();

$temparr['gerenwangpan'] = $currentSheet->getCell('E'$currentRow)->getValue();

$temparr['chaodafujian'] = $currentSheet->getCell('F'$currentRow)->getValue();

$temparr['suishenyou'] = $currentSheet->getCell('G'$currentRow)->getValue();

$temparr['chuanzhen'] = $currentSheet->getCell('H'$currentRow)->getValue();

$temparr['qiyewangpan'] = $currentSheet->getCell('I'$currentRow)->getValue();

//$arr[$currentRow-1] = $temparr;

$sql = "INSERT INTO `netease_price` (`usernum`, `price`, `rongliang`, `fujian`, `gerenwangpan`, `chaodafujian`,`suishenyou`, `chuanzhen`, `qiyewangpan`) VALUES (

'"$temparr['usernum']"',

'"$temparr['price']"',

'"$temparr['rongliang']"',

'"$temparr['fujian']"',

'"$temparr['gerenwangpan']"',

'"$temparr['chaodafujian']"',

'"$temparr['suishenyou']"',

'"$temparr['chuanzhen']"',

'"$temparr['qiyewangpan']"'

)";

mysql_query($sql);

/

自动读取

for($currentColumn='A';$currentColumn<=$allColumn;$currentColumn++){

$address = $currentColumn$currentRow;

echo $currentSheet->getCell($address)->getValue()"\t";

}

echo "<br />";

/

}

1下载 phpexcel,

2require_once '/Classes/PHPExcel/IOFactoryphp';$reader =PHPExcel_IOFactory::createReader('Excel5'); // 读取 excel 文件方式  此方法是读取excel2007之前的版本 excel2007 为读取2007以后的版本 也可以\Classes\PHPExcel\Reader 文件夹中的类(为所有读取类,需要哪个填上哪个就行)$PHPExcel = $reader->load("infoxls"); // 文件名称$sheet = $PHPExcel->getSheet(0); // 读取第一个工作表从0读起$highestRow = $sheet->getHighestRow(); // 取得总行数$highestColumn = $sheet->getHighestColumn(); // 取得总列数// 根据自己的数据表的大小修改;3$arr=array(1=>'A',2=>'B',3=>'C',4=>'D',5=>'E',6=>'F',7=>'G',8=>'H',9=>'I',10=>'J',11=>'K',12=>'L',13=>'M',14=>'N',15=>'O',16=>'P',17=>'Q',18=>'R',19=>'S',20=>'T',21=>'U',22=>'V',23=>'W',24=>'X',25=>'Y',26=>'Z');// 每次读取一行,再在行中循环每列的数值for ($row = 5; $row <= $highestRow; $row++) {for ($column = 1; $arr[$column] != 'T'; $column++) {$val = $sheet->getCellByColumnAndRow($column, $row)->getValue();$list[$row][] = $val;}}

print_r($list)。这个方法嘛,可能也不是任何时候都可以的,但确实是很实用的,试试之后你们会有不一样的感受的,真的是这样。

PHPExcel

PHPExcel 是用来 *** 作Office Excel 文档的一个PHP类库,它基于微软的OpenXML标准和PHP语言。可以使用它来读取、写入不同格式的电子表格,如 Excel (BIFF) xls, Excel 2007 (OfficeOpenXML) xlsx, CSV, Libre/OpenOffice Calc ods, Gnumeric, PDF, HTML等等。

PHP读取示例代码

//获取上传的excel临时文件

$path = $_FILES["file"]["tmp_name"];

//将临时文件移动当前目录,可自定义存储位置

 

move_uploaded_file($_FILES["file"]["tmp_name"],$_FILES["file"]["name"]);

//将获取在服务器中的Excel文件,此处为上传文件名

$path = $_FILES["file"]["name"];

//调用readExcel函数返回一个

二维数组

$exceArray = readExcel($path);

 

//创建一个读取

excel函数

function readExcel($path){

        //引入PHPExcel类库

    include 'Classes/PHPExcelphp';            

    include 'Classes/PHPExcel/IOFactoryphp';

 

    $type = 'Excel5';//设置为Excel5代表支持2003或以下版本,

Excel2007代表2007版

    $xlsReader = \PHPExcel_IOFactory::createReader($type);  

    $xlsReader->setReadDataOnly(true);

    $xlsReader->setLoadSheetsOnly(true);

    $Sheets = $xlsReader->load($path);

    //开始读取上传到服务器中的Excel文件,返回一个

二维数组

    $dataArray = $Sheets->getSheet(0)->

toArray();

    return $dataArray;

}

以上就是关于PHPExcel生成Excel无法读取全部的内容,包括:PHPExcel生成Excel无法读取、php读取excel,excel下多个个工作表,该怎么读取、怎么用PHPexcel读取excel数据等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9793936.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-02
下一篇2023-05-02

发表评论

登录后才能评论

评论列表(0条)

    保存