乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > php如何实现将一个页面以excel<em>格式</em>保存,需要的时候能在...-php导出

php如何实现将一个页面以excel<em>格式</em>保存,需要的时候能在...-php导出

作者:乔山办公网日期:

返回目录:excel表格制作


  1. 这属于php的技术;

  2. php可以用PHPExcel直接导出成excel文件;

代码如下:636f70797a64362

require_once("../lib/excelcreator.class.php");

 $myxls = new ExcelCreator ("中文Excel"); 

 $aTableHead = '

    <Row ss:AutoFitHeight="0">

     <Cell><Data ss:Type="String">Name3</Data></Cell>     <Cell><Data ss:Type="String">Surname3</Data></Cell>    </Row>';

 $aTableBody = '

    <Row ss:AutoFitHeight="0">

     <Cell><Data ss:Type="String">Schwarz3</Data></Cell>     <Cell><Data ss:Type="String">Oliver3</Data></Cell>    </Row>';

 $aTableBottom = '

    <Row ss:AutoFitHeight="0">

     <Cell><Data ss:Type="String">123</Data></Cell>     <Cell><Data ss:Type="String">Peter3</Data></Cell>    </Row>';

 $workSheet = $myxls->createWorkSheet ( "中文sheet1", $aTableHead, $aTableBody, $aTableBottom );

 echo $myxls->createExcel ( $workSheet );



推荐一个简单粗暴的输出办法,虽然excel会报个错,但是不影响浏览

<?php
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=test_data.xls");
//输出内容如下: 
echo   "姓名"."\t"; 
echo   "年龄"."\t"; 
echo   "学历"."\t"; 
echo   "\n"; 
echo   "张三"."\t"; 
echo   "25"."\t"; 
echo   "本科"."\t"; 
?>


但是这单纯是导出,再导入的时候就要复杂很多

推荐phpExcel插件,这个操作我就不在这里细说了,一句半句真说不清楚。


\r\n 和 chr(10) . chr(13) 都是可以的,看起来只增加了一个空格的占位符,这是因为没有设置单元格的自动换行属性,也就是说不允许单元格内容换行,所以换行字符显示为空格。

<?php

$file_name = $img[0]['file'];//路径
$type = $img[0]['type'];
$pro_name = 'name';
$file_name=iconv("utf-8","gb2312",$file_name);
$file=$file_name;
ob_end_clean();//清除缓存e79fa5e98193e59b9ee7ad94337
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");;
header("Content-Transfer-Encoding:binary");
header("Content-Length: ". filesize($file));
header('Content-Disposition: attachment; filename="'.$pro_name.date('YmdHis').'.'.$type);
readfile($file);

相关阅读

  • -thinkphp导出excel,php导出excel表格

  • 乔山办公网excel表格制作
  • 先建一个excel文件,把表头格式调整好,然e69da5e887aa7a686964616f337后另存为html格式,用浏览器打开,查看源代码,复制源代码到后台,然后循环拼tr部分的字符串,然后输出字符串//$filen
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网