質問

I have an application that works fine with PHPExcel to generate orders in Excel files. the client wants to have the order status as a watermark in Excel file. Is there a way to do this with PHPExcel?

I have searched their doc and I found no results. Also no example shown in any Google search I have made.

Thank you for your input.

PS: I saw that it is possible on PHPWord See en example of what I need: http://0.tqn.com/d/spreadsheets/1/5/D/H/-/-/2011-12-3-excel-watermark.gif

役に立ちましたか?

解決

You can set page headers to include a background image when the spreadsheet is printed using the &G code, as described in section 4.6.13 of the developer documentation; and 04printing.php in the /Examples folder shows an image in the header

他のヒント

You need to create the drawing object using the PhpSpreadsheet library and include that to the header section of excel.

https://github.com/PHPOffice/PhpSpreadsheet

Check below working code:

  <?php 
    require_once("vendor/autoload.php"); 
    
    // Input File
    $inputFileName = 'Route_details.xlsx';
    
    /** Load $inputFileName to a Spreadsheet Object  **/
    $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
    
    
    // Add a drawing to the header
    $objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing();
    $objDrawing->setName('Image');
    $objDrawing->setPath('./watermark_sample.png');
    // $objDrawing->setHeight(36);
    
    // Add the drawing object to Header part
    $spreadsheet->getActiveSheet()->getHeaderFooter()->addImage($objDrawing,  \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter::IMAGE_HEADER_LEFT);
    $spreadsheet->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&G&');
    
    // Write the data to excel file    
    $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
    $writer->save("ouput.xlsx");
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top