📌  相关文章
📜  PHP |电子表格_Excel_Writer | addWorksheet()函数

📅  最后修改于: 2022-05-13 01:56:46.890000             🧑  作者: Mango

PHP |电子表格_Excel_Writer | addWorksheet()函数

addWorksheet()函数是PHP中的内置函数| Spreadsheet_Excel_Writer 用于将新工作表添加到 Excel 工作簿。

句法:

Workbook::&addWorksheet( $name='' )

参数:此函数接受单个参数$字符串作为不能大于 31 个字符的工作表名称。

返回值:此函数在成功时返回对工作表对象的引用,在失败时返回 PEAR_ERROR。

示例 1:

PHP
addFormat();
 
// Set Bold Format
$format_bold->setBold();
 
// Add Worksheet to Spreadsheet
$worksheet =& $workbook->addWorksheet();
 
$format_bold->setBorder(2);
 
// Write to Worksheet
$worksheet->write(0, 0, "Details of GeeksforGeeks
                      Contributors", $format_bold);
$worksheet->write(1, 0, "Author", $format_bold);
$worksheet->write(1, 1, "User Handle", $format_bold);
$worksheet->write(2, 0, "Sarthak");
$worksheet->write(2, 1, "sarthak_ishu11");
 
// Send .xlsx file to header
$workbook->send('test.xls');
 
// Close Workbook Object
$workbook->close();
?>


PHP
addFormat();
 
// Add Worksheet to Spreadsheet
$worksheet =& $workbook->addWorksheet();
 
// Set and Add Border Width
$format_border->setBorder(2);
 
// Set and Add Color to Border
$format_border->setBorderColor('red');
 
// Write to Worksheet
$worksheet->write(0, 0, "Details of GeeksforGeeks
                     Contributors", $format_bold);
$worksheet->write(1, 0, "Author", $format_border);
$worksheet->write(1, 1, "User Handle", $format_border);
$worksheet->write(2, 0, "Sarthak");
$worksheet->write(2, 1, "sarthak_ishu11");
 
// Send .xlsx file to header
$workbook->send('test.xls');
 
// Close Workbook Object
$workbook->close();
?>


输出:

示例 2:

PHP

addFormat();
 
// Add Worksheet to Spreadsheet
$worksheet =& $workbook->addWorksheet();
 
// Set and Add Border Width
$format_border->setBorder(2);
 
// Set and Add Color to Border
$format_border->setBorderColor('red');
 
// Write to Worksheet
$worksheet->write(0, 0, "Details of GeeksforGeeks
                     Contributors", $format_bold);
$worksheet->write(1, 0, "Author", $format_border);
$worksheet->write(1, 1, "User Handle", $format_border);
$worksheet->write(2, 0, "Sarthak");
$worksheet->write(2, 1, "sarthak_ishu11");
 
// Send .xlsx file to header
$workbook->send('test.xls');
 
// Close Workbook Object
$workbook->close();
?>

输出:

参考: https://pear。 PHP.net/manual/en/package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-workbook.addworksheet。 PHP