无法以正确的格式导出xlsx或xls,所有数据都杂乱无章 [英] Can't export xlsx or xls in proper format all data are jumbled
本文介绍了无法以正确的格式导出xlsx或xls,所有数据都杂乱无章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Laravel excel库"maatwebsite/excel"
I use Laravel excel library "maatwebsite/excel"
这是我的代码
\Excel::create('Users Report' . $time, function ($excel) use ($arrUsers) {
$excel->sheet('Users', function ($sheet) use ($arrUsers) {
// Set all margins
$sheet->fromArray($arrUsers, null, 'A1', true);
$sheet->setSize('A1', 25, 18);
$sheet->setSize('B1', 25, 18);
$sheet->setSize('C1', 25, 18);
$sheet->row(1, array(
'Id', 'Name', 'Username', 'Address', 'Email'
));
// Freeze first row
$sheet->freezeFirstRow();
$sheet->cell('A1:F1', function ($cell) {
});
});
})->store('xlsx')->download('xlsx');
文件下载成功,但是当我尝试打开时显示如下
File is downloaded successfully but when I try to open is shown like follows
我推荐了以下网站,并根据他的解决方案进行了尝试,但没有得到任何解决方案. https://github.com/Maatwebsite/Laravel-Excel/issues/202
I refer following sites and tried according to his solutions but didn't get any solution. https://github.com/Maatwebsite/Laravel-Excel/issues/202
请帮帮我.
谢谢.
推荐答案
输出缓冲区中的问题已解决
Problem in output buffer solved by
ob_end_clean();
ob_start(); //At the very top of your program (first line)
\Excel::create('Users Report' . $time, function ($excel) use ($arrUsers) {
$excel->sheet('Users', function ($sheet) use ($arrUsers) {
// Set all margins
$sheet->fromArray($arrUsers, null, 'A1', true);
$sheet->setSize('A1', 25, 18);
$sheet->setSize('B1', 25, 18);
$sheet->setSize('C1', 25, 18);
$sheet->row(1, array(
'Id', 'Name', 'Username', 'Address', 'Email'
));
// Freeze first row
$sheet->freezeFirstRow();
$sheet->cell('A1:F1', function ($cell) {
});
});
})->store('xlsx')->download('xlsx');
ob_flush();
这篇关于无法以正确的格式导出xlsx或xls,所有数据都杂乱无章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文