【问题标题】:How can I set 2D array data to a range?如何将二维数组数据设置为范围?
【发布时间】:2018-09-28 10:17:50
【问题描述】:

我知道如何将 2D 数组从全新的行附加到工作表。

但在我的情况下,我需要将二维数组数据设置为下面的“B1:G3”范围。

二维数组数据:

[
   ["2018-01","2018-02","2018-03",....,"2018-12","Total"],
   [100,200,300,....,400,2000],
   [10,20,33,....,44,300]
]

如何做到这一点。
对了,我用的是maatwebsite/excel 2.1.0

感谢您的帮助。

【问题讨论】:

    标签: maatwebsite-excel laravel-excel


    【解决方案1】:

    最后我在 Laravel Excel 的源代码中找到了这个。

    我可以在下面使用:

    $sheet->fromArray($2DArrayData, null, 'B1', true, false);
    

    参数含义:

        /**
     * Fill worksheet from values in array
     *
     * @param array       $source               Source array
     * @param mixed       $nullValue            Value in source array that stands for blank cell
     * @param bool|string $startCell            Insert array starting from this cell address as the top left coordinate
     * @param boolean     $strictNullComparison Apply strict comparison when testing for null values in the array
     * @param bool        $headingGeneration
     * @throws PHPExcel_Exception
     * @return LaravelExcelWorksheet
     */
    public function fromArray($source = null, $nullValue = null, $startCell = 'A1', $strictNullComparison = false, $headingGeneration = true)
    {
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-04
      • 2014-07-01
      • 2021-08-08
      • 1970-01-01
      • 1970-01-01
      • 2020-01-18
      • 2020-03-09
      • 1970-01-01
      相关资源
      最近更新 更多