使用phpexcel导出excel表以设置行和列

i have the database

roll_no

201261001

201261002

201261003

201261004

201261005

201261006

201261007

201261008

I need to export to excel sheet in 6 rows and 12 columns format

output

201261001

201261002

201261003

201261004

201261005 201261008

201261006 201261007

The remaining cells should be empty

Something like the following will iterate over the resultset from your database query, and write to the appropriate row/column in the spreadsheet. It uses the modulus operator to determine when a column has been filled to 6 rows, and then increments the column and resets the row number ready for the next record.

$row = 1;
$column = 'A';
$record = 0;
while ($data = mysqli_fetch_assoc) {
    if (($record > 0) && ($record % 6 == 0)) {
        $row = 1;
        $column++;
    }
    $objPHPExcel->getActiveSheet()->getCell($column.$row)->setValue($data['roll_no']);
    $row++;
    $record++;
}