Answer the question
In order to leave comments, you need to log in
How to populate multiple columns in PHPExcel?
Hello, please tell me, I am generating an Excel file, data from the database should be inserted into it, and the fact is that this Excel should have 291 columns. Here is an option to do this:
$active_sheet2->setCellValue('A1',"yellowline1");
$active_sheet2->setCellValue('B1',"yellowline2");
$active_sheet2->setCellValue('C1',"yellowline4");
$active_sheet2->setCellValue('D1',"yellowline6");
Answer the question
In order to leave comments, you need to log in
You have received an array of data, written it into a variable, and then:
for($i = 1; $i < count($yourData); $i++){
$active_sheet2->setCellValue('A' . $i,"yellowline1");
$active_sheet2->setCellValue('B' . $i,"yellowline2");
$active_sheet2->setCellValue('C' . $i,"yellowline4");
$active_sheet2->setCellValue('D' . $i,"yellowline6");
}
$it = 1;
foreach ($results as $result) {
$active_sheet2->setCellValue('A'.$it, $result->yellowline1);
$active_sheet2->setCellValue('B'.$it, $result->yellowline2);
$active_sheet2->setCellValue('C'.$it, $result->yellowline3);
$active_sheet2->setCellValue('D'.$it, $result->yellowline4);
$it++;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question