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


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


setScript()函數是PHP中的內置函數| Spreadsheet_Excel_Writer,用於設置文本的腳本類型。

用法:

void Format::setScript( $script )

參數:該函數接受單個參數$script,該參數包含兩個值,上標為1,下標為2。


返回值:成功時返回TRUE,失敗時返回PEAR_ERROR。

範例1:

<?php 
  
require_once 'Spreadsheet/Excel/Writer.php'; 
  
// Create Spreadsheet_Excel_Writer object 
$workbook = new Spreadsheet_Excel_Writer(); 
$worksheet =& $workbook->addWorksheet(); 
  
// Creating the formats 
$format_superscript =& $workbook->addFormat(); 
$format_superscript->setScript(1); 
  
// Add Worksheet 
$worksheet =& $workbook->addWorksheet(); 
  
// Add superscript Text to cell 
$worksheet->write(0, 0, "x2", $format_superscript); 
  
$workbook->send('test.xls'); 
$workbook->close(); 
?>

輸出:

範例2:

<?php 
  
require_once 'Spreadsheet/Excel/Writer.php'; 
  
// Create Spreadsheet_Excel_Writer object 
$workbook = new Spreadsheet_Excel_Writer(); 
$worksheet =& $workbook->addWorksheet(); 
  
// Creating the formats 
$format_superscript =& $workbook->addFormat(); 
$format_subscript->setScript(2); 
  
// Add Worksheet 
$worksheet =& $workbook->addWorksheet(); 
  
// Add subscript text to cell 
$worksheet->write(0, 0, "Mg2SO4", $format_subscript); 
  
$workbook->send('test.xls'); 
$workbook->close(); 
?>

輸出:

參考: https://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-format.setscript.php



相關用法


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