SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Emailing a Generated File

    Hi, I need to create a report which is automatically emailed to everyone at end of day.

    I'm creating a cron job to do this at midnight, and I have created the script to create the csv file.

    I have 2 questions.

    1) Is it possible to put formatting on the csv file (or make it a different mime type) so that when excel reads it, it can have colours and different styles?

    2) To get it working I simply changed the header mime type and the disposition so it would download. Instead of echoing (to do this) I have now changed this to $file so all the contents of the file is in that variable.. instead of downloading the file I just want to use Swiftmailer to email this generated file off to the people i specify how would I go about attaching this variable/file to swiftmailer as it seems to want a file path which I dont have.

    Thanks

    Kevin

  2. #2
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. Not possible. CSV doesn't support any formatting.
    2.

    PHP Code:
    $message->attach(new Swift_Message_Attachment(
      
    $file"filename.csv""text/csv")); 

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. To do the formatting, can you not change the mime type to excel and output it differently?
    2. its that easy!? i knew that

    Kev

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KevinM2k View Post
    1. To do the formatting, can you not change the mime type to excel and output it differently?
    If you want to create a formatted Excel file, why not create it as a formatted Excel file rathe rthan a plain text CSV file.

    Take a look at PHPExcel

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ill take a look now, never knew of that!
    Thanks

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Matt,

    Im a little confused with that PHPExcel class it looks great, but:

    1) Does it only work with Excel 2007
    2) Im not sure where it attempts to save the file, I would just want to email it. Any idea how that would work?

    Kev

  7. #7
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KevinM2k View Post
    1) Does it only work with Excel 2007
    In addition to its own serialized format, PHPExcel reads Excel 2007 and Excel 5 (BIFF8) files, and CSV (or any separated value such as tab or pipe).
    It writes Excel 2007 and Excel 5 (BIFF8) files, CSV (or any separated value such as tab or pipe), HTML and PDF (and its own serialized format).

    Quote Originally Posted by KevinM2k View Post
    2) Im not sure where it attempts to save the file, I would just want to email it. Any idea how that would work?
    The file is written to wherever you want it written, and can than then be e-mailed. Alternatively, the output can be spooled for download without ever writing to a file. You could probably write a wrapper for the spooling that would allow your script to capture the binary data and embed it directly in your e-mail.

    Take a look at the sample code in the /Tests directory, and you can post any specific questions on the PHPExcel discussion forums.

  8. #8
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If you are using it with Office 2007 or Office 2003 (which you can get a compatibility pack for), why not use SpreadsheetML? I have used it in the past, and it is pretty good. You just output XML with styles, formatting, spanned columns etc in, and save it as a .xlsx file, making it compatible with the new office formats

  9. #9
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At the minute i've been working on the PHPExcel which is great! Ive asked my host to turn on php_zip.dll as that is required for PHPExcel, but yeah so far so good.

    Just gotta work out the spooler to allow me to capture the data..

    Thanks Mark


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •