Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHPExcel绘图图表导致内容不可读,图表已删除_Php_Charts_Phpexcel - Fatal编程技术网

PHPExcel绘图图表导致内容不可读,图表已删除

PHPExcel绘图图表导致内容不可读,图表已删除,php,charts,phpexcel,Php,Charts,Phpexcel,我使用PHPExcel生成图表,所有内容都是正确的,但有时当我打开文件时,当我单击“是”按钮进行修复时,会显示一条消息,指示无法读取的内容被删除。下面是我的密码 $workbook = new PHPExcel(); for($sh = 0; $sh <= 2; $sh++) { if($sh == 0) { $sheet = $workbook->createSheet($sh);

我使用PHPExcel生成图表,所有内容都是正确的,但有时当我打开文件时,当我单击“是”按钮进行修复时,会显示一条消息,指示无法读取的内容被删除。下面是我的密码

    $workbook = new PHPExcel();
    for($sh = 0; $sh <= 2; $sh++)
    {   
        if($sh == 0)
        {   
            $sheet = $workbook->createSheet($sh); 
            $sheet = $workbook->setActiveSheetIndex($sh);
            $workbook->getActiveSheet()->setTitle($this->lang->line('co_repBased_pos'));
            $sheet_name = $sheet->getTitle();

        }
        elseif($sh == 1)
        {   //$sheet = $workbook->createSheet($sh);
            $sheet = $workbook->setActiveSheetIndex($sh);
                  $workbook->getActiveSheet()->setTitle($this->lang->line('co_repBased_jloc'));  
            $sheet_name = $sheet->getTitle();  
        }
        elseif($sh == 2)
        {   
            $sheet = $workbook->createSheet($sh);
            $sheet = $workbook->setActiveSheetIndex($sh); 
            $workbook->getActiveSheet()->setTitle($this->lang->line('co_total_rep'));  
            $sheet_name = $sheet->getTitle();

        }

        $sheet->getTabColor()->setRGB('CC000#');
        // Set the page setting for easy print option 
        $sheet->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
        $sheet->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
        $sheet->getPageSetup()->setFitToPage(TRUE);
        $sheet->getPageSetup()->setFitToWidth(1);
        $sheet->getPageSetup()->setFitToHeight(0);
        // Set the protection of work book and sheet 
        $workbook->getSecurity()->setLockWindows(true);
        $workbook->getSecurity()->setLockStructure(true);
        $workbook->getSecurity()->setWorkbookPassword("pAsSwOrD");
        // Set sheet password protected 
        $sheet->getProtection()->setSheet(TRUE);

        $sheet->getProtection()->setSort(true);   
        $sheet->getProtection()->setInsertRows(true);   
        $sheet->getProtection()->setInsertColumns(true);   
        $sheet->getProtection()->setFormatCells(true); 
        $sheet->getProtection()->setSelectUnlockedCells(false);   
        $sheet->getProtection()->setSelectLockedCells(true);   
        $sheet->getProtection()->setObjects(true);   
        $sheet->getProtection()->setPassword("pAsSwOrD");   
        $styleHeadings = array(
                                'borders' => array(
                                    'allborders' => array(
                                        'style' => PHPExcel_Style_Border::BORDER_THIN,
                                            'color' => array('argb' => '#DBDBB7'),
                                        ),
                                    ),
                                'font' => array(
                                    'bold' => true,
                                    'size' => 20 
                                    ),
                                'fill' => array(
                                    'type' => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
                                    'startcolor' => array(
                                        'argb' => 'E9E9E9',
                                    ),
                                    'endcolor' => array(
                                        'argb' => 'E9E9E9',
                                    ),
                                ),
                                'alignment' => array(
                                'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER
                                ),   
                    );
        if($this->mng_auth->get_language()=='en')
        {
            $sheet->setRightToLeft(false); 
        }
        else
        {  
            $sheet->setRightToLeft(true); 
        }
        $start_headRow = $total_rows+1;
        $end_headRow = $total_rows+2;
        // Make the chart area setting 
        $j = 'B';       
        for($k = 0; $k < $course_count; $k++)
        {   
            $m=$k;
            $col = $j;           
            $j = chr(ord($j)+$m);    
        }  
        $total_std = 0;
        foreach($chart_total_stdOfCourse as $row)
        {
            if($row[1] > $total_std)
            {
                $total_std = $row[1];
            }
        }  

        $input_string  = $col;
        $base_value    = 64;
        $decimal_value = 26;
        $column_index  = 0;
        for ($d = 0; $d < strlen($input_string); $d++) 
        {
            // take the ASCII value.
            $char_value = ord($input_string[$d]);
            $char_value -= $base_value;
            $char_value *= pow($decimal_value, (strlen($input_string) - ($d + 1)));
            $column_index += $char_value;
        }
        //create column for present

        $present = PHPExcel_Cell::stringFromColumnIndex($column_index);
        //echo $course_count.'/'.$column_index.'/'.$end_headRow.'/'.$present; exit;
        if($column_index <= 9)
        {
            $present = 'J';
            $column_index = 9;
        }
        // End of chart area setting 
        $sheet->getStyle('A'.$start_headRow.':'.$present.$end_headRow)->applyFromArray($styleHeadings);
        if($sh == 0)
        {
            $sheet->setCellValue('A'.$start_headRow,'ÑÇæÑ æÑÓ åÇ Èå ÇÓÇÓ ÑÊÈå ÔÇÑÏ');
        }
        elseif($sh == 1)
        {
            $sheet->setCellValue('A'.$start_headRow,'ÑÇæÑ æÑÓ åÇ Èå ÇÓÇÓ ãÍá æÙíÝå ÔÇÑÏ');
        }
        elseif($sh == 2)
        {
            $sheet->setCellValue('A'.$start_headRow,'ÑÇæÑ æÑÓ åÇ Èå ÇÓÇÓ ãÌãæÚå ÔÇÑÏÇä');
        }
        $sheet->getStyle('A'.$start_headRow.':'.$present.$end_headRow)->getAlignment()->setWrapText(true);
        // Set mergeCells  start from 0 
        $sheet->mergeCellsByColumnAndRow(0,$start_headRow,$column_index,$end_headRow);
        if($sh == 0)
        {
            $sheet->fromArray(  
               $course_rep,
               NULL,
               'B'.$startRow_num 
            );
        }
        elseif($sh == 1)
        {
            $sheet->fromArray(  
               $course_jobLocBasedrep,
               NULL,
               'B'.$startRow_num  
            );

        }
        else
        {
            $sheet->fromArray(  
                   $chart_total_stdOfCourse,
                   NULL,
                   'B'.$startRow_num  
                );
        }
        if($sh <= 1)
        {
            $labels = array(
              new PHPExcel_Chart_DataSeriesValues('String', "'".$sheet_name."'".'!$C$'.$startRow_num, null, 1),
              new PHPExcel_Chart_DataSeriesValues('String', "'".$sheet_name."'".'!$D$'.$startRow_num, null, 1), 
              new PHPExcel_Chart_DataSeriesValues('String', "'".$sheet_name."'".'!$E$'.$startRow_num, null, 1), 
              new PHPExcel_Chart_DataSeriesValues('String', "'".$sheet_name."'".'!$F$'.$startRow_num, null, 1), 
            );

            // find the end row number of data source because we write from A2 so A3 is the start of main data 

            $categories = array(
              new PHPExcel_Chart_DataSeriesValues('String', "'".$sheet_name."'".'!$B$'.$category_start.':$B$'.$total_rows, null, 4),   
            );
            $values = array(
              new PHPExcel_Chart_DataSeriesValues('Number', "'".$sheet_name."'".'!$C$'.$category_start.':$C$'.$total_rows, null, 4),
              new PHPExcel_Chart_DataSeriesValues('Number', "'".$sheet_name."'".'!$D$'.$category_start.':$D$'.$total_rows, null, 4),  
              new PHPExcel_Chart_DataSeriesValues('Number', "'".$sheet_name."'".'!$E$'.$category_start.':$E$'.$total_rows, null, 4),  
              new PHPExcel_Chart_DataSeriesValues('Number', "'".$sheet_name."'".'!$F$'.$category_start.':$F$'.$total_rows, null, 4),  
            );
            $series = new PHPExcel_Chart_DataSeries(
              PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D,    // plotType
              PHPExcel_Chart_DataSeries::GROUPING_STACKED,    // plotGrouping
              array(0,1,2,3),                                 // plotOrder
              $labels,                                        // plotLabel
              $categories,                                    // plotCategory
              $values                                         // plotValues
            );
        }
        elseif($sh == 2)
        {    

            // Total student chart 
            $labels = array(
              //new PHPExcel_Chart_DataSeriesValues('String', $sheet_name.'!$Q$'.$startRow_num, null, 1),
              new PHPExcel_Chart_DataSeriesValues('String', "'".$sheet_name."'".'!$C$'.$startRow_num, null, 1)
            );

            // find the end row number of data source because we write from A2 so A3 is the start of main data 

            $categories = array(
              new PHPExcel_Chart_DataSeriesValues('String', "'".$sheet_name."'".'!$B$'.$category_start.':$B$'.$total_rows, null, 1)   
            );
            $values = array(
              new PHPExcel_Chart_DataSeriesValues('Number', "'".$sheet_name."'".'!$C$'.$category_start.':$C$'.$total_rows, null, 1)
              //new PHPExcel_Chart_DataSeriesValues('Number', $sheet_name.'!$B$'.$category_start.':$B$'.$total_rows, null, 4),  
            ); 
            $series = new PHPExcel_Chart_DataSeries(
              PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D,    // plotType
              PHPExcel_Chart_DataSeries::GROUPING_STACKED,    // plotGrouping
              array(0),                                       // plotOrder
              $labels,                                        // plotLabel
              $categories,                                    // plotCategory
              $values                                         // plotValues
            );  
        }                                                                          
        $series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);        
        $layout1 = new PHPExcel_Chart_Layout();    // Create object of chart layout to set data label 
        $layout1->setShowVal(TRUE);                   
        $layout1->setManual3dAlign(true);
        $layout1->setXRotation(20);
        $layout1->setYRotation(20);
        $layout1->setPerspective(15);                                              
        $layout1->setRightAngleAxes(TRUE);                                              
        //$layout1->setShowPercent(TRUE);
        //$layout1->setShowCatName(TRUE);
        //$layout1->setShowSerName(TRUE);
        //$layout1->setShowBubbleSize(TRUE);
        //$layout1->setShowLeaderLines(TRUE);
        //$layout1->setShowLegendKey(TRUE);
        //$image = base_url().'image/app_req.jpeg';
        //$header1 = new PHPExcel_Worksheet();   
        //$header1->setHeaderFooter(PHPExcel_Worksheet_HeaderFooter::addImage($image,'A12'));
        $plotarea = new PHPExcel_Chart_PlotArea($layout1, array($series));
        $title_name = $this->lang->line('co_report').''.$this->lang->line('co_reportFrom').$rep_sdate.''.$this->lang->line('co_reportto').''.$rep_edate;
        //echo $title_name; exit;
        $title    = new PHPExcel_Chart_Title($title_name, null);  
        //$title = new PHPExcel_Chart_Title(new PHPExcel_RichText(new PHPExcel_Cell('A','1','Ttile Chart',PHPExcel_Cell_DataType::TYPE_STRING,$sheet)));
        $legend   = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, null, false);
        $xTitle   = new PHPExcel_Chart_Title($this->lang->line('course_names'));
        $yTitle   = new PHPExcel_Chart_Title($this->lang->line('no_std'));
        $chart    = new PHPExcel_Chart(
          'chart1',                                       // name
          $title,                                         // title
          $legend,                                        // legend 
          $plotarea,                                      // plotArea
          true,                                           // plotVisibleOnly
          0,                                              // displayBlanksAs
          $xTitle,                                        // xAxisLabel
          $yTitle                                         // yAxisLabel
        );   
        $start_ofChart = $end_headRow+2;                
        $chart->setTopLeftPosition('A'.$start_ofChart);
        if($total_std < 20)
        {                           
            $total_std+= 20;
            $present++; 
            //echo $total_std; exit; 
            $chart->setBottomRightPosition((string)$present."$total_std");
        }                                         
        $sheet->addChart($chart); 
    }    
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="training report.xlsx"');
    header('Cache-Control: max-age=0'); 
    $writer = PHPExcel_IOFactory::createWriter($workbook, 'Excel2007');
    $writer->setIncludeCharts(TRUE);
    ob_start();
    ob_end_clean(); 
    $writer->save('php://output');
$workbook=new PHPExcel();
对于($sh=0;$sh createSheet($sh);
$sheet=$workbook->setActiveSheetIndex($sh);
$workbook->getActiveSheet()->setTitle($this->lang->line('co_repBased_pos');
$sheet_name=$sheet->getTitle();
}
elseif($sh==1)
{//$sheet=$workbook->createSheet($sh);
$sheet=$workbook->setActiveSheetIndex($sh);
$workbook->getActiveSheet()->setTitle($this->lang->line('co_repBased_jloc');
$sheet_name=$sheet->getTitle();
}
elseif($sh==2)
{   
$sheet=$workbook->createSheet($sh);
$sheet=$workbook->setActiveSheetIndex($sh);
$workbook->getActiveSheet()->setTitle($this->lang->line('co_total_rep');
$sheet_name=$sheet->getTitle();
}
$sheet->getTabColor()->setRGB('CC000#');
//设置“轻松打印”选项的页面设置
$sheet->getPageSetup()->setOrientation(PHPExcel_工作表_页面设置::方向_肖像);
$sheet->getPageSetup()->setPaperSize(PHPExcel_工作表_页面设置::PAPERSIZE_A4);
$sheet->getPageSetup()->setFitOpage(TRUE);
$sheet->getPageSetup()->setFitToWidth(1);
$sheet->getPageSetup()->setFitToHeight(0);
//设置工作手册和工作表的保护
$workbook->getSecurity()->setLockWindows(true);
$workbook->getSecurity()->setLockStructure(true);
$workbook->getSecurity()->setWorkbookPassword(“密码”);
//设置工作表密码保护
$sheet->getProtection()->setSheet(TRUE);
$sheet->getProtection()->setSort(true);
$sheet->getProtection()->setInsertRows(true);
$sheet->getProtection()->setInsertColumns(true);
$sheet->getProtection()->setFormatCells(true);
$sheet->getProtection()->setSelectUnlockedCells(false);
$sheet->getProtection()->setSelectLockedCells(true);
$sheet->getProtection()->setObjects(true);
$sheet->getProtection()->setPassword(“密码”);
$styleheaders=数组(
“边框”=>数组(
“allborders”=>数组(
'style'=>PHPExcel\u style\u Border::Border\u THIN,
'color'=>数组('argb'=>'#dbb7'),
),
),
'字体'=>数组(
'bold'=>正确,
“大小”=>20
),
'填充'=>数组(
'type'=>PHPExcel\u Style\u Fill::Fill\u GRADIENT\u LINEAR,
'startcolor'=>阵列(
'argb'=>'E9E9E9',
),
“endcolor”=>数组(
'argb'=>'E9E9E9',
),
),
“对齐”=>数组(
“水平”=>PHPExcel\u样式\u对齐::水平\u中心
),   
);
如果($this->mng\u auth->get\u language()
{
$sheet->setRightToLeft(假);
}
其他的
{  
$sheet->setRightToLeft(真);
}
$start_HEADLOW=$total_rows+1;
$end_headlow=$total_rows+2;
//设置图表区域
$j='B';
对于($k=0;$k<$course\u count;$k++)
{   
$m=$k;
$col=$j;
$j=chr(作战需求文件($j)+$m);
}  
$total_std=0;
foreach($chart\u total\u stdof课程为$row)
{
如果($row[1]>$total\u std)
{
$total_std=$row[1];
}
}  
$input_string=$col;
$base_值=64;
$decimal_值=26;
$column_index=0;
对于($d=0;$dapplyFromArray($styleheaders);
如果($sh==0)
{
$sheet->setCellValue('A'.$startèU HEADLOW,'.èèèèèèèèèèèèèïèèèèí;
}
elseif($sh==1)
{
$sheet->setCellValue('A'.$startæu Headlow,\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\);
}
elseif($sh==2)
{
$sheet->setCellValue('A'$startÔU HEADLOW,'NIGHææÛÛÛÛÛÛÛÔÏÛÛÛÛÛÛÛÛÛÛ;
}
$sheet->getStyle('A'.$start\U headRow'.:'.$present.$end\U headRow)->getAlignment()->setWrapText(true);
//设置合并单元格从0开始
$sheet->mergeCellsByColumnAndRow(0,$start\u headlow,$column\u index,$end\u headlow);
如果($sh==0)
{
$sheet->fromArray(
$course\u rep,
无效的
“B”。$startRow_num
);
}