Friday, September 5, 2025
HomeLanguagesPHP | Spreadsheet_Excel_Writer | setScript() Function

PHP | Spreadsheet_Excel_Writer | setScript() Function

The setScript() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set the script type of the text.

Syntax:

void Format::setScript( $script )

Parameters: This function accepts single parameter $script which contains two value as 1 for superscript and 2 for subscript.

Return Value: This function returns TRUE on success and PEAR_ERROR on failure.

Example 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();
?>


Output:

Example 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();
?>


Output:

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

RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6636 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11865 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7027 POSTS0 COMMENTS
Thapelo Manthata
6703 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS