【问题标题】:Updating Cell References in copied rows in PHPExcel (PHPSpreadsheet)在 PHPExcel (PHPSpreadsheet) 中更新复制行中的单元格引用
【发布时间】:2017-05-15 11:31:10
【问题描述】:

我正在使用以下代码复制 PHPSpreadsheet 中的行。但是,我想更改复制行中的公式引用以反映新的行号。 (例如(A1-B1)、(A2-B2)、A3-B3 等)有什么建议吗?

function copyRowFull(&$ws_from, &$ws_to, $row_from, $row_to) {
  $ws_to->getRowDimension($row_to)->setRowHeight($ws_from->getRowDimension($row_from)->getRowHeight());
  $lastColumn = $ws_from->getHighestColumn();
  ++$lastColumn;
  for ($c = 'A'; $c != $lastColumn; ++$c) {
    $cell_from = $ws_from->getCell($c.$row_from);
    $cell_to = $ws_to->getCell($c.$row_to);
    $cell_to->setXfIndex($cell_from->getXfIndex()); 
    $cell_to->setValue($cell_from->getValue());
  }
}

【问题讨论】:

    标签: php phpexcel phpexcel-1.8.0


    【解决方案1】:

    您应该能够使用PHPExcel_ReferenceHelper 类的updateFormulaReferences() 方法来更新公式字符串中的单元格引用

    /**
     * Update references within formulas
     *
     * @param    string    $pFormula    Formula to update
     * @param    int        $pBefore    Insert before this one
     * @param    int        $pNumCols    Number of columns to insert
     * @param    int        $pNumRows    Number of rows to insert
     * @param   string  $sheetName  Worksheet name/title
     * @return    string    Updated formula
     * @throws    PHPExcel_Exception
     */
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-23
      • 2022-01-09
      • 2018-07-20
      • 1970-01-01
      • 1970-01-01
      • 2018-06-17
      • 1970-01-01
      相关资源
      最近更新 更多