用php如何写导出excel代码?
以下文件有误,该怎么改呢?为什么第一行的内容都挤到第一个格子里了<?php$filename="biaoge".date('Y-m-d').".csv";//先定义一个e...
以下文件有误,该怎么改呢?为什么第一行的内容都挤到第一个格子里了
<?php $filename="biaoge".date('Y-m-d').".csv";//先定义一个excel文件header("Content-type:application/vnd.ms-excel");header("Content-Disposition:attachment;filename=$filename");header("Pragma: no-cache");header("Expires: 0");//输出内容如下: echo "姓名"."\t"; echo "年龄"."\t"; echo "学历"."\n"; echo "张三"."\t"; echo "25"."\t"; echo "本科"."\n"; echo "张三"."\t"; echo "25"."\t"; echo "本科"."\n"; echo "张三"."\t"; echo "25"."\t"; echo "本科"."\n"; echo "张三"."\t"; echo "25"."\t"; echo "本科"."\n"; ?> 展开
<?php $filename="biaoge".date('Y-m-d').".csv";//先定义一个excel文件header("Content-type:application/vnd.ms-excel");header("Content-Disposition:attachment;filename=$filename");header("Pragma: no-cache");header("Expires: 0");//输出内容如下: echo "姓名"."\t"; echo "年龄"."\t"; echo "学历"."\n"; echo "张三"."\t"; echo "25"."\t"; echo "本科"."\n"; echo "张三"."\t"; echo "25"."\t"; echo "本科"."\n"; echo "张三"."\t"; echo "25"."\t"; echo "本科"."\n"; echo "张三"."\t"; echo "25"."\t"; echo "本科"."\n"; ?> 展开
1个回答
展开全部
用PHPExcel,PHPExcel是相当强大的 MS Office Excel 文档生成类库。
你上它的官/网把程序包下/载下来,里面有 PHPExcel 的程序、还有30个实例程序和三个文档。
看一下其中的开发文档你就会用了。
读取(这段在开发文档里有的,在13页):
require_once '../Classes/PHPExcel/IOFactory.php';
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load("test.xlsx");
$objWorksheet = $objPHPExcel->getActiveSheet();
echo '<table>' . "\n";
foreach ($objWorksheet->getRowIterator() as $row) {
echo '<tr>' . "\n";
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell) {
echo '<td>' . $cell->getValue() . '</td>' . "\n";
}
echo '</tr>' . "\n";
}
echo '</table>' . "\n";
?>
你上它的官/网把程序包下/载下来,里面有 PHPExcel 的程序、还有30个实例程序和三个文档。
看一下其中的开发文档你就会用了。
读取(这段在开发文档里有的,在13页):
require_once '../Classes/PHPExcel/IOFactory.php';
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load("test.xlsx");
$objWorksheet = $objPHPExcel->getActiveSheet();
echo '<table>' . "\n";
foreach ($objWorksheet->getRowIterator() as $row) {
echo '<tr>' . "\n";
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell) {
echo '<td>' . $cell->getValue() . '</td>' . "\n";
}
echo '</tr>' . "\n";
}
echo '</table>' . "\n";
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询