1

在这里,我正在尝试使用 PHP-Spreadsheet/Excel/Writer.php 格式化 excel,一旦下载,我会在 excel 中看到崩溃的数据。下面是图像的屏幕截图。我已经用谷歌搜索并尝试了几个解决方案。还是一样,任何人都可以帮我找出解决方案

在此处输入图像描述

  <?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());
            }
    ?>
4

0 回答 0