小弟是出学者,刚刚开通博客,上来请教个问题。我写了个这个类,可是生成的word 文档为什么不能直接打开,每次打开都有提示需要转换器才可以正常显示文件,但是点否也可以打开,请各位高手指点一下。
小弟在此谢过了!
<?php
/**
* educe class for word&excel&txt
* this class is used in all scripts
* do NOT fiddle unless you know what you are doing
*
* Copyright(c) 2007 by qiqi. All rights reserved
*
* To contact the author write to {@link qqi_77@sina.com}
*
* @author 齐琦
*
*/
class Educe
{
/**
* description : document educe
*
* @param string $fileName
* @param array $titleName
* @param array $dataName
* @param string $fileMark 0:excel 1:txt 2:word
*/
function documentEduce($fileMark,$fileName,$titleName,$dataName)
{
header("Content-Type: application/vnd.ms-excel");
switch ($fileMark)
{
case 0:
echo header("Content-Disposition: attachment; filename=$fileName.xls");
break;
case 1:
echo header("Content-Disposition: attachment; filename=$fileName.txt");
break;
case 2:
echo header("Content-Disposition: attachment; filename=$fileName.doc");
break;
}
header("Pragma: no-cache");
header("Expires: 0");
$num=count($titleName);
for ($i=0;$i<$num;$i++)
{
echo "".$titleName[$i].""."/t";
}
if ($i==$num)
{
echo "".$titleName[$i].""."/t/n";
}
for ($y=0;$y<$num;$y++)
{
echo "".$dataName[$y].""."/t";
}
if ($y==$num)
{
echo "".$dataName[$y].""."/t/n";
}
}
}
?>