Laravel 6 Generate Word File

Laravel 6 , Laravel

Nicesnippets

6390

11-02-2020


Laravel 6 Generate Word File

Hi Guys,

In this blog, I will explain how to generate a word document file in laravel. we will show the example of create word document file in laravel.you can easy to generate word file in laravel.we will generate *.doc file without using any composer package. I will generate doc file from html content in laravel 5 application.

We might be some time require to create docs file from database in laravel. if you need to same requirement then you can easily achieve to generate word document.We will use headers with Html content and file name will be *.docx. we can use simple html tag like p, strong, ul, li, etc. that all tags will support for creating docs file. you can follow this tutorial to create a simple way docs file.

Here i give you full example of generate word document file example like create route. So you have to just follow example.

Create Route:


Now,we need to create route for generate word document file in laravel.So following add route fille path.

following path:/routes/web.php

<?php

Route::get('generate-docs', function(){

$headers = array(

"Content-type"=>"text/html",

"Content-Disposition"=>"attachment;Filename=myGeneratefile.doc"

);

$content = '<html>

<head><meta charset="utf-8"></head>

<body>

<p>My Blog - Nicesnippets.com</p>

<ul><li>Php</li><li>Laravel</li><li>Html</li></ul>

</body>

</html>';

return \Response::make($content,200, $headers);

});

It will help you...


Recommended Posts