我正在尝试使用3.1版导入5.7版中的.xlsx文件。我想要实现的是跳过文件的第一行以避免在我的数据库中导入列标题。LaravelMaatwebsite-excel
我尝试使用版本 2 语法,调用该skip()方法。
public function voter_import(Request $request)
{
if (empty($request->file('file')->getRealPath()))
{
return back()->with('success','No file selected');
}
else
{
Excel::import(new VotersImport, $request->file('file'))->skip(1);
return response('Import Successful, Please Refresh Page');
}
}
class VotersImport implements ToModel
{
public function model(array $row)
{
return new Voter([
'fname' => $row[0],
'lname' => $row[1],
'phone' => $row[2],
'gender' => $row[3],
'state' => $row[4],
'occupation' => $row[5],
'address' => $row[6],
'vin' => $row[7],
'dob' => $row[8],
'campaign_id' => $row[9],
]); …Run Code Online (Sandbox Code Playgroud) 我正在创建一个excel模板,其中应包含一个下拉列表.我看到它可能与phpexcel库(依赖的PHPExcel Multiple Dropdown列表).我想知道是否可以使用maatwebsite提供的laravel-excel库来完成.我需要dropdown,NamedRange,datavalidation,setFormula等函数的语法.
我正在尝试使用maatwebsite 3.0导入excel文件(.xlsx).如何修复此错误
调用未定义的方法Maatwebsite\Excel\Excel :: load()
我的控制器
public function importsave(Request $request)
{
if($request->hasFile('excel'))
{
$path = $request->file('excel')->getRealPath();
$data= Excel::load($path, function($reader) {})->get();
if(!empty($data) && $data->count())
{
foreach($data->toArray() as $key=>$value)
{
if(!empty($value))
{
Employee::insert($value);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我想我很接近,我只需要在 Mail 中传递 $excelFile 但它一直说它未定义,但是当我传递 $truckstop_post 时它会通过,但数据格式不正确,因为它还没有通过 Excel::create 。如何将 \Excel::create 的结果获取到 Mail::send 中?
public function truckstopPost()
{
$type = 'csv';
$truckstop_post = Loadlist::select('pick_city', 'pick_state', 'delivery_city', 'delivery_state', 'trailer_type', 'pick_date', 'load_type', 'length', 'width', 'height', 'weight', 'offer_money', 'special_instructions', 'company_contact', 'contact_phone')->where('urgency', 'OPEN')->orderBy('id', 'desc')->get();
$excelFile = \Excel::create('itransys', function($excel) use ($truckstop_post) {
$excel->sheet('mySheet', function($sheet) use ($truckstop_post)
{
$sheet->fromArray($truckstop_post);
});
$info = Load::find(8500);
$info = ['info'=>$info];
Mail::send(['html'=>'email.invoice_email_body'], $info, function($message) use ($info, $excelFile){
$message->to('mike@gmail.com')->subject('subject');
$message->from('mike@gmail.com', \Auth::user()->name);
$message->attachData($excelFile, 'Invoice.csv');
});
});
return back()->with('status', 'You Posted Truckstop!');
}
Run Code Online (Sandbox Code Playgroud)
如果我将 $truckstop_post …
我用来Maatwebsite加载excel文件。我正在加载几个文档,直到出现下一个错误:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /project1/vendor/phpoffice/phpexcel/Classes/PHPExcel/Cell.php on line 582
Run Code Online (Sandbox Code Playgroud)
我去了config/excel.php并将设置更新memoryCacheSize为128MB。做完之后,我跑了php artisan cache:clear,然后php artisan config:cache。再次尝试加载并返回相同的错误。
我该如何解决这个问题?
我正在使用Maatwebsite的库来阅读和创建excel文件.创作很容易,而且有点直观,但是当谈到阅读时,我根本无法理解.
我想出了如何循环遍历行,但让我感到困惑的是我的示例中的$ row实际上是字符串的类型,所以我不能做$ row-> something;
在我的控制器中,我想这样读:
Excel::load('storage\\exports\\'. $fName, function($reader) {
$reader->each(function($sheet) {
Log::warning("sheet happens");
// Loop through rows
$sheet->each(function($row) {
Log::warning($row);
});
});
});
Run Code Online (Sandbox Code Playgroud)
这给了我输出
[2016-01-28 06:42:05] local.WARNING: sheet happens
[2016-01-28 06:42:05] local.WARNING:
[2016-01-28 06:42:05] local.WARNING:
[2016-01-28 06:42:05] local.WARNING:
[2016-01-28 06:42:05] local.WARNING:
[2016-01-28 06:42:05] local.WARNING:
[2016-01-28 06:42:05] local.WARNING:
[2016-01-28 06:42:05] local.WARNING: sheet happens
[2016-01-28 06:42:05] local.WARNING: ocjena
[2016-01-28 06:42:05] local.WARNING: Kolokvijum 1 (%)
[2016-01-28 06:42:05] local.WARNING: Kolokvijum 2
[2016-01-28 06:42:05] local.WARNING: Kolokvijum 2 (%)
[2016-01-28 06:42:05] local.WARNING: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用最新版本的Laravel-Excel (3.1.9)将 Excel 文件转换为数组
下面的代码将下载文件:
return Excel::download(new SalesOrderExport('columns'),'test.xlsx')
Run Code Online (Sandbox Code Playgroud)
但我需要将其转换为仅获取数组。此时我不想将此 Excel 数据存储在数据库中。
我尝试使用下面的代码,但它不起作用,因为该load方法在版本 3 中不可用。
Excel::load($request->file('sampledata'), function ($reader) {
return response()->json($reader);
});
Run Code Online (Sandbox Code Playgroud)
请分享您对如何从 Excel 获取数组的想法。
当我试图maatwebsite/excel从我的项目中删除包时,我严重损坏了一些东西。问题是我无法跟踪我所做的更改。在我maatwebsite/excel从 composer.json 中删除之前,我phpoffice/phpspreadsheet可能从 composer.json 中删除了。但我记不清了。因为当我用 git 查看旧版本时,我再也找不到这个条目了。每次我调用 Composer 时,它现在都会给出一条类似以下内容的大量错误消息。
在 ArrayLoader.php 第 44 行:Unknown package has no name defined ([{"name":"asm89/stack-cors","version":"v2.0.1","version_normalized":"2.0.1.0","source ":{"type":"git","url":"https://github.com/asm89/stack-cors.git","reference":"23f469e81c65e2fb7fc7bce371fbdc363fe32adf"},"dist":{"type" :"zip","url":"https://api.github.com/repos/asm89/stack-cors/zipball/23f469e81c65e2fb7fc7bce371fbdc363fe32adf","reference":"23f469e81c65e2fb37f","23f469e81c65e2fb37f"">3fesumshad7f", "require":{"php":"^7.0","symfony/http->foundation":"~2.7|~3.0|~4.0|~5.0","symfony/http-kernel":"~2.7|~ 3.0|~4.0|~5.0"},"require-dev":{"phpunit/phpunit":"^6|^7|^8|^9","squizlabs/php_codesniffer":"^3.5"}," time":"2020-05-31T07:17:05+00:00","type":"library","extra":{"branch-alias":{"dev-master": "2.0-dev" }},"installation-source":"dist","autoload":{"psr-4":{"Asm89\Stack\":"src/"}},"notification-url":"https:// packagist.org/downloads/","license":["MIT"],"authors":[{"name":"Alexander","email":"iam.asm89@gmail.com"}],"description ":"跨源资源共享库和栈中间件","主页":"https://github.com/asm89/stack-cors","keywords":["cors","stack"],"install-path":"../asm89/stack-cors"},{"name":"bacon/bacon-qr-code","version" :"2.0.2","version_normalized":"2.0.2.0","source":{"type":"git","url":"https://github.com/Bacon/BaconQrCode.git", "reference":"add6d9ff97336b62f95a3b94f75cea4e085465b2"},"dist":{"type":"zip","url":"https://api.github.com/repos/Bacon/BaconQrCode/zipball/add6d9ff97336bsource":{"type":"git","url":"https://github.com/Bacon/BaconQrCode.git","reference":"add6d9ff97336b62f95a3b94f75cea4e085465b2"},"dist":{"type": "zip","url":"https://api.github.com/repos/Bacon/BaconQrCode/zipball/add6d9ff97336bsource":{"type":"git","url":"https://github.com/Bacon/BaconQrCode.git","reference":"add6d9ff97336b62f95a3b94f75cea4e085465b2"},"dist":{"type": "zip","url":"https://api.github.com/repos/Bacon/BaconQrCode/zipball/add6d9ff97336b
错误消息的大小为 165K。也许,有人对我如何解决这个问题有建议?
composer-php maatwebsite-excel laravel-8 phpoffice-phpspreadsheet
我需要通过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