2012-12-13 122 views
2

我使用PHPExcel並獲得以下錯誤創建圖表上:錯誤創建圖表[phpexcel]

致命錯誤:調用一個成員函數cellExists()非對象上在/ opt/LAMPP/htdocs中/ scgcc/Classes/PHPExcel/Calculation.php on line 3241

這個錯誤發生在$ objWorksheet-> addChart($ chart);

下面

圖表可變回報:

PHPExcel_Chart對象 ( [_name:PHPExcel_Chart:私人] => chart1 [_Worksheet:PHPExcel_Chart:私人] => [_title:PHPExcel_Chart:私人] => PHPExcel_Chart_Title對象 ( [_caption:PHPExcel_Chart_Title:私人] =>測試堆疊折線圖表 [_layout:PHPExcel_Chart_Title:私人] => )

[_legend:PHPExcel_Chart:private] => PHPExcel_Chart_Legend Object 
    (
     [_position:PHPExcel_Chart_Legend:private] => tr 
     [_overlay:PHPExcel_Chart_Legend:private] => 
     [_layout:PHPExcel_Chart_Legend:private] => 
    ) 

[_xAxisLabel:PHPExcel_Chart:private] => 
[_yAxisLabel:PHPExcel_Chart:private] => PHPExcel_Chart_Title Object 
    (
     [_caption:PHPExcel_Chart_Title:private] => Value ($k) 
     [_layout:PHPExcel_Chart_Title:private] => 
    ) 

[_plotArea:PHPExcel_Chart:private] => PHPExcel_Chart_PlotArea Object 
    (
     [_layout:PHPExcel_Chart_PlotArea:private] => 
     [_plotSeries:PHPExcel_Chart_PlotArea:private] => Array 
      (
       [0] => PHPExcel_Chart_DataSeries Object 
        (
         [_plotType:PHPExcel_Chart_DataSeries:private] => lineChart 
         [_plotGrouping:PHPExcel_Chart_DataSeries:private] => stacked 
         [_plotDirection:PHPExcel_Chart_DataSeries:private] => 
         [_plotStyle:PHPExcel_Chart_DataSeries:private] => 
         [_plotOrder:PHPExcel_Chart_DataSeries:private] => Array 
          (
           [0] => 0 
           [1] => 1 
           [2] => 2 
           [3] => 3 
          ) 

         [_plotLabel:PHPExcel_Chart_DataSeries:private] => Array 
          (
           [0] => PHPExcel_Chart_DataSeriesValues Object 
            (
             [_dataType:PHPExcel_Chart_DataSeriesValues:private] => String 
             [_dataSource:PHPExcel_Chart_DataSeriesValues:private] => Worksheet!$B$1 
             [_formatCode:PHPExcel_Chart_DataSeriesValues:private] => 
             [_marker:PHPExcel_Chart_DataSeriesValues:private] => 
             [_pointCount:PHPExcel_Chart_DataSeriesValues:private] => 1 
             [_dataValues:PHPExcel_Chart_DataSeriesValues:private] => Array 
              (
              ) 

            ) 

           [1] => PHPExcel_Chart_DataSeriesValues Object 
            (
             [_dataType:PHPExcel_Chart_DataSeriesValues:private] => String 
             [_dataSource:PHPExcel_Chart_DataSeriesValues:private] => Worksheet!$C$1 
             [_formatCode:PHPExcel_Chart_DataSeriesValues:private] => 
             [_marker:PHPExcel_Chart_DataSeriesValues:private] => 
             [_pointCount:PHPExcel_Chart_DataSeriesValues:private] => 1 
             [_dataValues:PHPExcel_Chart_DataSeriesValues:private] => Array 
              (
              ) 

            ) 

           [2] => PHPExcel_Chart_DataSeriesValues Object 
            (
             [_dataType:PHPExcel_Chart_DataSeriesValues:private] => String 
             [_dataSource:PHPExcel_Chart_DataSeriesValues:private] => Worksheet!$D$1 
             [_formatCode:PHPExcel_Chart_DataSeriesValues:private] => 
             [_marker:PHPExcel_Chart_DataSeriesValues:private] => 
             [_pointCount:PHPExcel_Chart_DataSeriesValues:private] => 1 
             [_dataValues:PHPExcel_Chart_DataSeriesValues:private] => Array 
              (
              ) 

            ) 

           [3] => PHPExcel_Chart_DataSeriesValues Object 
            (
             [_dataType:PHPExcel_Chart_DataSeriesValues:private] => String 
             [_dataSource:PHPExcel_Chart_DataSeriesValues:private] => Worksheet!$E$1 
             [_formatCode:PHPExcel_Chart_DataSeriesValues:private] => 
             [_marker:PHPExcel_Chart_DataSeriesValues:private] => 
             [_pointCount:PHPExcel_Chart_DataSeriesValues:private] => 1 
             [_dataValues:PHPExcel_Chart_DataSeriesValues:private] => Array 
              (
              ) 

            ) 

          ) 

         [_plotCategory:PHPExcel_Chart_DataSeries:private] => Array 
          (
           [0] => PHPExcel_Chart_DataSeriesValues Object 
            (
             [_dataType:PHPExcel_Chart_DataSeriesValues:private] => String 
             [_dataSource:PHPExcel_Chart_DataSeriesValues:private] => Worksheet!$A$2:$A$6 
             [_formatCode:PHPExcel_Chart_DataSeriesValues:private] => 
             [_marker:PHPExcel_Chart_DataSeriesValues:private] => 
             [_pointCount:PHPExcel_Chart_DataSeriesValues:private] => 5 
             [_dataValues:PHPExcel_Chart_DataSeriesValues:private] => Array 
              (
              ) 

            ) 

          ) 

         [_smoothLine:PHPExcel_Chart_DataSeries:private] => 
         [_plotValues:PHPExcel_Chart_DataSeries:private] => Array 
          (
           [0] => PHPExcel_Chart_DataSeriesValues Object 
            (
             [_dataType:PHPExcel_Chart_DataSeriesValues:private] => Number 
             [_dataSource:PHPExcel_Chart_DataSeriesValues:private] => Worksheet!$B$2:$B$6 
             [_formatCode:PHPExcel_Chart_DataSeriesValues:private] => 
             [_marker:PHPExcel_Chart_DataSeriesValues:private] => 
             [_pointCount:PHPExcel_Chart_DataSeriesValues:private] => 5 
             [_dataValues:PHPExcel_Chart_DataSeriesValues:private] => Array 
              (
              ) 

            ) 

           [1] => PHPExcel_Chart_DataSeriesValues Object 
            (
             [_dataType:PHPExcel_Chart_DataSeriesValues:private] => Number 
             [_dataSource:PHPExcel_Chart_DataSeriesValues:private] => Worksheet!$C$2:$C$6 
             [_formatCode:PHPExcel_Chart_DataSeriesValues:private] => 
             [_marker:PHPExcel_Chart_DataSeriesValues:private] => 
             [_pointCount:PHPExcel_Chart_DataSeriesValues:private] => 5 
             [_dataValues:PHPExcel_Chart_DataSeriesValues:private] => Array 
              (
              ) 

            ) 

           [2] => PHPExcel_Chart_DataSeriesValues Object 
            (
             [_dataType:PHPExcel_Chart_DataSeriesValues:private] => Number 
             [_dataSource:PHPExcel_Chart_DataSeriesValues:private] => Worksheet!$D$2:$D$6 
             [_formatCode:PHPExcel_Chart_DataSeriesValues:private] => 
             [_marker:PHPExcel_Chart_DataSeriesValues:private] => 
             [_pointCount:PHPExcel_Chart_DataSeriesValues:private] => 5 
             [_dataValues:PHPExcel_Chart_DataSeriesValues:private] => Array 
              (
              ) 

            ) 

           [3] => PHPExcel_Chart_DataSeriesValues Object 
            (
             [_dataType:PHPExcel_Chart_DataSeriesValues:private] => Number 
             [_dataSource:PHPExcel_Chart_DataSeriesValues:private] => Worksheet!$E$2:$E$6 
             [_formatCode:PHPExcel_Chart_DataSeriesValues:private] => 
             [_marker:PHPExcel_Chart_DataSeriesValues:private] => 
             [_pointCount:PHPExcel_Chart_DataSeriesValues:private] => 5 
             [_dataValues:PHPExcel_Chart_DataSeriesValues:private] => Array 
              (
              ) 

            ) 

          ) 

        ) 

      ) 

    ) 

[_plotVisibleOnly:PHPExcel_Chart:private] => 1 
[_displayBlanksAs:PHPExcel_Chart:private] => 0 
[_topLeftCellRef:PHPExcel_Chart:private] => A13 
[_topLeftXOffset:PHPExcel_Chart:private] => 0 
[_topLeftYOffset:PHPExcel_Chart:private] => 0 
[_bottomRightCellRef:PHPExcel_Chart:private] => H30 
[_bottomRightXOffset:PHPExcel_Chart:private] => 10 
[_bottomRightYOffset:PHPExcel_Chart:private] => 10 

請回復我,它很緊急。

感謝

+1

我一直錯誤的解決問題,而不是圖表沒有顯示你的所有單元格引用中某處的任何值 – DeveloperPHP

+0

,你引用的是沒有按小區在PHPExcel模型中不存在 –

+1

非常感謝您的回覆,我一直在解決這個問題。但是現在圖表線條並未出現,因爲您可以參考截圖@ http://uvresins.net/images/xls.png 和我的圖表變量與上面提到的相同。我不知道我錯過了什麼。你可以給我任何解決方案/提示。請幫忙。 – DeveloperPHP

回答

2

我的代碼是下面,你可以看到下面我使用的鍵部分,因爲我是從生成數據庫陣列值。

我正在顯示代碼的簡化形式,實際上實際的代碼有太多未知的東西4 u。我正在生成5張工作簿。

$ objWorksheet = $ objPHPExcel-> getActiveSheet();

$ objWorksheet-> fromArray( 陣列 (

[0] => Array 
    (
     [0] => 
     [1] => 12/2011 
     [2] => 01/2012 
     [3] => 02/2012 
    ) 

[1] => Array 
    (
     [0] => QATAR 
     [1] => 102.77 
     [2] => 100 
     [3] => 102.13 
    ) 

[2] => Array 
    (
     [0] => SAUDI ARABIA 
     [1] => 102.74 
     [2] => 100 
     [3] => 98.22 
    ) 

[3] => Array 
    (
     [0] => KUWAIT 
     [1] => 94.82 
     [2] => 100 
     [3] => 102.28 
    ) 

[4] => Array 
    (
     [0] => U.A.E. 
     [1] => 101.22 
     [2] => 100 
     [3] => 99.94 
    ) 

[5] => Array 
    (
     [0] => OMAN 
     [1] => 101.73 
     [2] => 100 
     [3] => 100.42 
    ) 

) );

$ dataseriesLabels =(

[0] => new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1,null, 1) 
[1] => new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1,null, 1) 
[2] => new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1,null, 1) 

);

$ xAxisTickValues =(

[0] =>新PHPExcel_Chart_DataSeriesValues( '字符串',「工作表!$ A $ 2:$ A $ 6',null,5) );

$ dataSeriesValues =陣列 (

[0] => new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$6',null,5) 
[1] => new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$6,null,5) 
[2] => new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$6,null,5) 

);

$系列=新PHPExcel_Chart_DataSeries(

PHPExcel_Chart_DataSeries::TYPE_LINECHART,  
PHPExcel_Chart_DataSeries::GROUPING_STACKED,  
range(0, count($dataSeriesValues)-1),   
$dataseriesLabels,        
$xAxisTickValues,        
$dataSeriesValues        

);

$ plotarea = new PHPExcel_Chart_PlotArea(null,array($ series));

$ legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend :: POSITION_TOPRIGHT,null,false);

$ title = new PHPExcel_Chart_Title('Test Stacked Line Chart'); $ yAxisLabel = new PHPExcel_Chart_Title('Value($ k)');

$圖=新PHPExcel_Chart( 'chart1',//名 $標題,標題// $ 傳說,傳說// $ plotarea,// plotArea 真,// plotVisibleOnly 0,// displayBlanksAs null,// xAxisLabel $ yAxisLabel // yAxisLabel );

$ chart-> setTopLeftPosition('A7'); $ chart-> setBottomRightPosition('H20');

$ objWorksheet-> addChart($ chart);

$ objWriter = PHPExcel_IOFactory :: createWriter($ objPHPExcel,'Excel2007'); $ objWriter-> setIncludeCharts(TRUE);

請告訴我,M I缺少什麼.....