Forums

Forums (http://www.abandonia.com/vbullet/index.php)
-   Programming (http://www.abandonia.com/vbullet/forumdisplay.php?f=25)
-   -   Php & Pear Development (http://www.abandonia.com/vbullet/showthread.php?t=7247)

Reup 17-09-2005 03:52 PM

I've been using a couple of useful PHP classes I'd thought I'd share:

FPDF - A quick PDF creation class
This is a really easy way to create good looking PDF documents on the fly! I've made colourfull tables and more with this in minutes!

PHPMailer - Great mail class
It has so many neat options!

And recently discovered the benefit of using PEAR-classes as well! I've used Spreadsheet_Excel_Writer to create .XLS files really quickly. I've been digging through all the other PEAR-classes and there are so many that look great. If anyone's interested I'll post my generic MySQL-dataset to .XLS-'parser' :ok:

If someone else has nifty classes they wrote or know about, I'd like to hear about them (links to if you got 'em)!

Data 18-09-2005 10:15 AM

indedd handy.

Reup 19-09-2005 07:18 AM

For anyone interested. This only works if PEAR is installed and configured on your server.

Code:

require_once 'Spreadsheet/Excel/Writer.php';

// $dataSet is any MySQL-query-result
// $title is the file-name including the complete path
// $MODE == 0 -> save as local file
// $MODE == 1 -> send HTTP headers -> open in browser! only use in NEW file, or
// the remaining HTML will be send to the sheet as well!!!

function writeExcel( $dataSet, $title, $MODE )
{
        // Creating a workbook
        $filename = $title.'.xls';
        $pathname = '.';
        $workbook = new Spreadsheet_Excel_Writer( $pathname.$filename );
       
        // Creating formats
        // Only bold in this case
        $format_bold =& $workbook->addFormat();
        $format_bold->setBold();       
       
        // sending HTTP headers if $MODE is set to 1
        if( $MODE == 1 ) $workbook->send($filename);
       
        // Creating a worksheet
        $worksheet =& $workbook->addWorksheet('SU5-Aanvragen'.$datum);
       
        // Writing column headers (bold)
        $numFields = mysql_num_fields( $dataSet );
        for( $k = 0; $k < $numFields; $k++ )
        {
 *$field = mysql_fetch_field( $dataSet, $k );
 *$fieldName = $field->name;
 *
 *$worksheet->write( 0, $k, $fieldName, $format_bold );
        }
 *
        //writing data, row for row (regular)
        for( $i = 0; $i < mysql_num_rows( $dataSet ); $i++ )
        {
 *// starting form row 1, because row 0 is the header-row
 *$row = mysql_fetch_array( $dataSet );
 *$index = $i + 1;
 *for( $k = 0; $k < $numFields; $k++ )
 *{
 *        $worksheet->write( $index, $k, $row[$k], $formal_bold );
 *} *       
        }
       
        // return the filename!
       
        // Let's send the file
        $workbook->close();
       
        return $pathname.$filename;
}



The current time is 07:36 PM (GMT)

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.