PHP将公式添加到xlsxwriter excel中的列

我可以把= MAX(K2,L2,M2,O2,P2,Q2,N2)在一个xlsxwriter没有问题,但我不能让它改变每行(即= MAX(K2,L2,M2 ,O2,P2,Q2,N2)

所以如果我有一千行,它将会在单元格F1000中(即= MAX(K1000,L1000,M1000,O1000,P10002,Q2,N1000))(BestPrice是F行)

这是我在PHP 5.3.24的代码

$resulted[$y] = array('ISBN' => $isbn, 'Quantity' => $qty, 'Title' => $shortTitle, 'ItemAmount'=>$amount, 'Best'=>$best, 'BestPrice'=> '=MAX(K2,L2,M2,O2,P2,Q2,N2)', 'Difference'=>'=E-H', 'AvaQty'=>$AvaQty, 'LastDate'=>$LastDate, 'LastPrice'=>$LastPrice, ); $y++; } $header = array('ISBN' => 'integer', 'Quantity' => 'integer', 'Title' => 'string', 'Item_Amount'=>'price', 'Best' =>'string', 'BestPrice'=> 'price', 'Difference'=>'price', 'AvaQty'=>'integer', 'LastDate'=>'date', 'LastPrice'=>'price', ); $col_options=array('widths'=> array(40, 10,40,10)); $writer = new XLSXWriter(); $writer->writeSheetHeader('Name', $header, $col_options); foreach($resulted as $row) $writer->writeSheetRow('Name', $row); $writer->writeToFile("../My".$tracking .".xlsx"); 

有什么想法吗

你只需要使用一个variables来跟踪你的行号。 根据$y是什么,你可以使用它。 如果没有,这样的事情将起作用:

 $y = 0; $row = 2; foreach($book_list as $book){ //Assuming you have some kind of book list you're iterating over... //Doing some stuff (eg setting those variables you use in the array) $resulted[$y] = array('ISBN' => $isbn, 'Quantity' => $qty, 'Title' => $shortTitle, 'ItemAmount'=>$amount, 'Best'=>$best, 'BestPrice'=> "=MAX(K{$row},L{$row},M{$row},O{$row},P{$row},Q{$row},N{$row})", //Note the change in this line. 'Difference'=>'=E-H', 'AvaQty'=>$AvaQty, 'LastDate'=>$LastDate, 'LastPrice'=>$LastPrice, ); $y++; $row++; } 

我怀疑你可以使用$y而不是一个单独的variables,假设它只是一个0索引计数器,你可以在循环迭代开始时做$row = $y+2 。 无论如何,这应该指向正确的方向