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 accepts single parameter as $filename which takes the name of the file to be send to the headers.

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

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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_align =& $workbook->addFormat();
  
// Set color for the text 
$format_align->setColor ('green');
  
// Set alignment of text to the center of the cell 
$format_align->setAlign('center');
  
// Set alignment of text to the center from the top of the cell 
$format_align->setAlign('vcenter');
  
// Add boldness to the text 
$format_align->setBold(1);
  
// Set size of the text
$format_align->setSize(25);
  
// Add data to the cell
$worksheet->write(0, 5, 'GeeksforGeeeks!', $format_align);
$worksheet->write(1, 5, 'A Computer Science Portal For Geeks', $format_align);
  
// Send HTTP headers with the content-type (application/vnd.ms-excel)
$workbook->send('test.xlsx');
  
// Free the memory
$workbook->close();
?>

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// require_once 'Spreadsheet/Excel/Writer.php';
  
// Add object of class Spreadsheet_Excel_Writer
$workbook = new Spreadsheet_Excel_Writer();
$worksheet =& $workbook->addWorksheet();
  
// Add Format to the workbook
$format_align =& $workbook->addFormat();
  
// Set Color for the text 
$format_align->setColor ('white');
  
// Set Alignment of text to the top of the cell 
$format_align->setAlign('top');
  
// Set Alignment of text to the right of the cell 
$format_align->setAlign('right');
  
// Set background color
$format_align->setBgColor('black');
  
// Set Pattern to the cell
$format_align->setPattern(1);
  
// Add Boldness to the text 
$format_center->setItalic(1);
  
// Set Size of the text
$format_align->setSize(20);
  
// Add data to the cell
$worksheet->write(7, 5, 'Sarthak Prajapati', $format_align);
$worksheet->write(8, 5, 'sarthak_ishu11', $format_align);
$worksheet->write(9, 5, 'Chandigarh', $format_align);
  
// Send HTTP headers with the content-type (application/vnd.ms-excel)
$workbook->send('test.xlsx');
  
// Free the memory
$workbook->close();
?>

chevron_right


Output:

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.