首页 > 解决方案 > PHPSPREADSHEET:在 Excel 图表中显示隐藏的数据行

问题描述

我使用phpspreadsheet包含图表导出的 excel 在 libre office 上运行良好,但是当我使用 MS 打开时有空白区域图表。Excel。

问题是,我用来构建图表的数据范围是使用此代码隐藏的。

$spreadsheet->getActiveSheet()->getRowDimension($rowNow)->setVisible(false);

但这可以通过在 MS 上的设置来完成。像这样出类拔萃。 在此处输入图像描述

我使用这段代码来构建图表:

//  Build the dataseries
    $series = new PhpOffice\PhpSpreadsheet\Chart\DataSeries(
        PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_PIECHART, // plotType
        NULL, // plotGrouping
        range(0, count($dataSeriesValues) - 1), // plotOrder
        $dataSeriesLabels, // plotLabel
        $xAxisTickValues, // plotCategory
        $dataSeriesValues        // plotValues
    );
    //  Set the series in the plot area
    $plotArea = new PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series]);
    $legend = new PhpOffice\PhpSpreadsheet\Chart\Legend(PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_RIGHT, null, false);
    $title = new PhpOffice\PhpSpreadsheet\Chart\Title($t);
    $yAxisLabel = new PhpOffice\PhpSpreadsheet\Chart\Title('Value');
    // create chart
    $chart = new PhpOffice\PhpSpreadsheet\Chart\Chart(
        'chart1', // name
        $title, // title
        $legend, // legend
        $plotArea, // plotArea
        true, // plotVisibleOnly
        0, // displayBlanksAs
        null, // xAxisLabel
        $yAxisLabel  // yAxisLabel
    );

    $chart->setTopLeftPosition($pos[0]);
    $chart->setBottomRightPosition($pos[1]);

我应该向我的图表构建器添加什么属性来表示我之前提供的设置?

标签: phpphpexcelphpspreadsheetphpoffice

解决方案


推荐阅读