1

Here i am trying to format excel using PHP-Spreadsheet/Excel/Writer.php, i see crashed data in excel once it gets downloaded.Below is the screen shot of the image.I have googled and tried couple of solutions. Still the same can any one please help me to figure out solution

enter image description here

  <?PHP

    session_start();
    include_once('database/Insert.php');
    include_once('database/Select.php');    


    header("Content-Type: application/vnd.ms-excel");
    header('Cache-Control: max-age=0');
    $filter= $_SESSION['filter'];
    function vendor($crdid){
        $contract_renewal_data = array();
        $getVendor= new Select;
        //echo $crdid;
        $crdidarray=explode(",",$crdid);
        $string="";
    for($d=0;$d<count($crdidarray);$d++){

    $contract_renewal_data = $getVendor->selectWhere('contract_renewal_data','crdid',$crdidarray[$d]);

        if($contract_renewal_data != null){
    if(count($crdidarray)>$d+1){
        $string .= "".str_replace(",",".",$contract_renewal_data[0]['vendor'])." ; ";
    }else{
    $string .= "".str_replace(",",".",$contract_renewal_data[0]['vendor'])."";
    }
    //echo $string;
    }
    }
        return $string;
    }

    require_once 'Spreadsheet/Excel/Writer.php';

    try{

    $workbook = new Spreadsheet_Excel_Writer();
     $workbook->setVersion(8);
    $format_bold =& $workbook->addFormat();
    $format_bold->setBold();

    $format_title =& $workbook->addFormat();
    $format_title->setBold();
    $format_title->setColor('white');

    $format_title->setBgColor('#9CF');
    $worksheet =& $workbook->addWorksheet();
    $worksheet->setInputEncoding('UTF-16LE');

    // While we are at it, why not throw some more numbers around
    $worksheet->write(0, 0, "S No", $format_title);
    $worksheet->write(0, 1, "Account Name", $format_title);
    $worksheet->write(0, 2, "Account Industry", $format_title);
    $worksheet->write(0, 3, "Capgemini Sector", $format_title);
    $worksheet->write(0, 4, "Incumbent SBU", $format_title);
    $worksheet->write(0, 5, "Name of Incumbent Vendors", $format_title);
    $worksheet->write(0, 6, "Account Attractiveness Score", $format_title);
    $worksheet->write(0, 7, "Cagpemini Positioning Score", $format_title);



    for($i=0;$i<count($filter);$i++){

        $worksheet->write($i+1, 0, ($i+1));
    $worksheet->write($i+1, 1, $filter[$i]['account_name']);
    $worksheet->write($i+1, 2,$filter[$i]['account_industry']);
    $worksheet->write($i+1, 3,$filter[$i]['cg_sector']);
    $worksheet->write($i+1, 4,$filter[$i]['Incumbent_SBU']);
    $worksheet->write($i+1, 5,vendor($filter[$i]['crdid']));
    $worksheet->write($i+1, 6,$filter[$i]['CI_in_senario1']);
    $worksheet->write($i+1, 7,$filter[$i]['CG_in_senario1']);


        }


    $workbook->send('Executive Dashboard.xls');
    $workbook->close();
    exit();
    }catch(Exception $e)
            { 
                   // $this->isConnected = false;
                   echo "error is ".$e->getMessage();
                    throw new Exception($e->getMessage());
            }
    ?>
Community
  • 1
  • 1
3bu1
  • 977
  • 12
  • 30
  • I have used phpexcel at lastyear I think we have to specify spreadsheet format like something 'Excel2007' or other but I don't remember at where reading or writing. – siddhesh Dec 01 '15 at 07:16
  • look at here https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/10-Reading-and-Writing.md how they are creating writer $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007"); – siddhesh Dec 01 '15 at 07:20
  • @siddhesh - OP isn't using PHPExcel, they're suing Spreadsheet Excel Writer (aka SEW) – Mark Baker Dec 01 '15 at 08:06
  • @siddhesh - Pear - spreadsheet_excel_write. – 3bu1 Dec 01 '15 at 08:25
  • 1
    okay sorry I have look from the tag actually you tagged it on phpexcel. – siddhesh Dec 01 '15 at 09:28

0 Answers0