1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Read an Excel file from PHP?

Discussion in 'PHP' started by mikelbeck, Aug 11, 2005.

  1. #1
    Does anybody know how to read a Microsoft Excel file from PHP?
    SEMrush
     
    mikelbeck, Aug 11, 2005 IP
    SEMrush
  2. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You would have to figure out the file format that excel saves to and then read it with php. I would recommend saving your excel doc as csv (comma separated values) and then parsing that in php would be no problem.
     
    exam, Aug 11, 2005 IP
  3. mikelbeck

    mikelbeck Peon

    Messages:
    787
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yeah, I'm already able to do that, but I wanted to take out the "human" part of the step and just read the original xls from php and then pump it into my database... Right now I do what you've said, open the file in Excel, save it as a csv and then let my script have at it.
     
    mikelbeck, Aug 11, 2005 IP
  4. UndiesHosting

    UndiesHosting Active Member

    Messages:
    219
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    78
    #4
    Perl has CPAN modules to read excel files as is. There is also the SQLFairy project (written in perl) that can convert an Excel document to sql.

    Not sure if PHP has anything similar, but if it did it would be in the PEAR extensions I believe.
     
    UndiesHosting, Aug 11, 2005 IP
  5. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #5
    exam, Aug 11, 2005 IP
  6. Connect

    Connect Guest

    Messages:
    191
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Always Google first :)
    Most of the time you can find what you want there.
     
    Connect, Aug 12, 2005 IP
  7. mikelbeck

    mikelbeck Peon

    Messages:
    787
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes, I already had a look at phpexcelreader. The problem with that is that it reads the entire spreadsheet at once, and if you've got a large spreadsheet ( like I do) memory is exhausted almost immediately.

    Google is my friend, I wouldn't be asking here if I was able to find what I needed via Google.
     
    mikelbeck, Aug 12, 2005 IP
  8. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ah, then maybe your question should have been: I have tried phpExcelReader, and it runs out of memory. Is there any way to modify it to make it work, or do you know of any other way of reading an excel file?

    Because of Excel's format, you probably can't just modify phpExcelReader so that it reads part of a file, becuase we probably have to see the entire file to parse it. Why don't you try increasing php's memory (in php.ini).
     
    exam, Aug 12, 2005 IP
  9. Scott

    Scott Peon

    Messages:
    273
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I haven't looked at phpexcelreader, and don't plan to, but a good way I use to get around memory issues is popen('cat ' .$filename, 'r'); instead of fopen. You can then use fgets($whatever, 1024); to grab a line at a time from within a !feof loop.
     
    Scott, Aug 12, 2005 IP
  10. North Carolina SEO

    North Carolina SEO Well-Known Member

    Messages:
    1,327
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    105
    #10
    Have you thought about going at the problem from a slightly different angle? Depending on what type of database you are using, there may be an import option within it. Just a thought(?) :)
     
    North Carolina SEO, Aug 12, 2005 IP
  11. itsbobbs

    itsbobbs Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11

    I am attaching the 4 files, which help in reading the
    excel file using PHP 4.4.

    It can be used in Windows/linux or any environments

    Thanks
    itsbobbs@gmail.com
     

    Attached Files:

    itsbobbs, Jul 2, 2007 IP
  12. itsbobbs

    itsbobbs Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12

    I am attching the zip file, which contains of the file
    to help you in reading excel file


    Thanks
    itsbobbs@gmail.com
    9840529212
    India
     
    itsbobbs, Jul 2, 2007 IP
  13. rps111

    rps111 Peon

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    If u want to import the data to sql then try Navicat...hope that helps
     
    rps111, Jul 2, 2007 IP
  14. smaxor

    smaxor Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Great little scripts thanks a lot.

    any idea why in FF it my first column would render like

    ["term"]=> string(36) "a�u�t�h�o�r�i�t�y� �d�o�g� �f�o�o�d�"

    with a question mark between each letter? In shell output it does and IE it doesn't. Only in FF.
     
    smaxor, Jul 26, 2007 IP
  15. rps111

    rps111 Peon

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    try navicat or softwares from EMS
     
    rps111, Jul 30, 2007 IP
  16. newstan

    newstan Member

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #16
    I have an xml doc that has more than one sheet. exactly 7.

    can the script read that?

    or what are the other solutions available?

    Thanks.
     
    newstan, Aug 24, 2007 IP
  17. sohel62

    sohel62 Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    This script can read .xls file with more than one sheet.
    But not xml doc.

    You can download the latest one of phpexcelreader

    :cool:
    Best of luck
    Taslim Sohel
     
    sohel62, Jan 28, 2008 IP
  18. sameena

    sameena Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    hai ,
    i want to know how to read excel file in php with one example using pear package
     
    sameena, Mar 27, 2008 IP
  19. kmofo

    kmofo Active Member

    Messages:
    442
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    85
    #19
    navicat should help you!
     
    kmofo, Apr 18, 2008 IP
  20. Yankee85

    Yankee85 Peon

    Messages:
    1,072
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0