通过 PHPExcel 从 excel 文件中的数组插入值

inserting values from array in excel file through PHPExcel

我正在尝试创建一个 excel 文件,其中包含我从以下数组

中获得的值
for ($i=0;$i<=20;$i++){

for ($j=16;$j<=24;$j++){
    $data1=array($R,$C,$i,$j,'0','0'); .

我试过那样做

$objPHPExcel = new PHPExcel();
$objWorksheet = $objPHPExcel->getActiveSheet();
$objWorksheet->fromArray(
    $data1
);

使用现有的 example.However,每次我尝试 运行 这个 php 文件时,excel 停止 working.What 我应该尝试吗?

编辑

$R=1;
$C=0.7;


for ($i=0;$i<=20;$i++){

for ($j=16;$j<=24;$j++){
    $data1[]=array($R,$C,$i,$j,'0','0');

    $objPHPExcel = new PHPExcel();
$objWorksheet = $objPHPExcel->getActiveSheet();
$objWorksheet->fromArray(
    array(
        $data1)

);

    }}
$objPHPExcel = new PHPExcel();
$objWorksheet = $objPHPExcel->getActiveSheet();
$R=1; 
$C=0.7; 
for ($i=0;$i<=20;$i++){ 
    for ($j=16;$j<=24;$j++){ 
        $data1[]=array($R,$C,$i,$j,'0','0'); 
    }
}
$objWorksheet->fromArray( $data1 );

//  Set the Labels for each data series we want to plot
//      Datatype
//      Cell reference for data
//      Format Code
//      Number of datapoints in series
//      Data values
//      Data Marker
$dataSeriesLabels = array(
    new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C', NULL, 1),   //  'Budget'
    new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D', NULL, 1),   //  'Forecast'
    new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$E', NULL, 1),   //  'Actual'
);
//  Set the X-Axis Labels
//      Datatype
//      Cell reference for data
//      Format Code
//      Number of datapoints in series
//      Data values
//      Data Marker
$xAxisTickValues = array(
    new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A:$B', NULL, 12),    //  Q1 to Q4 for 2010 to 2012
);
//  Set the Data values for each data series we want to plot
//      Datatype
//      Cell reference for data
//      Format Code
//      Number of datapoints in series
//      Data values
//      Data Marker
$dataSeriesValues = array(
    new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C:$C', NULL, 12),
    new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D:$D', NULL, 12),
    new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$E:$E', NULL, 12),
);

//  Build the dataseries
$series = new PHPExcel_Chart_DataSeries(
    PHPExcel_Chart_DataSeries::TYPE_BARCHART,       // plotType
    PHPExcel_Chart_DataSeries::GROUPING_CLUSTERED,  // plotGrouping
    range(0, count($dataSeriesValues)-1),           // plotOrder
    $dataSeriesLabels,                              // plotLabel
    $xAxisTickValues,                               // plotCategory
    $dataSeriesValues                               // plotValues
);
//  Set additional dataseries parameters
//      Make it a vertical column rather than a horizontal bar graph
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);

//  Set the series in the plot area
$plotArea = new PHPExcel_Chart_PlotArea(NULL, array($series));
//  Set the chart legend
$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_BOTTOM, NULL, false);

$title = new PHPExcel_Chart_Title('Test Grouped Column Chart');
$xAxisLabel = new PHPExcel_Chart_Title('Financial Period');
$yAxisLabel = new PHPExcel_Chart_Title('Value ($k)');


//  Create the chart
$chart = new PHPExcel_Chart(
    'chart1',       // name
    $title,         // title
    $legend,        // legend
    $plotArea,      // plotArea
    true,           // plotVisibleOnly
    0,              // displayBlanksAs
    $xAxisLabel,    // xAxisLabel
    $yAxisLabel     // yAxisLabel
);

//  Set the position where the chart should appear in the worksheet
$chart->setTopLeftPosition('G2');
$chart->setBottomRightPosition('P20');

//  Add the chart to the worksheet
$objWorksheet->addChart($chart);


// Save Excel 2007 file
echo date('H:i:s') , " Write to Excel2007 format" , EOL;
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->setIncludeCharts(TRUE);
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));