0

How to set the first row in phpexcel, i really new for this stuff when i export file using phpexcel the result always start with A1 row ! how to skip it..? i want to start insert my data in other row like A4 or any else. this is what i have in my code (update full code)

 function theme_views_data_export_xlsx_body(&$vars) {
 _views_data_export_header_shared_preprocess($vars);
 _views_data_export_body_shared_preprocess($vars);
 $complete_array = array_merge(array($vars['header']), $vars['themed_rows']);
  // Decode HTML entities.
  foreach ($complete_array as &$row) {
  foreach ($row as &$value) {
  $value = decode_entities($value);
  }
}

 // Load PHPExcel library.
 $library = libraries_load('PHPExcel');

 // Create PHPExcel spreadsheet and add rows to it.


  $objPHPExcel = new PHPExcel();
  $objPHPExcel->setActiveSheetIndex(0);
  $objPHPExcel->getActiveSheet()->setCellValue('F1', '=E2');
  $objPHPExcel->getActiveSheet()->fromArray($complete_array);
  $objPHPExcel->getActiveSheet()->setTitle('Nilai Ukk');
  $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
  // $objPHPExcel->getActiveSheet()->getStyle('A2')->getAlignment()-
 >setWrapText(true);
   $excel_type = 'excel2007';
   switch ($excel_type) {
   default:
   case 'excel2007':
  $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
  break;
 }

 // Catch the output of the spreadsheet.
  ob_start();

  $objWriter->save('php://output');
  $excelOutput = ob_get_clean();
   return $excelOutput;
   }

thanks

2 Answers2

0

According to Mark Baker you can do the following to skip first header row:

$highestRow = $sheet->getHighestRow(); 
$highestColumn = $sheet->getHighestColumn();

$sheetData = $sheet->rangeToArray(
    'A2:' . $highestColumn . $highestRow,
    NULL,TRUE,FALSE
);

See this: PHPExcel toArray skip first header row

Oussama Ben Ghorbel
  • 2,132
  • 4
  • 17
  • 34
0

You just need to skip row 1. don't set entire row field as NULL

You need to define a variable

$row = 2; // skip first row set direct value 2

Now you can use that variable in setCellValue("A{$row}", 'Your_Value'); it will set Your_Value in A2 field of excel sheet.

You can increment variable $row++ to add additional data to next row.

Ravi Hirani
  • 6,511
  • 1
  • 27
  • 42