-1

我有一个以下数组,需要使用phpexcel写入excel我可以直接将数组写入excel。

array(9) {
  [0] =>
  array(4) {
    'hostname' =>
    string(7) 'Dibeesh'
    'hostemail' =>
    string(14) 'xxx@xx.in'
    'hostcity' =>
    string(12) 'Kochi, India'
    'host' =>
    string(4) 'host'
  }
  [1] =>
  array(4) {
    'inviteename' =>
    string(5) 'Test1'
    'inviteeemail' =>
    string(12) 'xxx@xx.in'
    'inviteecity' =>
    string(12) 'Kochi, India'
    'invitee' =>
    string(7) 'invitee'
  }
  [2] =>
  array(4) {
    'inviteename' =>
    string(8) 'Nishanth'
    'inviteeemail' =>
    string(18) 'xxx@xx.com'
    'inviteecity' =>
    string(5) 'Aluva'
    'invitee' =>
    string(7) 'invitee'
  }
  [3] =>
  array(4) {
    'inviteename' =>
    string(9) 'Lal Mohan'
    'inviteeemail' =>
    string(10) 'xxx@xx.in'
    'inviteecity' =>
    string(12) 'Kochi, India'
    'invitee' =>
    string(7) 'invitee'
  }
  [4] =>
  array(4) {
    'inviteename' =>
    string(6) 'Mahesh'
    'inviteeemail' =>
    string(14) 'xxx@xxx.com'
    'inviteecity' =>
    string(10) 'Tvm, INdia'
    'invitee' =>
    string(7) 'invitee'
  }
  [5] =>
  array(4) {
    'hostname' =>
    string(9) 'Lal Mohan'
    'hostemail' =>
    string(10) 'xxx@xx.in'
    'hostcity' =>
    string(12) 'Kochi, India'
    'host' =>
    string(4) 'host'
  }
  [6] =>
  array(4) {
    'inviteename' =>
    string(6) 'Arshad'
    'inviteeemail' =>
    string(13) 'xxx@xx.in'
    'inviteecity' =>
    string(12) 'Kochi, India'
    'invitee' =>
    string(7) 'invitee'
  }
  [7] =>
  array(4) {
    'inviteename' =>
    string(5) 'Joyal'
    'inviteeemail' =>
    string(12) 'xxx@xx.in'
    'inviteecity' =>
    string(12) 'Kochi, India'
    'invitee' =>
    string(7) 'invitee'
  }
  [8] =>
  array(4) {
    'inviteename' =>
    string(7) 'Dibeesh'
    'inviteeemail' =>
    string(14) 'xxx@xx.in'
    'inviteecity' =>
    string(12) 'Kochi, India'
    'invitee' =>
    string(7) 'invitee'
  }
}

如何使用 phpexcel 将其写入 excel?请帮助我以下列格式写入 excel Excel格式

4

1 回答 1

1

是的!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 PHPExcel_Exception
 * @return PHPExcel_Worksheet
 */

例如

$objPHPExcel->getActiveSheet()->fromArray(
    $myArray,
    NULL,
    'A2'
);

虽然数组需要反映您正在写入的行和列,但您的数组将(就目前而言)写入 9 行,每行 4 列....如果您希望将数组中的 3 行写入每行你的 Excel,那么你需要重新组织你的数组以匹配它

于 2014-01-29T07:55:18.110 回答