PHP | Spreadsheet_Excel_Writer | setHAlign() Function Last Updated : 21 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The setHAlign() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set cell alignment of the spreadsheet. Syntax: void Format::setHAlign( $location ) Parameters: This function accepts single parameter as $location which takes the position, at which text is to be placed as 'left', 'center', 'right', 'fill', 'justify', 'merge', 'equal_space'. Return Value: This function returns TRUE on success and PEAR_ERROR on failure. Example 1: php <?php // require_once 'Spreadsheet/Excel/Writer.php'; // Add object of class Spreadsheet_Excel_Writer $workbook = new Spreadsheet_Excel_Writer(); $worksheet =& $workbook->addWorksheet(); // Add a 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->setHAlign('center'); // 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(); ?> Output: Example 2: php <?php // require_once 'Spreadsheet/Excel/Writer.php'; // Add object of class Spreadsheet_Excel_Writer $workbook = new Spreadsheet_Excel_Writer(); $worksheet =& $workbook->addWorksheet(); // Add a Format to the workbook $format_center =& $workbook->addFormat(); // Set Color for the text $format_center->setColor ('white'); // Set Alignment of text to the right of the cell $format_center->setHAlign('right'); // 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(); ?> Output: Reference: https://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-format.sethalign.php Comment More infoAdvertise with us Next Article PHP | Spreadsheet_Excel_Writer | setHAlign() Function sarthak_ishu11 Follow Improve Article Tags : Technical Scripter Web Technologies PHP PHP-function PHP-Spreadsheet_Excel_Writer +1 More Similar Reads PHP | Spreadsheet_Excel_Writer | setAlign() Function The setAlign() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set cell alignment of the spreadsheet. Syntax: void Format::setAlign( $location ) Parameters: This function accepts single parameter $location which takes the position, as Horizontal Alignments (left, c 2 min read PHP | Spreadsheet_Excel_Writer | setVAlign() Function The setVAlign() function is an inbuilt function in Spreadsheet_Excel_Writer which is used to set cell alignment of the spreadsheet. This is an alternative to the setAlign() function. Syntax:Â void Format::setVAlign( $location ) Parameters: This function accepts single parameter $location which is us 2 min read PHP | Spreadsheet_Excel_Writer | setItalic() Function The setItalic() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set the font style as italic. Syntax:Â void Format::setItalic() Parameters: This function does not accept any parameter. Return Value: This function returns TRUE on success and PEAR_ERROR on failure. E 1 min read PHP | Spreadsheet_Excel_Writer | setOutLine() Function The setOutLine() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set outlining for a font. Syntax:Â void Format::setOutLine() Parameters: This function does not accept any parameter. Return Value: This function returns TRUE on success and PEAR_ERROR on failure. Exa 1 min read PHP | Spreadsheet_Excel_Writer | send() Function The send() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to send HTTP headers with the correct content-type (application/vnd.ms-excel), cache control and filename for the file. Syntax: void Spreadsheet_Excel_Writer::send( $filename ) Parameters: This function accept 2 min read PHP | Spreadsheet_Excel_Writer | setShadow() Function The setShadow() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set the font as a shadow. Syntax:Â void Format::setShadow() Parameters: This function does not accept any parameter. Return Value: This function returns TRUE on success and PEAR_ERROR on failure. Examp 2 min read PHP | Spreadsheet_Excel_Writer | setUnderline() Function The setUnderline() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set the underline of the text. Syntax:Â void Format::setUnderline( $underline ) Parameters: This function accepts single parameter $underline. The possible value of this parameter is 1 for single li 2 min read PHP | Spreadsheet_Excel_Writer | setBold() Function The setBold() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set the boldness of the text. Syntax:Â void Format::setBold( $weight = 1 ) Parameters: This function accepts a single parameter $weight which is used to set the weight of the text. The default value of t 2 min read PHP | Spreadsheet_Excel_Writer | setColor() Function The setColor() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set the color of a cell content. Syntax: void Format::setColor( mixed $color ) Parameters: This function accepts single parameter as $color which takes value of color as string like 'green' or value fro 2 min read 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. 1 min read Like