-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] Use existing file as a template to append new data before export #2068
Comments
Finally this worked for me on version 3.1.0. In the actual version 3.1.10 this doesn't work because |
Editing existing files (templates) is on our roadmap (version 3.3), but without a specific release date. If you need it on priority, please have a look at our Commercial Support section: https://laravel-excel.com/commercial-support . |
Thanks for this quick answer. I will try this way. This is not a priority right now but I'm testing because I will need to add data to an existing excel with macros and dynamic tables, adding data and recalculating excel formulas. I'm trying all of this because I know this is not easy to do with a complex excel. If I find out something good I will report you |
In case of an update please comment as soon as possible |
Hello, @MarFelix. I was facing same problem and now I have a workaround that I'm using. This may help you.
So that's why the To workaround I add a flag on the method to get the export data (in my case FromCollection). This way it will not be process on step 2. Then, on That's the code: public function collection()
{
if ($this->calledByEvent) { // flag
return $this->myCollectionToExport;
}
return collect([]);
}
public function registerEvents(): array
{
return [
BeforeWriting::class => function(BeforeWriting $event) {
$templateFile = new LocalTemporaryFile(storage_path('app/public/files/mytemplate.xlsx'));
$event->writer->reopen($templateFile, Excel::XLSX);
$event->writer->getSheetByIndex(0);
$this->calledByEvent = true; // set the flag
$event->writer->getSheetByIndex(0)->export($event->getConcernable()); // call the export on the first sheet
return $event->getWriter()->getSheetByIndex(0);
},
];
} Take a look on With this information and steps, it would be possible to create a more complex workaround. |
Its not working |
Sorry If I'm late to the party, but I found the solution.
this is my controller :
hope it helps |
This doesn't seem to work when I use this in conjunction with the example for MultipleSheets for some reason. All I get are empty sheets. |
I guess this is a bit unrelated since I didn't use MultipleSheets, but I did this for multiple sheets.
|
This don't sees to work anymore i think |
Prerequisites
Versions
Description
I'm trying to edit an existing file to use as a template. I now that for this version, this function is not developed to use easily. But I would like to know if using the functions inside the plugin and playing with the
function resisterEvents()
I could do it by myself.I got to download an existing file and select a sheet. But not to edit it.
This is my code:
Some suggestions?
Many thanks
Additional Information
I tried to add info in a value with this code inside the
function resisterEvents()
and doesn't work:And also to append data through
function query()
The text was updated successfully, but these errors were encountered: