使用 Laravel-Excel 将行附加到现有 Excel 文档
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25793179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Append Rows to existing Excel document using Laravel-Excel
提问by Glad To Help
I have an existing Excel document, to which I want to append some data using Laravel-Excel. The package has nice documentation but unfortunately there is no full example showing how to do that, but only partial demonstration of manipulating rows.
我有一个现有的 Excel 文档,我想使用Laravel-Excel向其中附加一些数据。该包有很好的文档,但不幸的是没有完整的示例展示如何做到这一点,但只有部分操作演示。
What I am attempting to do is:
我正在尝试做的是:
- open the existing document
- get the first sheet, append new
- close the document
- 打开现有文档
- 获取第一张表,追加新
- 关闭文档
The code:
编码:
Excel::load($path . '/exported.xls', function($reader){
$sheet = $reader->getActiveSheet();
// Manipulate third row
$sheet->row(3, array(
'test1', 'test2'
));
});
Which results in
这导致
Call to undefined method PHPExcel_Worksheet::row()
调用未定义的方法 PHPExcel_Worksheet::row()
Has anyone succeeded appending data with this package?
有没有人成功地用这个包附加数据?
采纳答案by Glad To Help
Right now it is not possible to edit an Excel file like I intended to. Source: package creator.
现在不可能像我想要的那样编辑 Excel 文件。来源:包创建者。
回答by Patrick Brouwers
Laravel Excel 1.2.0 added support for appending rows (so modifying existing Excel files)
Laravel Excel 1.2.0 添加了对追加行的支持(因此修改现有的 Excel 文件)
http://www.maatwebsite.nl/laravel-excel/docs/import#edit
http://www.maatwebsite.nl/laravel-excel/docs/import#edit
The correct code would be:
正确的代码是:
Excel::load($path . '/exported.xls', function($reader)
{
$reader->sheet(function($sheet)
{
// Manipulate third row
$sheet->row(3, array(
'test1', 'test2'
));
});
})->export('xls');
回答by user1669496
It looks like you would use...
看起来你会用...
$sheet->appendRow(array(
'appended', 'appended'
));
Found in the docs here... http://www.maatwebsite.nl/laravel-excel/docs/export
在这里的文档中找到... http://www.maatwebsite.nl/laravel-excel/docs/export