如何在phpspreadsheet中使用Linest函数?

时间:2019-06-09 01:50:09

标签: php phpspreadsheet

我正在使用33_Chart_create_scatter.php生成XY散点图。我即将完成。我所剩下的就是引入linet函数。有人可以提供有关在phpspreadsheet中使用linet的一些代码吗?

我做了很多Google,没有运气。大量访问phpspreadsheet文档。有很多信息,我听不懂。到目前为止,我还没有使用过类,所以我不知道如何构成代码来与下面的代码部分中显示的类进行对话? 这是我使用的数据:     $ xAxisTickValues = [     new DataSeriesValues(DataSeriesValues :: DATASERIES_TYPE_NUMBER,'工作表!$ C $ 1:$ C $ 18',null,18),     new DataSeriesValues(DataSeriesValues :: DATASERIES_TYPE_NUMBER,'工作表!$ F $ 1:$ F $ 18',null,18)    [][1];

\PhpOffice\PhpSpreadsheet\Calculation\Statistical::LINEST


    'LINEST' => [
        'category' => Category::CATEGORY_STATISTICAL,
        'functionCall' => [Statistical::class, 'LINEST'],
        'argumentCount' => '1-4',
    ],

公共静态函数LINEST($ yValues,$ xValues = null,$ const = true,$ stats = false)     {         $ const =($ const ===空) true:(bool)函数:: flattenSingleValue($ const);         $ stats =($ stats ===空) false:(布尔)Function :: flattenSingleValue($ stats);         如果($ xValues === null){             $ xValues = range(1,count(Functions :: flattenArray($ yValues)));         }

当然,我还没有结果。我的期望是返回返回的最细统计。

一个星期没有人添加任何东西。这是我那一周完成的工作:通过对33 Chart create scatter中的数据运行公式wizzard / linest,得到了以下两个数据数组。我制作的图表。因此,我知道从phpspreadsheet / linest中获取的数据是什么。

Six foot data array
0.798178535 18.35040936
0.012101577 0.241020964
0.996335545 0.53274435
4350.269442 16
1234.67843  4.541064671

Ten foot data array
0.819287926 16.98988304
0.007826008 0.15586663
0.998542214 0.344522174
10959.54502 16
1300.848983 1.899128449

setCellValue, puts the formula in cell A32 and  cell A32 displays the first number from the Six foot data array above.

$helper->log, gives the following output. The getCell gives the linest     formula in the cell.
getCalculatedValue gives the Last value in the Six foot data array above.

    19:12:47 Write Xlsx format to 33_Chart_create_scatter.xlsx in 0.0138  seconds
    19:12:47 Value of linest six foot from getCell(A32) : =LINEST(D1:D18 ,    C1:C18 , TRUE, TRUE)
    19:12:47 Value of linest six foot used getCalculatedValue get cell A32 : 4.5410646714826
    19:12:47 Value of linest ten foot from getCell(A42) : =LINEST(G1:G18 ,  F1:F18 , TRUE, TRUE)
   19:12:47 Value of linest ten foot used getCalculatedValue get cell A42 : 1.8991284485724

我尝试了

   $spreadsheet->getActiveSheet()->fromArray($linestSix ,null,'C32'); 

与上述setCellValue相同。 单击此链接enter link description here,以查看运行代码生成图表时的浏览器输出,33 Chart create scatter。在[Worksheet!A32]的对象中向下走大约75行,有我的数据,但是,如何从那里得到数据呢?我是从下面$ linest6的print_r中得到的。

    $linest6 = $spreadsheet->getActiveSheet()->setCellValue('A32',     '=LINEST(D1:D18 , C1:C18 , TRUE, TRUE)');

   echo 'The six foot data array : <br>';
   echo '<pre>';
   print_r($linest6);
   echo '</pre>';

有人,也许是马克·贝克(Mark Ba​​ker),可以帮我从linet中获取统计信息,就像我在公式向导中所描述的一样吗?谢谢。

1 个答案:

答案 0 :(得分:0)

我终于明白了!!多次前往Google。回顾如何从类函数中检索数组。这是我的最终脚本。

    $stats = new Statistical();
$statArr6 = $stats->LINEST($dataArraySixY, $dataArraySixX, TRUE, TRUE);
$statArr10 = $stats->LINEST($dataArrayTenY, $dataArrayTenX, TRUE, TRUE);


$worksheet->fromArray(
    $statArr6, 
    NULL, 
    "C22");
$worksheet->fromArray(
$statArr10,
NULL,
'C32'
);

我还有更多信息可以显示,但是我有数组。