PHP Spreadsheet_Excel_Writer | AddFormat () Function

Syntax:
Workbook::& amp; addFormat ($properties = array())
Parameters:This the function takes one parameter, $properties, which takes the value of an array. To set the different formats, we use their respective functions, such as setBold() for Bold, setBorder() for borders, and many more.Example 1: require_once ' Spreadsheet / Excel / Writer.php' ;  
// Add book $workbook = new Spreadsheet_Excel_Writer();  
// Add format to spreadsheet $format_bold = & amp; $workbook -> addFormat();  
// Set format to bold $format_bold -> setBold();  
// Add worksheet to Sprerdsheet $worksheet = & amp; $workbook -> addWorksheet(); $format_bold -> setBorder (2);  
// Save to sheet $worksheet -> write (0, 0, "Details of GeeksforGeeks Contributors ", $format_bold ); $worksheet -> write (1, 0, "Author" , $format_bold ); $worksheet -> write (1, 1, "User Handle" , $format_bold ); $worksheet -> write (2, 0, "Sarthak" ); $worksheet -> write (2, 1, "sarthak_ishu11" );  
// Submit the .xlsx file in the header $workbook -> send ( 'test.xls' );  
// Close the book object $workbook -> close(); ?>
Output: Example 2: < tbody> require_once 'Spreadsheet / Excel / Writer.php' ;  
// Add book $workbook = new Spreadsheet_Excel_Writer();  
// Add format to spreadsheet $format_border = & amp; $workbook -> addFormat();  
// Add worksheet to Sprerdsheet $worksheet = & amp; $workbook -> addWorksheet();  
// Set and add border width $format_border -> setBorder (2);  
// Set and add color to border $format_border -> setBorderColor ( 'red' );  
// Save to sheet $worksheet -> write (0, 0, "Details of GeeksforGeeks Contributors ", $format_bold ); $worksheet -> write (1, 0, "Author" , $format_border ); $worksheet -> write (1, 1, "User Handle" , $format_border ); $worksheet -> write (2, 0, "Sarthak" ); $worksheet -> write (2, 1, "sarthak_ishu11" );  
// Submit the .xlsx file in the header $workbook -> send ( 'test.xls' );  
// Close the book object $workbook -> close(); ?>
Output: Link : https://pear.php.net/manual /en/package.fileformats.spreadsheet-excel-writer.intro-format.php



Get Solution for free from DataCamp guru