PHP | Spreadsheet_Excel_Writer | setHAlign() Function
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 // 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 // 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:

Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- D3.js | d3.lab() Function
- PHP | max( ) Function
- D3.js | d3.rgb() Function
- D3.js | d3.map.set() Function
- PHP | min( ) Function
- PHP | Ds\Set contains() Function
- PHP | Ds\Set add() Function
- PHP | key() Function
- p5.js | cos() function
- CSS | rgb() Function
- p5.js | red() function
- PHP | Ds\Set first() Function
- D3.js | d3.hcl() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



