send()函数是PHP中的内置函数| Spreadsheet_Excel_Writer,用于发送带有正确的content-type(application /vnd.ms-excel),文件的缓存控制和文件名的HTTP标头。
用法:
void Spreadsheet_Excel_Writer::send( $filename )
参数:该函数接受单个参数作为$filename,该参数采用要发送到标题的文件名。
返回值:成功时返回TRUE,失败时返回PEAR_ERROR。
范例1:
<?php
// require_once 'Spreadsheet/Excel/Writer.php';
// Add object of class Spreadsheet_Excel_Writer
$workbook = new Spreadsheet_Excel_Writer();
$worksheet =& $workbook->addWorksheet();
// Add a format to the workbook
$format_align =& $workbook->addFormat();
// Set color for the text
$format_align->setColor ('green');
// Set alignment of text to the center of the cell
$format_align->setAlign('center');
// Set alignment of text to the center from the top of the cell
$format_align->setAlign('vcenter');
// Add boldness to the text
$format_align->setBold(1);
// Set size of the text
$format_align->setSize(25);
// Add data to the cell
$worksheet->write(0, 5, 'GeeksforGeeeks!', $format_align);
$worksheet->write(1, 5, 'A Computer Science Portal For Geeks', $format_align);
// Send HTTP headers with the content-type (application/vnd.ms-excel)
$workbook->send('test.xlsx');
// Free the memory
$workbook->close();
?>
输出:
范例2:
<?php
// require_once 'Spreadsheet/Excel/Writer.php';
// Add object of class Spreadsheet_Excel_Writer
$workbook = new Spreadsheet_Excel_Writer();
$worksheet =& $workbook->addWorksheet();
// Add Format to the workbook
$format_align =& $workbook->addFormat();
// Set Color for the text
$format_align->setColor ('white');
// Set Alignment of text to the top of the cell
$format_align->setAlign('top');
// Set Alignment of text to the right of the cell
$format_align->setAlign('right');
// Set background color
$format_align->setBgColor('black');
// Set Pattern to the cell
$format_align->setPattern(1);
// Add Boldness to the text
$format_center->setItalic(1);
// Set Size of the text
$format_align->setSize(20);
// Add data to the cell
$worksheet->write(7, 5, 'Sarthak Prajapati', $format_align);
$worksheet->write(8, 5, 'sarthak_ishu11', $format_align);
$worksheet->write(9, 5, 'Chandigarh', $format_align);
// Send HTTP headers with the content-type (application/vnd.ms-excel)
$workbook->send('test.xlsx');
// Free the memory
$workbook->close();
?>
输出:
相关用法
注:本文由纯净天空筛选整理自sarthak_ishu11大神的英文原创作品 PHP | Spreadsheet_Excel_Writer | send() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。