A
A
Aizharik2018-05-03 10:19:01
PHP
Aizharik, 2018-05-03 10:19:01

PHP Library for creating Excel files from a template?

Hello,
Tell me a package for working with Excel according to a template,
There are several Excel tables (invoice, invoice act-output works), that is, the files are not large. In fact, change only the values ​​of some cells and duplicate the line with the name of the goods. (1-5 lines)
Google leads mainly to PHPExcel which is DEPRECATED, and which is now called PhpSpreadsheet. PhpSpreadsheet creates documents normally, but it can no longer take the Excel file to change the values ​​​​(when resaving and then opening it in Excel, it swears that the file extension is wrong or the file is damaged), even copy-pasting the example code from the documentation resaves the damaged file that Excel cannot open .
Copy-paste code from the PhpSpreadsheet docs

$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load('template.xlsx');

$worksheet = $spreadsheet->getActiveSheet();

$worksheet->getCell('A1')->setValue('John');
$worksheet->getCell('A2')->setValue('Smith');

$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('write.xls');

This is how one Excel file out of several looks like.
5aeab6aabe38e319526224.png
I tried to save the html table as .xls, Excel swears but opens it, but then it is very difficult to print from it (the table is spread over several pages and it is difficult to check the size)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis _______________, 2018-05-03
@LuchS-lynx

I solved a similar problem using standard Excel tools, namely through macros. Here is my article, although it is applicable to the Executive documentation in construction, but the essence is the same: fill in standard forms according to the template. Sheets are created in which there will be data for filling out forms, and then with a macro we write data from the cells from the data sheet to specific cells of the file. https://m.habr.com/post/344956/
Of the minuses of the solution, the template file will have to be configured for each printer, i.e. if you print on one set it up and forget it, but if you need to print on another, then no one will guarantee that the markup of previously saved files will not work. It is solved by reconfiguring the output for printing a template for a different printer and re-outputting old files

R
roxblnfk, 2019-10-03
@roxblnfk

tinybutstrong with the opentbs plugin will easily complete the task of generating an office document from a template

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question