我需要通过Laravel Excel导出具有复杂标题的工作表。我需要一个主标题和另一个子标题。
我正在这样尝试,
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
class InvoicesExport implements FromQuery, WithHeadings
{
public function headings(): array
{
return [
'Account 1' =>[
"Account 1 id",
"Account 1 branch"
],
'Account 2' =>[
"Account 2 id",
"Account 2 branch"
],
];
}
}
Run Code Online (Sandbox Code Playgroud)
但获取标题列,如 [“帐户 1 id”、“帐户 1 分支”]
有没有办法存档这个任务?
我有一个金额列,当数字没有小数时我想设置整数格式,当数字有小数时设置双精度格式。在这两种方式中,我想为数字添加分隔符。目前,我使用bindValue,但Excel单元格不知道金额列是数字格式,我应该选择它们并将它们转换为数字。
public function bindValue(Cell $cell, $value)
{
if (is_int($value)) {
$cell->setValueExplicit($value, '#,##0');
return true;
}else if (is_double($value)) {
$cell->setValueExplicit($value, '#,##0.00');
return true;
}else{
$cell->setValueExplicit($value, DataType::TYPE_STRING);
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
我该如何修复它?
excel number-formatting laravel laravel-excel maatwebsite-excel
对不起,我想用laravel-excel导出我的报告.这是控制器:
public function getExcelfile(){
$users = UserService::findAllPublic();
$total = UserService::count();
$total_with_photo = UserService::countWithPhoto();
Excel::create('excelfile', function($excel) use ($users, $total, $total_with_photo) {
$excel->sheet('Excel', function($sheet) use ($users, $total, $total_with_photo) {
$sheet->loadView('report.excel')->with("users", $users)->with("total", $total)->with("total_with_photo", $total_with_photo);
});
})->export('xls');
}
Run Code Online (Sandbox Code Playgroud)
这是位于报告文件夹的excel.blade.php:
<html> <body> Total Registered User : {{$total}} Total Registered User With Photo : {{$total_with_photo}} <h1>Data User</h1> @if(!empty($users)) <table class="table table-striped table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Photo</th>
<th>Nama</th>
<th>Struck</th>
<th>Email</th>
<th>Phone</th>
<th>FB ID</th>
<th>Timestamp</th>
<th>Publish</th>
</tr>
</thead>
@foreach ($users as $row)
<tr>
<td>{{$row->id}}</td>
<td><img src="{{URL::asset('assets/images/upload/' . $row->photo)}}" …Run Code Online (Sandbox Code Playgroud) 我正在尝试将Laravel Excel(http://www.maatwebsite.nl/laravel-excel/docs)软件包安装到我的Laravel 5上.这是我到目前为止所做的:
"maatwebsite/excel": "2.*"到我的要求,composer update
完成就好了,我有所有的包文件'Maatwebsite\Excel\ExcelServiceProvider',到提供者数组'Excel' => 'Maatwebsite\Excel\Facades\Excel',到别名数组这是问题 - 当我尝试跑步时php artisan vendor:publish,它会告诉我Nothing to publish for tag [].
当我使用php artisan tinker并运行时$excel = App::make('excel'),它会告诉我ReflectionException with message 'Class excel does not exist'.
我究竟做错了什么?
我正在使用这个包用Laravel生成excel文档:https: //github.com/Maatwebsite/Laravel-Excel
但是,文档没有说明如何将文件中的图像插入到我的Excel文档中.我非常确定本地phpexcel本身是可能的,但如何通过这个包来做到这一点?
一些示例代码将非常感激..
我不知道我做错了什么,或者它可能是正常的.我必须加载并"读取"大约12000行的excell.我使用这个代码.
Excel::selectSheetsByIndex(0)->load($path.$fileName, function ($reader) {
$reader->each(function($row){
Log::info('$row');
});
});
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,没有什么可以使阅读变得如此缓慢.我需要在读取后处理数据,如果只读取超过5-10分钟就会出现问题.
我也尝试使用块过滤器,但没有什么比这更好了.
这是正常的吗?
我知道excel阅读速度很慢,正如我在其他问题中读到的那样,但"这个"很慢?谢谢.
我正在使用laravel-excel库来读取 Excel 文件。
http://www.maatwebsite.nl/laravel-excel/docs/import
//http://localhost:8000/assets/panel/excel/test123.xls
$address = URL::to('/assets/panel/excel/').'/test123.xls';
// dd($address);
Excel::load($address, function($reader) {
$results = $reader->get();
dd($results);
});
Run Code Online (Sandbox Code Playgroud)
该文件http://localhost:8000/assets/panel/excel/test123.xls存在,但我收到此错误:
Could not open C:\xampp\htdocs\tahrircenter\http://localhost:8000/assets/panel/excel/test123.xls for reading! File does not exist.
Run Code Online (Sandbox Code Playgroud)
我知道错误的含义,但是如何使用我的地址而不是该库中的目录地址?
我从这里获取教程:https ://laravel-excel.maatwebsite.nl/3.0/exports/extending.html
所以我使用版本3
我的Excel是这样的:
我想把它改成这样:
所以我想将字符England更改为红色并加粗
我尝试这样:
namespace App\Exports;
...
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\BeforeExport;
use Maatwebsite\Excel\Events\AfterSheet;
class SummaryExport implements FromView, WithEvents
{
...
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$event->sheet->styleCells(
'B1:D1',
[
'borders' => [
'outline' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,
'color' => ['argb' => 'EB2B02'],
],
]
]
);
},
];
}
}
Run Code Online (Sandbox Code Playgroud)
存在这样的错误:
Method Maatwebsite\Excel\Sheet::styleCells does not exist.
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误?
我正在尝试在使用PHP 7.4的Docker 容器中运行的Larevel 7中安装Laravel Excel,但出现此错误,但我不知道如何修复。
\n\ne-learning-app/src on \xee\x82\xa0 dev [$!] via \xe2\xac\xa2 v12.8.1 via v7.4.4\n\xe2\x9e\x9c docker:composer require maatwebsite/excel\nStarting e-learning-app-php ... done\nUsing version ^3.1 for maatwebsite/excel\n./composer.json has been updated\nLoading composer repositories with package information\nUpdating dependencies (including require-dev)\nYour requirements could not be resolved to an installable set of packages.\n\n Problem 1\n - maatwebsite/excel 3.1.x-dev requires phpoffice/phpspreadsheet ^1.11 -> satisfiable by phpoffice/phpspreadsheet[1.11.0, 1.12.0, 1.13.0].\n - maatwebsite/excel 3.2.x-dev requires phpoffice/phpspreadsheet ^1.11 -> satisfiable by phpoffice/phpspreadsheet[1.11.0, 1.12.0, …Run Code Online (Sandbox Code Playgroud) 我正在使用Laravel Excel创建包含多个工作表的 Excel 文档。我一直在遵循他们的示例,了解他们是如何做到这一点的,但是当我去下载文件时,它是:
Excel 无法打开文件“kingdoms (1).xlsx”,因为文件格式或文件扩展名无效。验证文件未损坏并且文件扩展名与文件格式匹配。
我不确定为什么。
所以我是这样做的:
public function export() {
return Excel::download(new KingdomsExport, 'kingdoms.xlsx', \Maatwebsite\Excel\Excel::XLSX);
}
Run Code Online (Sandbox Code Playgroud)
class KingdomsExport implements WithMultipleSheets {
use Exportable;
/**
* @return array
*/
public function sheets(): array {
$sheets = [];
$sheets[] = new BuildingsSheet;
// .. other commented out sheets.
return $sheets;
}
}
Run Code Online (Sandbox Code Playgroud)
class BuildingsSheet implements FromView, WithTitle, ShouldAutoSize {
/**
* @return View
*/
public function view(): View {
return view('admin.exports.kingdoms.sheets.buildings', [
'buildings' => …Run Code Online (Sandbox Code Playgroud) laravel-excel ×10
laravel ×7
excel ×6
laravel-5 ×5
php ×5
docker ×1
html ×1
laravel-5.6 ×1
laravel-8 ×1
phpexcel ×1