Jump to content

aebstract

Members
  • Posts

    1,105
  • Joined

  • Last visited

Posts posted by aebstract

  1. I'm needing to know what would be quicker in rendering and displaying. I'm going to have a list of about 45 items under 6 categories. I'm wanting to put it all in a database and loop through it with php, but if that would end up slowing down the site I want to look at something else. Typing it all in to html, would that be faster? Thanks for any info.

  2. Hi, I am wanting to get in to ajax and have a few specific applications that I am trying to learn this for to start. First thing I want to figure out and learn is how to use ajax with php to mess around with forms. I have a dropdown menu with a list of about 5-6 options. I want to have some sort of hidden field that if you select say option 2, it shows up for the user to fill out. If that option isn't chosen, then the form field never shows up and isn't used. Can someone point me in the right direction? Docs or anything would be great. I've found a lot on checking availability on usernames and form processing but not this. Thanks

  3. $i = 0;
    while($i < 12) {
        if($i == 0)
            echo date('F');
        else if(date('F', strtotime("+1 month")) != date('F'))
            echo date('F', strtotime("+1 month"));
        $i++;
    }
    

    Quick and Dirty way to just output it to text....one can easily create and array from this

     

    Only problem is that doesn't start on current month or loop back after december to january. Though the post just above this shows I got it working correctly, was just seeing if it should/could be trimmed down any.

  4. Nailed it first try:

    $months_array = array(1=>'January', 2=>'February', 3=>'March', 4=>'April', 5=>'May', 6=>'June', 7=>'July', 8=>'August', 9=>'September', 10=>'October', 11=>'November', 12=>'December');
    
    $output .= "<select name=\"due_date_month\">";
    $i = date('n');
          $output .= "<option value=\"$i\">$months_array[$i]</option>";
    if ($i == 12) { $i=1; } else { $i++; }
    
    $m = date('n');
    while ($i != $m){
    
          $output .= "<option value=\"$i\">$months_array[$i]</option>";
    if ($i == 12) { $i=1; } else { $i++; }
    }
    
    
    $output .= "</select>";
    

     

    Might be a way to clean it up some though?

  5. If I do an array, which is what I was thinking of (still not 100% sure on how it would work) and I set the months like 1 => January, 2 => February and I am starting on April, being 4. When I get to 12 how do I loop around to 1 and continue till I hit 4?

     

    edit: I could possibly do something like if my key is 12 to set it to 1 and start and kill it when my key hits the starting month. Shouldn't be too hard.

  6. Gah, edit button goes away over time. I do believe that they are being deleted now that I have been looking at it harder. I needed to go back to the cart page after updating for it to take affect, which means that I should be able to move my print of the cart down through my code till I find where it's messing it up, I'll post back with details as I figure it out ;(

  7. OKAY UPDATE:

     

    Here is an update on this issue, I added every part in the database to the cart and then hit the update button. It removed certain items from the display but was still in the array. So it's something in the display of the cart after the update button is hit. Here is where it gets displayed from:

     

    function showCart() {
    
    global $db;
    $totalprice = 0;
    $output = "";
        $color1 = "#EEEEEE";
        $color2 = "#DDDDDD";
        $row_count = 0;
    if (isset($_SESSION['cart'])) {
    
             $output .= '<form action="index.php?page=cart" method="post" id="cartfunctions">';
    
      foreach ($_SESSION['cart'] as $id => $array2){
      foreach ($array2 as $material => $array3){
      foreach ($array3 as $finish => $array4){
    
    $result = mysql_query("SELECT * FROM p_products WHERE id='$id'") or DIE(mysql_error());
    
          while($r=mysql_fetch_array($result))
          {
    
          $partnumber=$r["partnumber"];
          $partname=$r["partname"];
          $description=$r["description"];
          $category=$r["category"];
          $price=$r["price"];
    
          }
    
    $row_color = ($row_count % 2) ? $color1 : $color2;
    
             $output .= "
    <table width=\"590\" style=\"border-top: 1px solid #000; background-color: $row_color;\">
    <tr>
    <td width=\"100\" valign=\"top\"><img src=\"products/$partnumber-cart.jpg\" class=\"jkimagelarge\" title=\"products/$partnumber.jpg\" /></td>
    <td width=\"350\">
    $partname<br />
    $partnumber<br />
    $$price<br /><br />
    Material: $material<br />
    Finish: $finish";
    
    if (isset($array4['size'])){
    $output .= "<br />Size: {$array4['size']}";
    }
    
    $output .= "</td>
    <td width=\"60\"><input type=\"text\" name=\"$id$material$finish\" value=\"{$array4['qty']}\" size=\"3\" maxlength=\"3\" /></td>
    <td width=\"80\">";
    
    $qty = "{$array4['qty']}";
    $qtyprice = $price*$qty;
    
    $output .= "$$qtyprice</td>
    </tr>
    </table>";
    $row_count++;
    $totalprice = $totalprice + $qtyprice;
        }
       }
      }
    
             $output .= "<p align=\"right\">Grand Total: $totalprice</p>";
    	 $output .= "<input type=\"submit\" value=\"\" name=\"updatecart\" id=\"updatecart\" /><br /><br />";
             $output .= '</form>';
             		 $output .= "<form action=\"index.php?page=cart\" method=\"post\"><input type=\"submit\" value=\"\" name=\"checkout\" id=\"checkout\" /></form>";
    
    } else {
             $output .= '<p>You shopping cart is empty.</p>';
    }
    
    return $output;
    
    }
    

  8. Okay, here is my cart.php where everything happens for updating the cart:

     

    <?php
    header("Cache-control: private");
    if(!isset($_SESSION["id"]))
    {
    header("Location: index.php?page=login");
    exit;
    }
    
    
    if (isset($_POST['checkout'])){
    header("Location: index.php?page=checkout");
    exit;
    }
    
    
    
    if (isset($_POST['updatecart'])){
    
    
    
    
    
    
      foreach ($_SESSION['cart'] as $id2 => $array2){
    
    $count = count($array2);
    
    		foreach ($array2 as $material2 => $array3){
    
    
    $count2 = count($array3);
    
    		foreach ($array3 as $finish2 => $array4){
    
    
    $postqty = $id2.$material2.$finish2;
    
    if ($_POST[$postqty] == 0) {
    if ($count > 1){
    if ($count2 > 1){
    unset ($_SESSION['cart'][$id2][$material2][$finish2]);
    } else {
    unset ($_SESSION['cart'][$id2][$material2]);
    }
    } else {
    unset ($_SESSION['cart'][$id2]);
    }
    } else {
    if (isset($array4['size'])) {
    $_SESSION['cart'][$id2][$material2][$finish2] = array(qty => $_POST[$postqty], size => $array4['size']);
    } else {
    $_SESSION['cart'][$id2][$material2][$finish2] = array(qty => $_POST[$postqty]);
    }
    }
    
    
    
    	      }
    
    	}
    
      }
    
    
    
    
    
    
    
    
    
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    if (isset($_POST['checkout'])){
    echo "checkout";
    }
    
    
    
    
    
    
    $showCart = showCart(0);
    
    $content .= "<div id=\"full_content\">
    
    Shopping Cart<br />
    
    $showCart
    
    </div>";
    
    
    
    ?>

     

    There is a big functions.php page, I can post if needed (don't think it is). If you guys need to look at any other code just let me know.

     

    Here is my problem: When I put in a new number for the item, say I have 2 of item A and change it to 5 of item A and click update. It does this without a problem. It'll loop through and check to see if which items are suppose to be updated and do it as it should be. I have my parts split in to sections, just be a column name in my db. My problem is that ONLY on one category type, when I update ANY part on the cart page, the items from that specific category get completely removed from the cart. No matter what item I try to update.. I am lost as to why this is doing this, I really hope someone can point out what is going wrong. While you guys look at this I'm going to get a sample array for the cart to post to show what it looks like.

     

     

     

    edit:

    Here is a sample array:

    Array ( 
    [48] => Array ( [Aluminum] => Array ( [uncoated] => Array ( [qty] => 4 ) ) ) 
    [33] => Array ( [Aluminum] => Array ( [uncoated] => Array ( [qty] => 7 [size] => 2.2 ) ) ) 
    [11] => Array ( [stainless Steel] => Array ( [uncoated] => Array ( [qty] => 1 [size] => 4.5 ) ) ) 
    ) 
    

     

    This is for item id 48,33,11. The one that will get deleted when you update any item is id 11.

     

  9. No, it's stopping before it creates a file. I just saw the requirements for this library:

     

    * PHP version 5.2 or higher

        * PHP extension php_zip enabled

        * PHP extension php_xml enabled

        * PHP extension php_gd2 enabled (if not compiled in)

     

    I'm currently on 5.1.6. I'm on hold waiting to talk to someone from my Host right now to see if I can get it upgraded, and ask if those php extensions are enabled or not. Just to be certain.

     

    Server is running on Linux.

  10. Okay, I just tested with their exact code, ended up stopping at the same spot. I used their most basic example as a test as well, ends up stopping on the same thing:

    <?php
    /**
    * PHPExcel
    *
    * Copyright (C) 2006 - 2009 PHPExcel
    *
    * This library is free software; you can redistribute it and/or
    * modify it under the terms of the GNU Lesser General Public
    * License as published by the Free Software Foundation; either
    * version 2.1 of the License, or (at your option) any later version.
    *
    * This library is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    * Lesser General Public License for more details.
    *
    * You should have received a copy of the GNU Lesser General Public
    * License along with this library; if not, write to the Free Software
    * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    *
    * @category   PHPExcel
    * @package    PHPExcel
    * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
    * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL
    * @version    1.6.6, 2009-03-02
    */
    
    /** Error reporting */
    error_reporting(E_ALL);
    
    /** Include path **/
    set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
    
    /** PHPExcel */
    include 'PHPExcel.php';
    
    /** PHPExcel_IOFactory */
    include 'PHPExcel/IOFactory.php';
    
    // Create new PHPExcel object
    echo date('H:i:s') . " Create new PHPExcel object\n";
    $objPHPExcel = new PHPExcel();
    
    // Set properties
    echo date('H:i:s') . " Set properties\n";
    $objPHPExcel->getProperties()->setCreator("Maarten Balliauw");
    $objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");
    $objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");
    $objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
    $objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");
    $objPHPExcel->getProperties()->setKeywords("office 2007 openxml php");
    $objPHPExcel->getProperties()->setCategory("Test result file");
    
    
    // Add some data
    echo date('H:i:s') . " Add some data\n";
    $objPHPExcel->setActiveSheetIndex(0);
    $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Hello');
    $objPHPExcel->getActiveSheet()->setCellValue('B2', 'world!');
    $objPHPExcel->getActiveSheet()->setCellValue('C1', 'Hello');
    $objPHPExcel->getActiveSheet()->setCellValue('D2', 'world!');
    
    // Rename sheet
    echo date('H:i:s') . " Rename sheet\n";
    $objPHPExcel->getActiveSheet()->setTitle('Simple');
    
    
    // Set active sheet index to the first sheet, so Excel opens this as the first sheet
    $objPHPExcel->setActiveSheetIndex(0);
    
    
    // Save Excel 2007 file
    echo date('H:i:s') . " Write to Excel2007 format\n";
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
    
    // Echo memory peak usage
    echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";
    
    // Echo done
    echo date('H:i:s') . " Done writing file.\r\n";
    
    

     

     

    15:30:31 Create new PHPExcel object

    15:30:31 Set properties

    15:30:31 Add some data

    15:30:31 Rename sheet

    15:30:31 Write to Excel2007 format

     

     

    Is this some sort of setting I need to have enabled on my server or something?

  11. Okay I am trying to just run one of their basic examples, with a slight modification (just removed the stuff that added sheet two). Going through their examples, just about everything that is done has an echo, let's you know where you're getting stuck at and whatnot. Well, here is the code for the two pages:

     

    testexcel.php

    <?php
    
    
    include "testexcel.inc.php";
    
    /** PHPExcel_IOFactory */
    include 'PHPExcel/IOFactory.php';
    
    // Save Excel 2007 file
    echo date('H:i:s') . " Write to Excel2007 format\n";
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
    
    // Echo memory peak usage
    echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";
    
    // Echo done
    echo date('H:i:s') . " Done writing file.\r\n";
    
    

     

    and testexcel.inc.php

    <?php
    
    
    /** Error reporting */
    error_reporting(E_ALL);
    
    /** Include path **/
    set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
    
    /** PHPExcel */
    require_once 'PHPExcel.php';
    
    /** PHPExcel_RichText */
    require_once 'PHPExcel/RichText.php';
    
    // Create new PHPExcel object
    echo date('H:i:s') . " Create new PHPExcel object\n";
    $objPHPExcel = new PHPExcel();
    
    // Set properties
    echo date('H:i:s') . " Set properties\n";
    $objPHPExcel->getProperties()->setCreator("Maarten Balliauw");
    $objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");
    $objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");
    $objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
    $objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");
    $objPHPExcel->getProperties()->setKeywords("office 2007 openxml php");
    $objPHPExcel->getProperties()->setCategory("Test result file");
    
    
    // Create a first sheet, representing sales data
    echo date('H:i:s') . " Add some data\n";
    $objPHPExcel->setActiveSheetIndex(0);
    $objPHPExcel->getActiveSheet()->setCellValue('B1', 'Invoice');
    $objPHPExcel->getActiveSheet()->setCellValue('D1', time());
    $objPHPExcel->getActiveSheet()->getStyle('D1')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH);
    $objPHPExcel->getActiveSheet()->setCellValue('E1', '#12566');
    
    $objPHPExcel->getActiveSheet()->setCellValue('A3', 'Product Id');
    $objPHPExcel->getActiveSheet()->setCellValue('B3', 'Description');
    $objPHPExcel->getActiveSheet()->setCellValue('C3', 'Price');
    $objPHPExcel->getActiveSheet()->setCellValue('D3', 'Amount');
    $objPHPExcel->getActiveSheet()->setCellValue('E3', 'Total');
    
    $objPHPExcel->getActiveSheet()->setCellValue('A4', '1001');
    $objPHPExcel->getActiveSheet()->setCellValue('B4', 'PHP for dummies');
    $objPHPExcel->getActiveSheet()->setCellValue('C4', '20');
    $objPHPExcel->getActiveSheet()->setCellValue('D4', '1');
    $objPHPExcel->getActiveSheet()->setCellValue('E4', '=C4*D4');
    
    $objPHPExcel->getActiveSheet()->setCellValue('A5', '1012');
    $objPHPExcel->getActiveSheet()->setCellValue('B5', 'OpenXML for dummies');
    $objPHPExcel->getActiveSheet()->setCellValue('C5', '22');
    $objPHPExcel->getActiveSheet()->setCellValue('D5', '2');
    $objPHPExcel->getActiveSheet()->setCellValue('E5', '=C5*D5');
    
    $objPHPExcel->getActiveSheet()->setCellValue('E6', '=C6*D6');
    $objPHPExcel->getActiveSheet()->setCellValue('E7', '=C7*D7');
    $objPHPExcel->getActiveSheet()->setCellValue('E8', '=C8*D8');
    $objPHPExcel->getActiveSheet()->setCellValue('E9', '=C9*D9');
    
    $objPHPExcel->getActiveSheet()->setCellValue('D11', 'Total excl.:');
    $objPHPExcel->getActiveSheet()->setCellValue('E11', '=SUM(E4:E9)');
    
    $objPHPExcel->getActiveSheet()->setCellValue('D12', 'VAT:');
    $objPHPExcel->getActiveSheet()->setCellValue('E12', '=E11*0.21');
    
    $objPHPExcel->getActiveSheet()->setCellValue('D13', 'Total incl.:');
    $objPHPExcel->getActiveSheet()->setCellValue('E13', '=E11+E12');
    
    // Add comment
    echo date('H:i:s') . " Add comments\n";
    
    $objPHPExcel->getActiveSheet()->getComment('E11')->setAuthor('PHPExcel');
    $objCommentRichText = $objPHPExcel->getActiveSheet()->getComment('E11')->getText()->createTextRun('PHPExcel:');
    $objCommentRichText->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getComment('E11')->getText()->createTextRun("\r\n");
    $objPHPExcel->getActiveSheet()->getComment('E11')->getText()->createTextRun('Total amount on the current invoice, excluding VAT.');
    
    $objPHPExcel->getActiveSheet()->getComment('E12')->setAuthor('PHPExcel');
    $objCommentRichText = $objPHPExcel->getActiveSheet()->getComment('E12')->getText()->createTextRun('PHPExcel:');
    $objCommentRichText->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getComment('E12')->getText()->createTextRun("\r\n");
    $objPHPExcel->getActiveSheet()->getComment('E12')->getText()->createTextRun('Total amount of VAT on the current invoice.');
    
    $objPHPExcel->getActiveSheet()->getComment('E13')->setAuthor('PHPExcel');
    $objCommentRichText = $objPHPExcel->getActiveSheet()->getComment('E13')->getText()->createTextRun('PHPExcel:');
    $objCommentRichText->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getComment('E13')->getText()->createTextRun("\r\n");
    $objPHPExcel->getActiveSheet()->getComment('E13')->getText()->createTextRun('Total amount on the current invoice, including VAT.');
    $objPHPExcel->getActiveSheet()->getComment('E13')->setWidth('100pt');
    $objPHPExcel->getActiveSheet()->getComment('E13')->setHeight('100pt');
    $objPHPExcel->getActiveSheet()->getComment('E13')->setMarginLeft('150pt');
    $objPHPExcel->getActiveSheet()->getComment('E13')->getFillColor()->setRGB('EEEEEE');
    
    
    // Add rich-text string
    echo date('H:i:s') . " Add rich-text string\n";
    $objRichText = new PHPExcel_RichText( $objPHPExcel->getActiveSheet()->getCell('A18') );
    $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.');
    
    // Merge cells
    echo date('H:i:s') . " Merge cells\n";
    $objPHPExcel->getActiveSheet()->mergeCells('A18:E22');
    $objPHPExcel->getActiveSheet()->mergeCells('A28:B28');		// Just to test...
    $objPHPExcel->getActiveSheet()->unmergeCells('A28:B28');	// Just to test...
    
    // Protect cells
    echo date('H:i:s') . " Protect cells\n";
    $objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);	// Needs to be set to true in order to enable any worksheet protection!
    $objPHPExcel->getActiveSheet()->protectCells('A3:E13', 'PHPExcel');
    
    // Set cell number formats
    echo date('H:i:s') . " Set cell number formats\n";
    $objPHPExcel->getActiveSheet()->getStyle('E4')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
    $objPHPExcel->getActiveSheet()->duplicateStyle( $objPHPExcel->getActiveSheet()->getStyle('E4'), 'E5:E13' );
    
    // Set column widths
    echo date('H:i:s') . " Set column widths\n";
    $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
    $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12);
    $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(12);
    
    // Set fonts
    echo date('H:i:s') . " Set fonts\n";
    $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setName('Candara');
    $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(20);
    $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
    $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
    
    $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
    $objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
    
    $objPHPExcel->getActiveSheet()->getStyle('D13')->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getStyle('E13')->getFont()->setBold(true);
    
    // Set alignments
    echo date('H:i:s') . " Set alignments\n";
    $objPHPExcel->getActiveSheet()->getStyle('D11')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
    $objPHPExcel->getActiveSheet()->getStyle('D12')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
    $objPHPExcel->getActiveSheet()->getStyle('D13')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
    
    $objPHPExcel->getActiveSheet()->getStyle('A18')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
    $objPHPExcel->getActiveSheet()->getStyle('A18')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
    
    $objPHPExcel->getActiveSheet()->getStyle('B5')->getAlignment()->setShrinkToFit(true);
    
    // Set column borders
    echo date('H:i:s') . " Set column borders\n";
    $objPHPExcel->getActiveSheet()->getStyle('A4')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('B4')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('C4')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('D4')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('E4')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    
    $objPHPExcel->getActiveSheet()->getStyle('A11')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('B11')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('C11')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('D11')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('E11')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    
    $objPHPExcel->getActiveSheet()->getStyle('A4')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('A5')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('A6')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('A7')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('A8')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('A9')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('A10')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    
    $objPHPExcel->getActiveSheet()->getStyle('E4')->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('E5')->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('E6')->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('E7')->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('E8')->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('E9')->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('E10')->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    
    $objPHPExcel->getActiveSheet()->getStyle('D11')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('D12')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('D13')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
    
    $objPHPExcel->getActiveSheet()->getStyle('E11')->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('E12')->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('E13')->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
    
    $objPHPExcel->getActiveSheet()->getStyle('D13')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
    $objPHPExcel->getActiveSheet()->getStyle('E13')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
    $objPHPExcel->getActiveSheet()->getStyle('D13')->getBorders()->getBottom()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
    $objPHPExcel->getActiveSheet()->getStyle('E13')->getBorders()->getBottom()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
    
    // Set border colors
    echo date('H:i:s') . " Set border colors\n";
    $objPHPExcel->getActiveSheet()->getStyle('D13')->getBorders()->getLeft()->getColor()->setARGB('FF993300');
    $objPHPExcel->getActiveSheet()->getStyle('D13')->getBorders()->getTop()->getColor()->setARGB('FF993300');
    $objPHPExcel->getActiveSheet()->getStyle('D13')->getBorders()->getBottom()->getColor()->setARGB('FF993300');
    $objPHPExcel->getActiveSheet()->getStyle('E13')->getBorders()->getTop()->getColor()->setARGB('FF993300');
    $objPHPExcel->getActiveSheet()->getStyle('E13')->getBorders()->getBottom()->getColor()->setARGB('FF993300');
    $objPHPExcel->getActiveSheet()->getStyle('E13')->getBorders()->getRight()->getColor()->setARGB('FF993300');
    
    // Set fills
    echo date('H:i:s') . " Set fills\n";
    $objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
    $objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->getStartColor()->setARGB('FF808080');
    $objPHPExcel->getActiveSheet()->getStyle('B1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
    $objPHPExcel->getActiveSheet()->getStyle('B1')->getFill()->getStartColor()->setARGB('FF808080');
    $objPHPExcel->getActiveSheet()->getStyle('C1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
    $objPHPExcel->getActiveSheet()->getStyle('C1')->getFill()->getStartColor()->setARGB('FF808080');
    $objPHPExcel->getActiveSheet()->getStyle('D1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
    $objPHPExcel->getActiveSheet()->getStyle('D1')->getFill()->getStartColor()->setARGB('FF808080');
    $objPHPExcel->getActiveSheet()->getStyle('E1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
    $objPHPExcel->getActiveSheet()->getStyle('E1')->getFill()->getStartColor()->setARGB('FF808080');
    
    // Set style for header row using alternative method
    echo date('H:i:s') . " Set style for header row using alternative method\n";
    $objPHPExcel->getActiveSheet()->duplicateStyleArray(
    	array(
    		'font'    => array(
    			'bold'      => true
    		),
    		'alignment' => array(
    			'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_RIGHT,
    		),
    		'borders' => array(
    			'top'     => array(
    					'style' => PHPExcel_Style_Border::BORDER_THIN
    				)
    		),
    		'fill' => array(
     			'type'       => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
      			'rotation'   => 90,
     			'startcolor' => array(
     				'argb' => 'FFA0A0A0'
     			),
     			'endcolor'   => array(
     				'argb' => 'FFFFFFFF'
     			)
     		)
    	),
    	'A3:E3'
    );
    
    $objPHPExcel->getActiveSheet()->getStyle('A3')->applyFromArray(
    	array(
    		'alignment' => array(
    			'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
    		),
    		'borders' => array(
    			'left'     => array(
    					'style' => PHPExcel_Style_Border::BORDER_THIN
    				)
    		)
    	)
    );
    
    $objPHPExcel->getActiveSheet()->getStyle('B3')->applyFromArray(
    	array(
    		'alignment' => array(
    			'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
    		)
    	)
    );
    
    $objPHPExcel->getActiveSheet()->getStyle('E3')->applyFromArray(
    	array(
    		'borders' => array(
    			'right'     => array(
    					'style' => PHPExcel_Style_Border::BORDER_THIN
    				)
    		)
    	)
    );
    
    // Unprotect a cell
    echo date('H:i:s') . " Unprotect a cell\n";
    $objPHPExcel->getActiveSheet()->getStyle('B1')->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
    
    // Add a hyperlink to the sheet
    echo date('H:i:s') . " Add a hyperlink to the sheet\n";
    $objPHPExcel->getActiveSheet()->setCellValue('E26', 'www.phpexcel.net');
    $objPHPExcel->getActiveSheet()->getCell('E26')->getHyperlink()->setUrl('http://www.phpexcel.net');
    $objPHPExcel->getActiveSheet()->getCell('E26')->getHyperlink()->setTooltip('Navigate to website');
    $objPHPExcel->getActiveSheet()->getStyle('E26')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
    
    $objPHPExcel->getActiveSheet()->setCellValue('E27', 'Terms and conditions');
    $objPHPExcel->getActiveSheet()->getCell('E27')->getHyperlink()->setUrl("sheet://'Terms and conditions'!A1");
    $objPHPExcel->getActiveSheet()->getCell('E27')->getHyperlink()->setTooltip('Review terms and conditions');
    $objPHPExcel->getActiveSheet()->getStyle('E27')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
    
    
    
    // Play around with inserting and removing rows and columns
    echo date('H:i:s') . " Play around with inserting and removing rows and columns\n";
    $objPHPExcel->getActiveSheet()->insertNewRowBefore(6, 10);
    $objPHPExcel->getActiveSheet()->removeRow(6, 10);
    $objPHPExcel->getActiveSheet()->insertNewColumnBefore('E', 5);
    $objPHPExcel->getActiveSheet()->removeColumn('E', 5);
    
    // Set header and footer. When no different headers for odd/even are used, odd header is assumed.
    echo date('H:i:s') . " Set header/footer\n";
    $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&BInvoice&RPrinted on &D');
    $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $objPHPExcel->getProperties()->getTitle() . '&RPage &P of &N');
    
    // Set page orientation and size
    echo date('H:i:s') . " Set page orientation and size\n";
    $objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
    $objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
    
    // Rename sheet
    echo date('H:i:s') . " Rename sheet\n";
    $objPHPExcel->getActiveSheet()->setTitle('Invoice');
    
    
    // Set active sheet index to the first sheet, so Excel opens this as the first sheet
    $objPHPExcel->setActiveSheetIndex(0);
    
    

     

     

    Here is what is getting sent back to me as results:

     

    15:20:26 Create new PHPExcel object
    15:20:26 Set properties
    15:20:26 Add some data
    15:20:26 Add comments
    15:20:26 Add rich-text string
    15:20:26 Merge cells
    15:20:26 Protect cells
    15:20:26 Set cell number formats
    15:20:26 Set column widths
    15:20:26 Set fonts
    15:20:26 Set alignments
    15:20:26 Set column borders
    15:20:26 Set border colors
    15:20:26 Set fills
    15:20:26 Set style for header row using alternative method
    15:20:26 Unprotect a cell
    15:20:26 Add a hyperlink to the sheet
    15:20:26 Play around with inserting and removing rows and columns
    15:20:27 Set header/footer
    15:20:27 Set page orientation and size
    15:20:27 Rename sheet
    15:20:27 Write to Excel2007 format
    

     

    Which tells me, the last thing it does is this:

    echo date('H:i:s') . " Write to Excel2007 format\n";

     

    and stops before it does the rest:

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
    
    // Echo memory peak usage
    echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";
    
    // Echo done
    echo date('H:i:s') . " Done writing file.\r\n";
    

     

     

    Any help on this is greatly appreciated. Thanks

     

     

     

     

    EDIT: I just threw in an extra echo, to isolate the exact line:

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
    

     

    It's the second line in the above code, I put an echo in after the first line and it output fine. Put one after the second line and it was stopped at that point.

    What is wrong with this?

    $objWriter->save(str_replace('.php', '.xlsx', __FILE__));

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.