I have tried the following program for writing the contents into Spreadsheet. I downloaded the Spreadsheet_Excel_Writer package also.
<?php
ini_set('include_path','/xhome/rekha/public_html/PHP_FORUM/PHP/open_office/Spreadsheet_Excel_Writer-0.9.2/Spreadsheet/Excel/Writer.php');
$workbook = new Spreadsheet_Excel_Writer();
$workbook->send('grades.xls');
$format_bold =& $workbook->addFormat();
$format_bold->setBold();
$worksheet =& $workbook->addWorksheet();
$worksheet->write(0, 0, "NAME", $format_bold);
$worksheet->write(0, 1, "MARK1", $format_bold);
$worksheet->write(0, 2, "MARK2", $format_bold);
$worksheet->write(0, 3, "MARK3", $format_bold);
$worksheet->write(0, 4, "MARK4", $format_bold);
$worksheet->write(0, 5, "MARK5", $format_bold);
$worksheet->write(0, 6, "TOTAL", $format_bold);
$workbook->close();
?>
But while running this php program I got the following Fatal error.
Fatal error: Class 'Spreadsheet_Excel_Writer' not found in /xhome/rekha/public_html/PHP_FORUM/PHP/open_office/spread.php on line 4
Call Stack
# Time Memory Function Location
1 0.0003 59868 {main}( ) ../spread.php:0
I tried to solve this error.But I can't. Please can anyone help me to solve this error.
you'll have to include the library, otherwise PHP won't recognize the Spreadsheet_Excel_Writer class.
And you'll also have to specify a path for the include_path, instead of a file. And usually it's best practice to append your new path, to the existing path. So you'll first have to retrieve the current include_path and append your new path to that one.
This should work:
<?php
ini_set('include_path',ini_get('include_path').':/xhome/rekha/public_html/PHP_FORUM/PHP/open_office/Spreadsheet_Excel_Writer-0.9.2/');
require_once 'Spreadsheet/Excel/Writer.php';
$workbook = new Spreadsheet_Excel_Writer();
$workbook->send('grades.xls');
$format_bold =& $workbook->addFormat();
$format_bold->setBold();
$worksheet =& $workbook->addWorksheet();
$worksheet->write(0, 0, "NAME", $format_bold);
$worksheet->write(0, 1, "MARK1", $format_bold);
$worksheet->write(0, 2, "MARK2", $format_bold);
$worksheet->write(0, 3, "MARK3", $format_bold);
$worksheet->write(0, 4, "MARK4", $format_bold);
$worksheet->write(0, 5, "MARK5", $format_bold);
$worksheet->write(0, 6, "TOTAL", $format_bold);
$workbook->close();
?>
And it seems that you've downloaded the source of the Spreadsheet_Excel_Writer and installed it manually in your project.
I suggest you use the PEAR installer, included with PHP to install this package. The PEAR libraries are usually included by default through he default include_path. So you should only need the 'require_once' statement. no need to change the include_path.
just enter on the command line:
pear install Spreadsheet_Excel_Writer-beta
Once you've installed the library successfully using PEAR, you can remove the ini_set line from your script.
Hope this solves your problem.
Further informations regarding PEAR: http://pear.php.net/manual/en/guide.users.commandline.cli.php
我之前使用过这个库,但更好的是PHPExcel ,它支持更新的XLS和XSLX文件格式。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.