Certain vibrant sites use PHP language to make particular content. One can use it to access user input, SQL databases and files on server. PHP can be used to make an excel spreadsheet either on web browser or store it to server. Special PHP extension package Pear has a easy class particularly for creating excel files.
• Open PHP file using word pad and find the code to process XLS file.
• Add 'Writer.php' file of Pear Spreadsheet or Excel extension at the start of the file or particularly where processing the XLS file. Enter following code:
require_once 'Spreadsheet/Excel/Writer.php';
• Make a new object. Entrée following code:
$workbook = new Spreadsheet_Excel_Writer();
File name can be added in object's constructor to store file to server. Here file is "test.xls."
Enter following code:
$workbook = new Spreadsheet_Excel_Writer('test.xls');
• To view spreadsheet in web browser, http headers must be set. Filename requires to be passed to send function. It is "test.xls" in this case. Enter following code:
$workbook->send('test.xls');
• Make a worksheet in workbook via addWorksheet() function.
Enter following code:
$worksheet =& $workbook->addWorksheet('Worksheet1');
'Worksheet1' is name of worksheet.
• Content can be written to file form write() utility. It is performed on worksheet, and not on the workbook object.
Enter following code:
$worksheet->write('row', 'col', 'content');
'row' and 'col' is your integers. 'content' is your string. The line of code should be repeated for every cell that have content.
• Close file and enter blow given code:
$workbook->close()



Reply With Quote
Copyright Techfuels
Bookmarks