PHP |电子表格_Excel_Writer | setVAlign()函数
setVAlign()函数是 Spreadsheet_Excel_Writer 中的一个内置函数,用于设置电子表格的单元格对齐方式。这是setAlign()函数的替代方法。
句法:
void Format::setVAlign( $location )
参数:此函数接受单个参数$location ,该参数用于设置要放置文本的位置,例如 'top'、'vcenter'、'bottom'、'vjustify'、'vequal_space'。\
返回值:此函数在成功时返回 TRUE,在失败时返回 PEAR_ERROR。
示例 1:
PHP
addWorksheet();
// Add format to the workbook
$format_center =& $workbook->addFormat();
// Set color for the text
$format_center->setColor ('green');
// Set alignment of text to the center of the cell
$format_center->setVAlign('vcenter');
// Add boldness to the text
$format_center->setBold(1);
// Set size of the text
$format_center->setSize(25);
// Add data to the cell
$worksheet->write(0, 5, 'GeeksforGeeeks!', $format_center);
$worksheet->write(1, 5, 'A Computer Science Portal For Geeks', $format_center);
// Send file to the browser
$workbook->send('test.xlsx');
// Free the memory
$workbook->close();
?>
PHP
addWorksheet();
// Add Format to the workbook
$format_center =& $workbook->addFormat();
// Set Color for the text
$format_center->setColor ('white');
// Set Alignment of text to the top of the cell
$format_center->setVAlign('top');
// Set background color
$format_center->setBgColor('black');
// Set Pattern to the cell
$format_center->setPattern(1);
// Add Boldness to the text
$format_center->setItalic(1);
// Set Size of the text
$format_center->setSize(20);
// Add data to the cell
$worksheet->write(7, 5, 'Sarthak Prajapati', $format_center);
$worksheet->write(8, 5, 'sarthak_ishu11', $format_center);
$worksheet->write(9, 5, 'Chandigarh', $format_center);
// Send file to the browser
$workbook->send('test.xlsx');
// Free the memory
$workbook->close();
?>
输出:
示例 2:
PHP
addWorksheet();
// Add Format to the workbook
$format_center =& $workbook->addFormat();
// Set Color for the text
$format_center->setColor ('white');
// Set Alignment of text to the top of the cell
$format_center->setVAlign('top');
// Set background color
$format_center->setBgColor('black');
// Set Pattern to the cell
$format_center->setPattern(1);
// Add Boldness to the text
$format_center->setItalic(1);
// Set Size of the text
$format_center->setSize(20);
// Add data to the cell
$worksheet->write(7, 5, 'Sarthak Prajapati', $format_center);
$worksheet->write(8, 5, 'sarthak_ishu11', $format_center);
$worksheet->write(9, 5, 'Chandigarh', $format_center);
// Send file to the browser
$workbook->send('test.xlsx');
// Free the memory
$workbook->close();
?>
输出:
参考: https://pear。 PHP.net/manual/en/package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-format.setvalign。 PHP