當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP Spreadsheet_Excel_Writer setAlign()用法及代碼示例


setAlign()函數是PHP中的內置函數| Spreadsheet_Excel_Writer用於設置電子表格的單元格對齊。

用法:

void Format::setAlign( $location )

參數:此函數接受采用位置的單個參數$location,例如“水平對齊”(左,中,右,填充,對齊,合並,equal_space)和“垂直對齊”(頂部,vcenter,底部,對齊,vequal_space)。要實現水平和垂直對齊方式的組合,請兩次調用此方法。


返回值:成功時返回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 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 file to the browser 
$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 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.setalign.php



相關用法


注:本文由純淨天空篩選整理自sarthak_ishu11大神的英文原創作品 PHP | Spreadsheet_Excel_Writer | setAlign() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。