PHP excel output with graphic(.jpg, etc)?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • perhapscwk
    New Member
    • Sep 2007
    • 123

    PHP excel output with graphic(.jpg, etc)?

    I use below to output data to a excel file using PHP,
    however, how to include some photo(.jpg) in my excel output?


    Code:
    header("Content-type: application/vnd.ms-excel");
    header("Content-Disposition: attachment; filename=excel.xls");
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    How do you create the Excel file?

    Comment

    • perhapscwk
      New Member
      • Sep 2007
      • 123

      #3
      html output......the basic method

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        If you want me to be able to help you modify the output your are sending as your Excel file, I need to actually see the way you are currently creating the output. The code that needs to be modified.

        Simply naming the method used to create pretty much every webpage in existence is not exactly helpful.

        Comment

        • perhapscwk
          New Member
          • Sep 2007
          • 123

          #5
          Code:
              header("Content-Type: application/vnd.ms-excel; charset=utf-8");
              header("Content-Disposition: attachment; filename=zzzzz.xls");
          	header("Pragme: no-cache");
          	header("Expires: 0");	
          
          print "<table border='0' cellspacing='5'>";
          print "<tr><th>Col A</th><th>Col B</th></tr>";
          print "<tr><td><img src="/images/aaaa.jpg"></td><td>Pictures</td></tr>";
          print "</table>";
          However, when we open the xls, it is not open in same folder of the jpg file,
          we can;t see the image.

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Ok. Try embedding the image in the HTML tag.
            [code=php]
            $data = base64_encode(f ile_get_content s('image.png')) ;
            $imgTag = '<img src="data:image/png;base64,'. $data . '">';
            [/code]

            Comment

            • perhapscwk
              New Member
              • Sep 2007
              • 123

              #7
              not works...i read from online ppl said img not the correct method to embed images in excel..any others suggestion?

              Comment

              • Atli
                Recognized Expert Expert
                • Nov 2006
                • 5062

                #8
                I'm not sure exactly how Excel works, but you could try something like PHPExcel. That should allow you to build Excel sheets with embed images.

                Comment

                Working...