用写入文本的方法,字段数据间用逗号,可以生成csv格式的excel文件
-----------------------------------
以下广告:
本人搞了个虚拟主机,支持PHP,MYSQL,ASP,ACCESS,MSSQL
http://www.51vh.cn
希望大家多支持哈
-----------------------------------
以下广告:
本人搞了个虚拟主机,支持PHP,MYSQL,ASP,ACCESS,MSSQL
http://www.51vh.cn
希望大家多支持哈
<?php
$outStr=ob_get_contents();
ob_end_clean();
header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".strlen($outStr));
Header("Content-Disposition: attachment; filename=test.Xls");
// 输出文件内容
echo $outStr ;
?>
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
?>
//改动相应文件头就可以输出.doc .xls等文件格式了
Excel 类 V1.1
By Monkey
-----------------------------------------------函数说明
读取Excel文件
function Read_Excel_File($ExcelFile,$Result)$ExcelFile Excel文件名
$Result 返回的结果
函数返回值 正常返回0,否则返回错误信息返回的值数组
$result[sheet名][行][列] 的值为相应Excel Cell的值
建立Excel文件
function Create_Excel_File($ExcelFile,$Data) $ExcelFile Excel文件名
$Data Excel表格数据
请把函数写在PHP脚本的开头例1:
<?
require "excel_class.php";Read_Excel_File("Book1.xls",$return);for ($i=0;$i<count($return[Sheet1]);$i++)
{
for ($j=0;$j<count($return[Sheet1][$i]);$j++)
{
echo $return[Sheet1][$i][$j]."|";
}
echo "<br>";
}
?>例2:
<?
require "excel_class.php";Read_Excel_File("Book1.xls",$return);
Create_Excel_File("ddd.xls",$return[Sheet1]);
?>类文件:excel_class.zip
下载地址:http://www.cnblogs.com/Files/coolstr/excel_class.zip http://coolstr.cnblogs.com/archive/2005/11/18/279829.html