Laravel Excel version 3.1 Show 1. Data preparationBuild two tables, add some data, check the data in the controller, and use it for the template. Table 1-order: id, order_no, img_path, note Table 2-order_item: id, order_id, sku, num Check data:
Print result: View Image 2. Template preparationNew template: resources/views/order_export.blade.php
3. New export class
OrderExport 3.1. Implement the FromView interfaceImplement the view() method
3.2, adjust the template
3.3, call in the controller
3.4. Export results:View Image At this time, the export has been completed, but there are some things that need to be noted. The css in the template can only be embedded and only a few styles can be used. The specific ones have not been tried, only knowing the border line will not work. In addition, the image img tag is not applicable, and the effect will not be output when exporting. 4. Picture exportImage export needs to use WithEvents to monitor events, which is not mentioned in this manual. Or the above derived class: OrderExport, need to implement WithEvents and implement the registerEvents() method When the excel sheet is monitored, insert a picture:
The setImage2Excel() method is encapsulated by itself and is convenient to call when multiple images are needed to export. result: View Image |