例子//首先一步
$excel = new COM("Excel.sheet") or Die ("Did not instantiate Excel");// 建立EXCEL的COM对象
//打开一个工作簿
$pathin = "工作簿目录";
$workbook = "工作簿名称";
$wkb = $excel->application->Workbooks->Open($pathin.$workbook) or Die ("Did not open $pathin $workbook");
//建新工作簿
$wkb = $excel->application->Workbooks->Add or Die("Unable to add a new work book");
//打开工作表
$sheet_name = "sheet1"
$sheet = $wkb->Worksheets($sheet_name) or Die("Unable to active $sheet_name");
//读一个单元格
$readcell = $sheet->cells($row,$column); //行和列直接用十进制数表示
$readcell->activate;
$result = $selcell->value; //读出单元格值
$excel = new COM("Excel.sheet") or Die ("Did not instantiate Excel");// 建立EXCEL的COM对象
//打开一个工作簿
$pathin = "工作簿目录";
$workbook = "工作簿名称";
$wkb = $excel->application->Workbooks->Open($pathin.$workbook) or Die ("Did not open $pathin $workbook");
//建新工作簿
$wkb = $excel->application->Workbooks->Add or Die("Unable to add a new work book");
//打开工作表
$sheet_name = "sheet1"
$sheet = $wkb->Worksheets($sheet_name) or Die("Unable to active $sheet_name");
//读一个单元格
$readcell = $sheet->cells($row,$column); //行和列直接用十进制数表示
$readcell->activate;
$result = $selcell->value; //读出单元格值
适合固定字段
准备好几个Excel模版,放在某个角落,要用的时候Copy一个过来,然后用OpenRowSet批量插入。然后就可以下载了,需要主意的是Excel六万多行就顶不住了。方案二:
适合非固定字段
百度一下Response.ContentType="application/vnd.ms-excel"
用HTML表格装填好数据输出时为Excel。方案三:
适合非固定字段
由方案一想出来的。
依然是模版Copy,不过这次模版是空的,第一次Copy模版过来,将第一行字段写入,然后再批量插数据进去。这种方法非常简单,不用考虑建Excel,直接Copy就可以了,安全上顶多注意一下FSO。
去这看看,去否有你需要的东东
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");
echo "编号\t用户ID\t用户名\t口令\t性别\n";
$result = mysql_query(...);
while($r = mysql_fetch_array($result))
{
echo $r[编号]."\t".$r[用户ID]."\t".$r[用户名]."\t".$r[口令]."\t".$r[性别]."\n";
}
?>
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");
echo "编号\t用户ID\t用户名\t口令\t性别\n";
$result = mysql_query(...);
while($r = mysql_fetch_array($result))
{
echo $r[编号]."\t".$r[用户ID]."\t".$r[用户名]."\t".$r[口令]."\t".$r[性别]."\n";
}
?>
--------------------------这个就可以了
excel 问题,高手解决,help!
$excel = new COM("Excel.sheet") or Die ("Did not instantiate Excel");// 建立EXCEL的COM对象错误信息:
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `Excel.sheet': 拒绝访问。 ' in E:\iis\libraire\excel\excel.php:40 Stack trace: #0 E:\iis\libraire\excel\excel.php(40): com->com('Excel.sheet') #1 E:\iis\libraire\excel\testclass.php(28): Excel->excel() #2 {main} thrown in E:\iis\libraire\excel\excel.php on line 40
我用的IIS(6.0)+windows 2003 server
我的QQ:531515035
email :jiehan126.com
谢谢指点