【问题标题】:How do I use linest function in phpspreadsheet?如何在phpspreadsheet中使用linest函数?
【发布时间】:2019-06-09 01:50:09
【问题描述】:

我正在使用 33_Chart_create_scatter.php 来生成 XY 散点图。我即将完成。我剩下的就是诱导最简单的功能。有人可以提供一些关于在phpspreadsheet中使用linest的代码吗?

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

\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 === null) ? true : (bool) 函数::flattenSingleValue($const); $stats = ($stats === null) ? false : (bool) 函数::flattenSingleValue($stats); if ($xValues === null) { $xValues = range(1, count(Functions::flattenArray($yValues))); }

当然,我还没有结果。我的期望是返回最简单的统计数据。

一周没有人添加任何东西。以下是我在那一周完成的工作:我通过对 33 Chart create scatter 中的数据运行公式 wizzard/linest 得到以下两个数据数组。我做的图表。所以,我知道我想要从 phpspreadsheet/linet 得到什么数据。

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。向下进入对象的大约 75 行到 [Worksheet!A32] ,有我的数据,但是,我如何将它从那里取出?我是从下面 $linet6 的 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 中获取统计数据,就像我在上面从公式向导中描述的一样吗?谢谢。

【问题讨论】:

  • @MarkBaker 你愿意看看这个吗?谢谢你
  • @Mark Ba​​ker 我正在尝试这个,以防你的名字和姓氏放在一起是错误的?

标签: php phpspreadsheet


【解决方案1】:

我终于明白了!!多次访问谷歌。查看如何从类函数中检索数组。这是我的最终脚本。

    $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'
);

我还有一点要显示的信息,但我有数组。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 2023-02-13
    相关资源
    最近更新 更多