douzhou7037 2016-12-31 13:04
浏览 479

在PHPExcel中复制的行中更新单元格引用(PHPSpreadsheet)

I am using the following code to copy rows in PHPSpreadsheet. However I would like to change the formula references in the copied rows to reflect the new row number. (e.g. (A1-B1), (A2-B2), A3-B3 etc.) Any suggestions?

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());
  }
}
  • 写回答

1条回答 默认 最新

  • dpxbc88022 2016-12-31 23:22
    关注

    You should be able to use the updateFormulaReferences() method of the PHPExcel_ReferenceHelper class to update cell references in a formula string

    /**
     * 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
     */
    
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿