2012-02-08 80 views
2

我正在写一个PHP脚本生成Excel通过使用PHP的Excel报表Excel中的拖曳。我想这样做是允许用户指定细胞的contants可以“拖动”。我的意思是要利用或模拟Excel中的该功能,可以让用户选择一个或多个小区,为了产生相邻单元格的内容拖动的内容。我无法找到关于此的任何信息。我是否需要在脚本中生成单元格的内容,或者是否存在PHP excel的一些鬼鬼祟祟的功能,可以为我做到这一点?我会假设前者,但我对PHPExcel很新,所以想在潜入之前确定。PhpExcel:如何模拟单元格内容

+0

你怎么想实现这个?你想允许用户这样做在一个HTML表?你想在哪里发生“拖动”,以及用户如何与它进行交互? – DaveRandom 2012-02-08 10:40:43

回答

4

PHPExcel没有“偷偷摸摸”的功能,您必须为每个单元格设置内容,但有一对夫妇的方法,可以帮助在一个单一的通话设置几个单元格的值。

如果你谈论的是直线数据内容,你可以指定一个起始细胞,并通过数值数组到工作表的fromArray()方法:

* Fill worksheet from values in array 
* 
* @param array $source     Source array 
* @param mixed $nullValue    Value in source array that stands for blank 
*            cell 
* @param 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 
* @throws Exception 
* @return PHPExcel_Worksheet 
public function fromArray($source = null, 
          $nullValue = null, 
          $startCell = 'A1', 
          $strictNullComparison = false 
         ) 

如果您需要在一系列的操作公式细胞,例如= $ A1 + $ B1 + $ C $ 1为一组行,这样$ A1和$ B1成为第二行的$ A2和$ B2,第三行的$ A3和$ B3等,那么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 
* @return string Updated formula 
* @throws Exception 
public function updateFormulaReferences($pFormula = '', 
             $pBefore = 'A1', 
             $pNumCols = 0, 
             $pNumRows = 0, 
             $sheetName = '' 
             )