Asked  7 Months ago    Answers:  5   Viewed   118 times

I'm having a difficult time getting PHPExcel to work. In the class HTML.php, where the object is declared, $objPHPExcel = new PHPExcel(); (on line 153), it can't seem to load PHPExcel. The entire error is:

Fatal error: Class 'PHPExcel' not found in /home/main/public_html/home/IEW/PHPExcel/Reader/HTML.php on line 153

The PHPExcel Library is located at /home/main/public_html/home/IEW/PHPExcel/

(My host is GoDaddy with cpanel is that makes any sort of difference).

Thanks!

 Answers

77

For PHPExcel to work properly you have to include PHPExcel.php like this:

include_once('PHPExcel/PHPExcel.php');

Also, in some cases reinstalling whole package can help.

Saturday, May 29, 2021
 
Kevin_Kinsey
answered 7 Months ago
34

I've since fixed this by reinstalling the whole package. Not at all sure what individual file or configuration would have caused the error, might have been to do with previous person to use that code. But anyway, fixed now.

Saturday, May 29, 2021
 
Jauco
answered 7 Months ago
40

'&B' will only set bold text for printed page headers and footers, as described in the section of the documentation entitled Setting the print header and footer of a worksheet

Formatting the content of a cell is described in the section of the documentation entitled Formatting cells, something like:

$objPHPExcel->getActiveSheet()->getCell('A1')->setValue('bold');
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);

or (if your content contains actual markup) using Rich Text objects if you only want to set part of the text to bold.

$objRichText = new PHPExcel_RichText();
$objRichText->createText('This text is ');

$objBoldTextRun = $objRichText->createTextRun('bold');
$objBoldTextRun->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getCell('B1')->setValue($objRichText);

but you will need to parse your markup to convert it to a Rich Text object

Saturday, May 29, 2021
 
BrunoRamalho
answered 7 Months ago
27

It's mentioned in the documentation.


    $objRichText = new PHPExcel_RichText();
    $objRichText->createText('This invoice is ');

    $objPayable = $objRichText->createTextRun('payable within thirty days after the end of the month');
    $objPayable->getFont()->setBold(true);
    $objPayable->getFont()->setItalic(true);
    $objPayable->getFont()->setColor( new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_DARKGREEN ) );

    $objRichText->createText(', unless specified otherwise on the invoice.');

    $objPHPExcel->getActiveSheet()->getCell('A18')->setValue($objRichText);

Saturday, May 29, 2021
 
toesslab
answered 7 Months ago
86

Create an autoloader for PHPExcel and add it to the Zend autoloader stack.

In library/My/Loader/Autoloader/PHPExcel.php:

class My_Loader_Autoloader_PHPExcel implements Zend_Loader_Autoloader_Interface
{
    public function autoload($class)
    {
        if ('PHPExcel' != $class){
            return false;
        }
        require_once 'PHPExcel.php';
        return $class;
    }
}

And in application/configs/application.ini:

autoloadernamespaces[] = "My_"

Then, in application/Bootstrap.php:

protected function _initAutoloading()
{
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->pushAutoloader(new My_Loader_Autoloader_PHPExcel());
}

Then you should be able to instantiate PHPExcel - say, in a controller - with a simple:

$excel = new PHPExcel();

The only sticky part is all of this is how PHPExcel handles loading all its dependencies within its own folder. If that is done intelligently - either with calls like require_once basename(__FILE__) . '/someFile.php' or with its own autoloader that somehow doesn't get in the way of the Zend autoloader - then all should be cool. #famouslastwords

Monday, June 14, 2021
 
twk
answered 6 Months ago
twk
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share