function createXLSAdv(&$rows, $row_labels = null, $row_headers = null, $title = null)
 {
     ob_clean();
     ob_start();
     require_once JPATH_COMPONENT_SITE . DS . 'libraries' . DS . 'pear' . DS . 'PEAR.php';
     require_once JPATH_COMPONENT_SITE . DS . 'libraries' . DS . 'Excel' . DS . 'Writer.php';
     // Creating a workbook
     $workbook = new Spreadsheet_Excel_Writer();
     $worksheet = $workbook->addWorksheet($title);
     $BIFF = new Spreadsheet_Excel_Writer_BIFFwriter();
     $format = new Spreadsheet_Excel_Writer_Format($BIFF);
     $format->setBold(1);
     $format->setAlign('center');
     for ($k = 0; $k < count($row_labels); $k++) {
         $worksheet->write(0, $k, $row_headers[$row_labels[$k]], $format);
     }
     for ($i = 0; $i < count($rows); $i++) {
         for ($k = 0; $k < count($row_labels); $k++) {
             $worksheet->write($i + 1, $k, $rows[$i][$row_labels[$k]]);
         }
     }
     $workbook->close();
     $attachment = ob_get_contents();
     @ob_end_clean();
     echo $attachment;
 }
Esempio n. 2
0
    function createXLS($result) {

        ob_clean();
        ob_start();
        set_time_limit(0);
        error_reporting(0);
        require_once JPATH_COMPONENT_SITE . '/libraries/pear/PEAR.php';
        require_once (JPATH_ROOT . '/components/com_bids/libraries/Excel/Writer.php');
        // Creating a workbook
        $workbook = new Spreadsheet_Excel_Writer();
        $workbook->setTempDir(JPATH_ROOT.DS.'tmp');
        $worksheet = $workbook->addWorksheet('Exported Auctions');
        $BIFF = new Spreadsheet_Excel_Writer_BIFFwriter();
        $format = new Spreadsheet_Excel_Writer_Format($BIFF);
        $format->setBold(1);
        $format->setAlign('center');

        $colNr = 0;

        $worksheet->write(0, $colNr++, "User", $format);
        $worksheet->write(0, $colNr++, "Title", $format);
        $worksheet->write(0, $colNr++, "Short description");
        $worksheet->write(0, $colNr++, "Description");
        $worksheet->write(0, $colNr++, "Initial price");
        $worksheet->write(0, $colNr++, "Currency");
        $worksheet->write(0, $colNr++, "BIN price");
        $worksheet->write(0, $colNr++, "Auction type");
        $worksheet->write(0, $colNr++, "Automatic");
        $worksheet->write(0, $colNr++, "Payment");
        $worksheet->write(0, $colNr++, "Shipment Info");
        $worksheet->write(0, $colNr++, "Start date");
        $worksheet->write(0, $colNr++, "End date");
        $worksheet->write(0, $colNr++, "Param: picture");
        $worksheet->write(0, $colNr++, "Param: add_picture");
        $worksheet->write(0, $colNr++, "Param: auto_accept_bin");
        $worksheet->write(0, $colNr++, "Param: bid_counts");
        $worksheet->write(0, $colNr++, "Param: max_price");
        $worksheet->write(0, $colNr++, "Published");
        $worksheet->write(0, $colNr++, "Category");
        $worksheet->write(0, $colNr++, "Highest Bid");
        for ($i = 0; $i < count($result); $i++) {
            $colNr = 0;
            $worksheet->write($i + 1, $colNr++, $result[$i]->username);
            $worksheet->write($i + 1, $colNr++, $result[$i]->title);
            $worksheet->write($i + 1, $colNr++, $result[$i]->shortdescription);
            $worksheet->write($i + 1, $colNr++, $result[$i]->description);
            $worksheet->write($i + 1, $colNr++, $result[$i]->initial_price);
            $worksheet->write($i + 1, $colNr++, $result[$i]->currency);
            $worksheet->write($i + 1, $colNr++, $result[$i]->BIN_price);
            switch ($result[$i]->auction_type) {
                case 1:
                    $worksheet->write($i + 1, $colNr++, 'public');
                    break;
                case 2:
                    $worksheet->write($i + 1, $colNr++, 'private');
                    break;
                case 3:
                    $worksheet->write($i + 1, $colNr++, 'BIN only');
                    break;
            }
            $worksheet->write($i + 1, $colNr++, $result[$i]->automatic);
            $worksheet->write($i + 1, $colNr++, $result[$i]->payment_method);
            $worksheet->write($i + 1, $colNr++, $result[$i]->shipment_info);
            $worksheet->write($i + 1, $colNr++, $result[$i]->start_date);
            $worksheet->write($i + 1, $colNr++, $result[$i]->end_date);
            $params = explode("\n", $result[$i]->params);
            $tmp = explode("=", $params[0]); // picture param
            $worksheet->write($i + 1, $colNr++, $tmp[1]);
            $tmp = explode("=", $params[1]); // add_picture
            $worksheet->write($i + 1, $colNr++, $tmp[1]);
            $tmp = explode("=", $params[2]); // auto_accept_bin
            $worksheet->write($i + 1, $colNr++, $tmp[1]);
            $tmp = explode("=", $params[3]); // bid_counts
            $worksheet->write($i + 1, $colNr++, $tmp[1]);
            $tmp = explode("=", $params[4]); // max_price
            $worksheet->write($i + 1, $colNr++, $tmp[1]);

            $worksheet->write($i + 1, $colNr++, $result[$i]->published);
            $worksheet->write($i + 1, $colNr++, $result[$i]->catname);
            $worksheet->write($i + 1, $colNr++, $result[$i]->highest_bid);

            $worksheet->setColumn(0, 0, 9);
            $worksheet->setColumn(1, 12, 25);
        }
        $workbook->close();
        $attachment = ob_get_clean();

        return $attachment;
    }