如何去除生成时的下载提示
梦宇飞 2009-07-17 05:19:00 <?php
/**
error_reporting(E_ALL);
class clsMsDocGenerator{
var $appName = 'MsDocGenerator';
var $appVersion = '0.2';
var $leftMargin = 2.5;
var $rightMargin = 2.5;
var $topMargin = 3.0;
var $bottomMargin = 3.0;
var $documentBuffer;
var $formatBuffer;
var $cssFile;
var $lastSessionNumber;
var $lastPageNumber;
var $atualPageWidth;
var $tableIsOpen;
var $tableLastRow;
function clsMsDocGenerator($pageOrientation = 'LANDSCAPE', $pageType = 'A4', $cssFile = ''){
$this->documentBuffer = '';
$this->formatBuffer = '';
$this->cssFile = $cssFile;
$this->lastSessionNumber = 0;
$this->lastPageNumber = 0;
$this->atualPageWidth = 0;
$this->tableIsOpen = false;
$this->tableLastRow = 0;
$this->newSession($pageOrientation, $pageType);
$this->newPage();
}//end clsMsDocGenerator()
/**
* public int newSession(const $pageOrientation = 'PORTRAIT', const $pageType = 'A4')
* @param $pageOrientation: The orientation of the pages of the session, 'PORTRAIT' or 'LANDSCAPE'
* @param $pageType: The type of the paper of the pages of the session
* @return int: the number of the new session
*/
function newSession($pageOrientation = 'LANDSCAPE', $pageType = 'A4'){
$this->lastSessionNumber++;
if($this->lastSessionNumber != 1){
$this->endSession();
$this->documentBuffer .= "<br clear=all style='page-break-before:always; mso-break-type:section-break'>\n";
}
$this->atualPageWidth = constant($pageType . '_WIDTH');
$sessionName = "Section" . $this->lastSessionNumber;
$pageSize = constant($pageType . '_' . $pageOrientation . '_SIZE');
$pageMargins = constant($pageType . '_' . $pageOrientation . '_MARGIN');
$this->formatBuffer .= "@page $sessionName\n";
$this->formatBuffer .= " {size: $pageSize;\n";
$this->formatBuffer .= " margin: $pageMargins;\n";
$this->formatBuffer .= " mso-header-margin: 36pt;\n";
$this->formatBuffer .= " mso-footer-margin: 36pt;\n";
$this->formatBuffer .= " mso-paper-source: 0;}\n";
$this->formatBuffer .= "div.$sessionName\n";
$this->formatBuffer .= " {page: $sessionName;}\n\n";
$this->documentBuffer .= "<div class=$sessionName>\n";
return $this->lastSessionNumber;
}//end newSession()
/**
* public int newPage(void)
* @return int: the number of the new page
*/
function newPage(){
$this->lastPageNumber++;
if($this->lastPageNumber != 1)
$this->documentBuffer .= "<br clear=all style='page-break-before:always;'>";
return $this->lastPageNumber;
}//end newPage()
/**
* public void output(void)
*/
function output($filename=''){
$this->endSession();
header('Content-Type: application/msword; charset=gb2312');
if(!$filename){
header("Content-Disposition:filename=$filename");
}
echo '<html xmlns:o="urn:schemas-microsoft-com:office:office"' . "\n";
echo ' xmlns:w="urn:schemas-microsoft-com:office:word"' . "\n";
echo ' xmlns="http://www.w3.org/TR/REC-html40">' . "\n";
$this->outputHeader();
$this->outputBody();
echo '</html>' . "\n";
if($filename):
$file_content= ob_get_contents();
$handle = fopen($filename,"w+");
if(!is_writable($filename))
{
echo '<font color=red>该目录无权限!</font><br />';
return false;
}
if(!fwrite($handle,$file_content))
{
echo "<font color=red>DOC $filename 创建失败!</font><br />";
return false;
}
fclose($handle);
ob_end_clean();
endif;
}
/**
* public void addParagraph(string $content, array $inlineStyle = NULL, string $className = 'normalText')
* @param $content: content of the paragraph
* @param $inlineStyle: array of css block properties
* #param $className: class name of any class defined in extra format file
*/
function addParagraph($content, $inlineStyle = NULL, $className = 'normalText'){
$style = '';
if(is_array($inlineStyle)){
foreach($inlineStyle as $key => $value)
$style .= "$key: $value;";
}
$this->documentBuffer .= "<p class=$className" . ($style != '' ? " style='$style'" : '') . ">".($content == '' ? '<o:p></o:p>' : $content)."</p>\n";
}//end addParagraph()
/**
* public void startTable(array $inlineStyle = NULL, string $className = 'normalTable')
* @param $inlineStyle: array of css table properties, property => value
* @param $className: class name of any class defined in extra format file
*/
function startTable($inlineStyle = NULL, $className = 'normalTable'){
$style = 'border-collapse:collapse;border:none;mso-border-alt:solid windowtext '.BORDER_ALT.'pt;';
$style .= 'mso-yfti-tbllook:480;mso-padding-alt:0cm '.PADDING_ALT_RIGHT.'pt 0cm '.PADDING_ALT_LEFT.'pt;';
$style .= 'mso-border-insideh:'.BORDER_INSIDEH.'pt solid windowtext;mso-border-insidev:'.BORDER_INSIDEV.'pt solid windowtext;';
if(is_array($inlineStyle)){
foreach($inlineStyle as $key => $value)
$style .= "$key: $value;";
}
$this->documentBuffer .= "<table class=$className style='$style' border='0' cellspacing='0' cellpadding='0'>\n";
$this->tableIsOpen = true;
}//end startTable()
?>