一切尽在:
$word->Selection->FontSelection.Font.Size=20;
Selection.Font.Name = "黑体";
Selection->Font->Bold = True;
$word->Selection->FontSelection.Font.Size=20;
Selection.Font.Name = "黑体";
Selection->Font->Bold = True;
1、利用php生成一个html文件,这个html就是你要的带表格或指定字体(黑体、20号)和格式的html文件。
2、然后用
header("Content-type: application/msword");
header("Content-disposition: attachment; filename=要成生的word文件名称");
header("Pragma: no-cache");
header("Expires: 0");
readfile('生成的html文件名称');这样就可以生成一个带格式的word文件!
{
var $Align;
var $Width;
var $Height;
var $Style_ClassName;
var $BgColor;
var $Spacing;
var $Padding;
var $Table_Id;
/*
+------------------------------------------------------------------------------
| 功能:表格初始化属性
+------------------------------------------------------------------------------
*/
function Table()
{ $this->Table_Id = '';
$this->Align = 'center';
$this->Width = '100%';
$this->Height = '';
$this->Style_ClassName = 'black91';
$this->BgColor = '#666666';
$this->Spacing = 1;
$this->Padding = 1;
}//end Table
/*
+------------------------------------------------------------------------------
| 功能:设置表格属性
+------------------------------------------------------------------------------
*/
function Set_Table($Id,$Is_Have_Border,$Align,$Width,$Height,$Css_Name,$Border_Color,$Bg_Color,$Spacing,$Padding)
{
if ($Is_Have_Border)
$this->Border=1;
else
$this->Border=0;
$this->Table_Id = $Id;
$this->Align = $Align;
$this->Width = $Width;
$this->Height = $Height;
$this->Style_ClassName = $Css_Name;
$this->BgColor = $Bg_Color;
$this->Spacing = $Spacing;
$this->Padding = $Padding;
}//end Set_Table
/*
+------------------------------------------------------------------------------
| 功能:创建一个表格头
+------------------------------------------------------------------------------
*/
function Create_Table_Head($Caption,$Width,$Height,$Css_Name,$Bg_Color,$Align='center',$Valign='middle')
{
$this->TableHead_Td_Caption[] = $Caption;
$this->TableHead_Td_Align[] = $Align;
$this->TableHead_Td_Valign[] = $Valign;
$this->TableHead_Td_Width[] = $Width;
$this->TableHead_Td_Height[] = $Height;
$this->TableHead_Td_Style_ClassName[] = $Css_Name;
$this->TableHead_Td_Bg_Color[] = $Bg_Color;
}//end Create_Table_Head /*
+------------------------------------------------------------------------------
| 功能:创建一个表格行tr
+------------------------------------------------------------------------------
*/
function Create_Table_Tr($Id='',$Css_Name='',$Bg_Color='',$Height='',$Event_List='',$Align='center',$Valign='middle')
{
$this->TableTr_Id[] = $Id;
$this->TableTr_Align[] = $Align;
$this->TableTr_Valign[] = $Valign;
$this->TableTr_Style_ClassName[] = $Css_Name;
$this->TableTr_Bg_Color[] = $Bg_Color;
$this->TableTr_Height[] = $Height;
$this->TableTr_Event_List[] = $Event_List;
}//end Create_Table_Tr
/*
+------------------------------------------------------------------------------
| 功能:创建一个表格小格td
+------------------------------------------------------------------------------
*/
function Create_Table_Td($row,$Caption='',$Width='',$Height='',$Css_Name='',$Bg_Color='',$Event_List='',$Align='left',$Valign='middle',$ColSpan=1)
{
$this->TableTd_Caption[$row][] = $Caption;
$this->TableTd_Align[$row][] = $Align;
$this->TableTd_Valign[$row][] = $Valign;
$this->TableTd_Width[$row][] = $Width;
$this->TableTd_Height[$row][] = $Height;
$this->TableTd_Style_ClassName[$row][] = $Css_Name;
$this->TableTd_Bg_Color[$row][] = $Bg_Color;
$this->TableTd_Event_List[$row][] = $Event_List;
$this->TableTd_ColSpan[$row][] = $ColSpan;
}//end Create_Table_Td
soryy,我贴的那段 class table贴错地方了,不是贴这里的
=====================================================
生成带表格的word文件做法:
1、利用php生成一个带表格的html文件,这个html就是你要的带表格或指定字体(黑体、20号)和格式的html文件。
2、然后用
header("Content-type: application/msword");
header("Content-disposition: attachment; filename=要成生的word文件名称");
header("Pragma: no-cache");
header("Expires: 0");
readfile('生成的html文件名称');系统读入你生成的那个html文件,输出的时候以word形式输出,这样就可以输出一个带格式的word文件!如果你想生成一个word文件,可以用:$fp = fopen('word文件名','w');
$Word_Contents = readfile('生成的html文件名称');
fputs($fp,$Word_Contents);
fclose($fp);将html文件的源代码内容写入word文件即可,不过对打开这个word文件的office版本有限制,我试过officeXP行得通,office2000估计也行,office97不行!