Importing Excel files into MySQL with PHP

If you have Excel files that need to be imported into MySQL, you can import them easily with PHP. First, you will need to download some prerequisites:

PHPExcelReader – http://sourceforge.net/projects/phpexcelreader/
Spreadsheet_Excel_Writer – http://pear.php.net/package/Spreadsheet_Excel_Writer

Once you’ve downloaded both items, upload them to your server. Your directory listing on your server should have two directories: Excel (from PHPExcelReader) and Spreadsheet_Excel_Writer-x.x.x (from Spreadsheet_Excel_Writer). To work around a bug in PHPExcelReader, copy oleread.inc from the Excel directory into a new path:

Spreadsheet/Excel/Reader/OLERead.php

The PHPExcelReader code will expect OLERead.php to be in that specific location. Once that is complete, you’re ready to use the PHPExcelReader class. I made an example Excel spreadsheet like this:

Name                Extension   Email
----------------------------------------------------
Jon Smith           2001        jsmith@domain.com
Clint Jones         2002        cjones@domain.com
Frank Peterson      2003        fpeterson@domain.com

After that, I created a PHP script to pick up the data and insert it into the database, row by row:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
require_once 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$data->read('exceltestsheet.xls');
 
$conn = mysql_connect("hostname","username","password");
mysql_select_db("database",$conn);
 
for ($x = 2; $x < = count($data->sheets[0]["cells"]); $x++) {
    $name = $data->sheets[0]["cells"][$x][1];
    $extension = $data->sheets[0]["cells"][$x][2];
    $email = $data->sheets[0]["cells"][$x][3];
    $sql = "INSERT INTO mytable (name,extension,email) 
        VALUES ('$name',$extension,'$email')";
    echo $sql."\n";
    mysql_query($sql);
}

After the script ran, each row had been added to the database table successfully. If you have additional columns to insert, just repeat these lines, using an appropriate variable for each column:

$variable = $data->sheets[0]["cells"][$row_number][$column_number];

For more details, you can refer to a post in Zend’s Developer Zone.

Comments

  1. AR says

    Am I correct in saying line 4 reads the whole spreadsheet into memory?
    Won’t that have issues with huge files, like 10 or 20 sheets each with 64k lines in them?

  2. OmahaVike says

    Warning: reader does not work with Excel 2007. Author’s email addy in the code is no longer valid, and it appears that the sourceforge project has been abandonded.

  3. says

    thanks for the sharing.
    but i’m still confusing with your explanation above about:

    To work around a bug in PHPExcelReader, copy oleread.inc from the Excel directory into a new path:

    Spreadsheet/Excel/Reader/OLERead.php

    The PHPExcelReader code will expect OLERead.php to be in that specific location. Once that is complete, you’re ready to use the PHPExcelReader class.
    Can you explanation that?

  4. says

    Good Morning Colleagues,

    I get the exception message below, each time I run the codes above.

    Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\LGHS\admin\Excel\reader.php on line 261

  5. swaraaj says

    Hi Nnamdi

    $this->_ole = & new OLERead(); (line 261a)

    just remove the ‘&’ sign there and your script will be working this is really awesome script for exporting data from excel file to sql its really worth working with it.

    thanks a lot
    for any query feel free to post here.

  6. Balanca says

    Can’t get it to work!

    It displays this message:

    Fatal error: Maximum execution time of 30 seconds exceeded in oleread.inc on line 172

    Can anybody help me, please.

  7. harisoft says

    Not working. Getting message ”
    Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\Spreadsheet\Excel\Excel\Spreadsheet\Excel\Reader\oleread.php on line 172″

  8. Martín Indico says

    Thanks for your post, tried it on my website and it worked very well with .xls spreadsheet excel 2003, I have not had any problems.

  9. Sem says

    Hello,

    I am having a hard time resolving a problem regarding utf-8 characterset, Turkish to be specific. I am trying to import a username that has some of these characters, İŞĞÇÜÖ.

    if the column has İ in it, it interprets the rest of these unique characters just fine, meaning that it prints them out ok. but if there is no İ but other characters like ŞĞÇÜÖ, it does not interprets them as it should.

    Any idea why?

  10. Daisy says

    Hi,

    I am having a problem with when excel date. The value of date I got from excel shows only like this (Mar/Tue/2010201020102010). Anyone can help?

  11. asma says

    hello
    the program works but when I home him I find these problems
    “Notice: Uninitialized string offset: 2199023255040 in /home/suptec/public_html/charlemagne/Excel/oleread.php on line 27″ and
    Notice: Undefined index: in /home/suptec/public_html/charlemagne/Excel/oleread.php on line 136
    and
    Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 71 bytes) in /home/suptec/public_html/charlemagne/Excel/oleread.php on line 131
    plz help me

  12. supraja says

    setOutputEncoding(‘CP1251′);
    $data->read(‘example.xls’);

    $conn = mysql_connect(“10.40.20.201″,”root”,”tanla@123″);
    mysql_select_db(“voiceobd”,$conn);

    for ($x = 2; $xsheets[0]["cells"]); $x++)
    {
    $msisdn=$data->sheets[0]["cells"][$x][1];
    $achievement=$data->sheets[0]["cells"][$x][2];
    $date=$data->sheets[0]["cells"][$x][3];
    $sql=”INSERT INTO achievementlist (msisdn,achieved,date)VALUES (‘$msisdn’,$achievement,’$date’)”;
    echo $sql.”\n”;
    mysql_query($sql);
    }
    ?>

    after executing it is showing:

    The filename example.xls is not readable

  13. jawwad says

    The code is working but every time it shows error which is given below.

    “The filename exceltestsheet.xls is not readable”

    can anyone help me i am using ms excel 2010 but i’ve saved the file into 2003 format but it could not read my file any more… kind reply me soon thanks in advance

  14. SP says

    Hi,

    Is there any way to do the revers? I want to get all the data I have in the mysql database to excel.
    I can see a class named Excelwriter. I am not much of a coder. Is that useful anyhow?

  15. soumya says

    I tried a lot to add more number of columns but it only imports 6 rows in to the mysql db… Any alternative method to do that.. I tried with a lot of variables and looping structure but it only imports 6 no of columns.. HELP ME!!!

  16. Ankita Raj says

    Sir it only takes up six columns , as u told to repeat the steps using a no of variables i too did the same but no results. At max six columns are added..Is there any way to modify the “reader.php” or “oleread.inc” files ? to make it to take more than six colums.. Please reply soon..

  17. says

    If you are using this code:
    require_once ‘Excel/reader.php';
    $data = new Spreadsheet_Excel_Reader();
    $data->setOutputEncoding(‘CP1251′);
    $data->read(‘exceltestsheet.xls’);

    $conn = mysql_connect(“hostname”,”username”,”password”);
    mysql_select_db(“database”,$conn);

    for ($x = 2; $x sheets[0]["cells"]); $x++) {
    $name = $data->sheets[0]["cells"][$x][1];
    $extension = $data->sheets[0]["cells"][$x][2];
    $email = $data->sheets[0]["cells"][$x][3];
    $sql = “INSERT INTO mytable (name,extension,email)
    VALUES (‘$name’,$extension,’$email’)”;
    echo $sql.”\n”;
    mysql_query($sql);
    }

    As given in the article,
    Then it should not be a problem.

    I myself have added more than 20-25 rows in the table using this code.
    Make sure that you store the data in the variable first and then use itin sql query.

    Also make sure, there is no problem in your excel file also.

  18. Ankita Raj says

    Actually i did the same but i am able to add columns more than 6.. Rows are being added up leaving behind the columns ..No problem in excel file.. “$phno = $data->sheets[0]["cells"][$x][7];” This doesn’t work out…no column is added to the db.

  19. Smita Ahuja says

    The adding of columns more than six doesn’t work out.. Actually when we try to add the columns more than six the specified row is not inserted to the db.. PLEASE HELP ME ,… I am in a urgent need..

  20. murad says

    require_once ‘Spreadsheet/Excel/reader.php';
    $data = new Spreadsheet_Excel_Reader();
    $data->setOutputEncoding(‘CP1251′);
    $data->read(‘mom.xls’);

    $conn = mysql_connect(“localhost”,”root”,”123″);
    mysql_select_db(“test”,$conn);

    for ($x = 2; $xsheets[0]["cells"]); $x++) {
    $name = $data->sheets[0]["cells"][$x][1];
    $extension = $data->sheets[0]["cells"][$x][2];
    $email = $data->sheets[0]["cells"][$x][3];
    $sql = “INSERT INTO mytable (name,extension,email)
    VALUES (‘$name’,$extension,’$email’)”;
    echo $sql.”\n”;
    mysql_query($sql);
    }

    work well.

  21. brian says

    Hey
    I am trying to make it happen with the phpexcelreader but it keeps throwing an error ‘The filename is not readable’ What might be the problem?

  22. haidar says

    Please Help Me
    every thing is ok
    but i have the ERROR
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    The filename exceltestsheet.xls is not readable >
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    how can i solve it

    i saved my Excel file AS 2003
    And Put the same name appeared in u r php code in it

    HOW CAN I SOLVE THIS

    PLEASE HELP

  23. anjani says

    require_once(phpExcelReader/Excel/Reader/OLERead.php) [function.require-once]: failed to open stream: No such file or directory in C:xampphtdocs
    ewexcel est.php on line 2

  24. anjani says

    setOutputEncoding(‘CP1251′);
    $data->read(‘exceltestsheet.xls’);
    $conn = mysql_connect(“localhost”,”root”,”root”);
    mysql_select_db(“anjani”,$conn);

    for ($x = 2; $x sheets[0]["cells"]); $x++)
    {
    $name = $data->sheets[0]["cells"][$x][1];
    $extension = $data->sheets[0]["cells"][$x][2];
    $email = $data->sheets[0]["cells"][$x][3];
    $phone = $data->sheets[0]["cells"][$x][4];
    $sql = “INSERT INTO mytable (name,extension,email,phone)
    VALUES (‘$name’,$extension,’$email’,’$phone’)”;
    echo $sql.”\n”;
    mysql_query($sql);
    }

  25. Sourabh Singh says

    I have imported an excel sheet of more than 30 coloumns and 50 rows by using the same code.
    THe code works absolutely fine. If it is not working for you than you might be writing wrong coloumn number or sheet numbers in the code. Because some times it counts first sheet as 0th and sometime as 1st.

    Good Luck

  26. Vladimir says

    Good afternoon.
    I do not know who to turn to the question that worries me.
    There is a list of employees who (1) should go on vacation, (2) are already on vacation, (3) and who had returned from vacation.
    This list is in Excel. Using Macros for Excel date input determines what color to paint the string.
    (1) – Yellow
    (2) – Red
    (3) – white by default.
    I work on the engine, Joomla, revised set of pages, nothing useful could not be found. Please if you can help me with this question. the site is ready. It remains only to decide that question.
    Sincerely, Vladimir.

    Please forgive me for mistakes, the text translated using google.

  27. chad says

    Nice script. Works great.

    i changed spacing on < =
    for ($x = 2; $x sheets[0]["cells"]); $x++) {

    Have a question about $sql

    My results are successfully added to the db.
    I want them to overwrite the tables every time the page is loaded instead of adding the same information repeatedly.
    I’ve tried a few commands to drop or truncate but I havent found the right syntax.
    Can anyone help?

  28. chad says

    got this to work:

    $sql2 = “TRUNCATE TABLE `mytable`;”;
    $res = mysql_query($sql2) or die(mysql_error());
    echo “Done.”;
    for ($x = 2; $x sheets[0]["cells"]); $x++) {
    $name = $data->sheets[0]["cells"][$x][1];
    $extension = $data->sheets[0]["cells"][$x][2];
    $email = $data->sheets[0]["cells"][$x][3];
    $sql1 = “INSERT INTO `mytable` (name,extension,email)
    VALUES (‘$name’,’$extension’,’$email’)”;
    echo ”;
    echo $name . ‘ ‘;
    echo ”;
    echo $extension . ‘ ‘;
    echo $email . ”;
    $res = mysql_query($sql1) or die(mysql_error());

  29. iqbal says

    Hai , I have something to ask.
    $persen= $excel->sheets[0]["cells"][$i][1];

    I have a type persen (%) in my excel file. If I use that sintax then the value is 1 or 0. I think this sintax not allow a float variable.
    Help mee

  30. vignseh says

    i caanot understand…
    To work around a bug in PHPExcelReader, copy oleread.inc from the Excel directory into a new path:

    Spreadsheet/Excel/Reader/OLERead.php

    The PHPExcelReader code will expect OLERead.php to be in that specific location. Once that is complete, you’re ready to use the PHPExcelReader class.

    clarify as soon as u see this.

  31. Venus says

    Hi haidar,
    I’ve seen this error “The filename exceltestsheet.xls is not readable” too;
    It seems that, the error appears when the file ‘exceltestsheet.xls’ directory is not correct. The file must be in root directory where your index.php file is there if you work on url rewriting mode. Somewhere such as ‘xampp/htdocs/YourProject’.
    Good luck.

  32. Shyam says

    Hi,
    I am very much new to this one. ” I have a table named ‘members’ in that i have two fields namely ID(auto increment) EMPID and EMPNAME.” My query is – i have created one admin panel, through this panel i need to update my table with CSV file which i downloaded from my server. Can you please help me.

  33. says

    Hi,

    this code run fine on my local machine but when i run it on server(live) then its excel/reader.php file does not work. i check my configuration setting of apache both where i find that virtual support directory are disabled in server while on locat machine it is enabled. i have done more R&D to enabled virtual directory but i have no clue to enabled it.if you can help me it will very appreciated …

  34. Trinh Nguyen says

    Hi every one,

    I put the Spreadsheet/Excel/Reader/OLERead.php into the same place with Excel/reader.php. Is it what the tutorial mean?

    This is my code:

    setOutputEncoding(‘CP1251′);
    $data->read(‘hocphi.xls’);

    // Database connect

    $con = mysql_connect(“localhost”, “root”, “root”);
    if(!$con)
    {
    die(‘Could not connect: ‘ . mysql_error());
    }
    mysql_set_charset(‘utf8′);
    mysql_select_db(“import_excel”, $con);

    for ($row_number = 9; $row_number sheets[0]["cells"][$row_number][2];
    $name = $data->sheets[0]["cells"][$row_number][3];
    $registered_subjects = $data->sheets[0]["cells"][$row_number][4];
    $total_credits = $data->sheets[0]["cells"][$row_number][5];
    $amount = $data->sheets[0]["cells"][$row_number][7];
    $notes = $data->sheets[0]["cells"][$row_number][8];

    $sql = “INSERT INTO tuition (mssv, name, registered_subjects, total_credits, amount, notes)
    VALUES (‘$mssv’,’$name’,’$registeredd_subjects’, $total_credits, ‘$amount’, ‘$notes’)”;

    echo $sql.”\n”;

    mysql_query($sql);
    }

    mysql_close($con);
    ?>

    When I load it (http://localhost/excelimport.php) got this error message:

    HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

    Please, help me! Thank you very much!

    Trinh Nguyen

  35. Trinh Nguyen says

    Sorry, the code above missed some parts:

    setOutputEncoding(‘CP1251′);
    $data->read(‘hocphi.xls’);

    // Database connect

    $con = mysql_connect(“localhost”, “root”, “root”);
    if(!$con)
    {
    die(‘Could not connect: ‘ . mysql_error());
    }
    mysql_set_charset(‘utf8′);
    mysql_select_db(“import_excel”, $con);

    for ($row_number = 9; $row_number sheets[0]["cells"][$row_number][2];
    $name = $data->sheets[0]["cells"][$row_number][3];
    $registered_subjects = $data->sheets[0]["cells"][$row_number][4];
    $total_credits = $data->sheets[0]["cells"][$row_number][5];
    $amount = $data->sheets[0]["cells"][$row_number][7];
    $notes = $data->sheets[0]["cells"][$row_number][8];

    $sql = “INSERT INTO tuition (mssv, name, registered_subjects, total_credits, amount, notes)
    VALUES (‘$mssv’,’$name’,’$registered_subjects’, $total_credits, ‘$amount’, ‘$notes’)”;

    echo $sql.”\n”;

    mysql_query($sql);
    }

    mysql_close($con);
    ?>

  36. Koustubh says

    Thanks for the code. It worked for me. Once again thanks.

    I have only one query regarding code in my code i get warning on line 12
    Notice: Undefined offset: 2 in D:\wamp\www\demo\phpExcelReader\import.php on line 12

    and my line 12 is

    for ($x = 2; $x sheets[0]["cells"]); $x++) {
    $oldurl = $data->sheets[0]["cells"][$x][1];
    $newurl = $data->sheets[0]["cells"][$x][2]; — this is line no 12
    }

    Can you please tel me what this warning for?

    Thanks
    Koustubh

  37. says

    It works great in my server, when I publish it at another server; didn’t work, even don’t show errors in error log… is there some requirements to php version or something else for the server where it is ejecuted?
    Sorry my english… :) someone could help me?

  38. Elti69 says

    Hello,
    The script works great for .xls files…

    I have xlsx files and i don’t know where/what I can change to make this work…

    Please help me

  39. says

    jika ada send error “The filename C:\xampp\tmp\php407.tmp is not readable” pada saat import dari data excel.csv ke mysql, itu knp ya???? tolong d bantu ya, makasi sebelumnya :)

  40. says

    pagi, saya mo tanya, jika ada send error “The filename C:\xampp\tmp\php407.tmp is not readable” pada saat import dari data excel.csv ke mysql, itu knp ya???? tolong d bantu ya, makasi sebelumnya :)

  41. Ronald Eyit says

    Thnx for this post, l have been looking for something like this for some time.

    I have also modified the example here to receive uploaded excel files from an html form, the excel file must be formatted in a standard way suiting ur database tables of coz, it then reads the uploaded file contents and inserts them in to the database.

    note l use $_POST['user_file']['tmp_name'] and not $_POST['user_file']['name'] for getting absolute path to the uploaded file

    read($_FILES['user_file']['tmp_name']);

    for ($x = 2; $x sheets[0]["cells"]); $x++)
    {
    $regno = $excel->sheets[0]["cells"][$x][1];
    $names = $excel->sheets[0]["cells"][$x][2];
    $gender = $excel->sheets[0]["cells"][$x][3];
    $email = $excel->sheets[0]["cells"][$x][4];

    mysql_query(“INSERT INTO tbl_users (username, status, rights) VALUES (‘”.$regno.”‘, 0, 700)”);

    $insertid = mysql_insert_id();

    mysql_query(“INSERT INTO tbl_studentlist (userid, names, gender, email) VALUES (‘”.$insertid.”‘, ‘”.$names.”‘, ‘”.$gender.”‘, ‘”.$email.”‘)”);

    }
    }

    ?>

  42. shankit says

    this code is running only for .xls file
    please if any body can tell me to run the code for .xlxs file

  43. navneet says

    anyone use this script for unicode.if use this

    $fileReader->setOutputEncoding(‘UTF-8′);
    $fileReader->read($readFileName);

  44. says

    Warning: require_once(Excel/reader.php) [function.require-once]: failed to open stream: No such file or directory in E:\xampp\htdocs\Spreadsheet\Excel\test.php on line 2

    Fatal error: require_once() [function.require]: Failed opening required ‘Excel/reader.php’ (include_path=’.;E:\xampp\php\PEAR’) in E:\xampp\htdocs\Spreadsheet\Excel\test.php on line 2

    i have path problem

  45. Kuppuram says

    In reade.php, Line – 261 $this->_ole =& new OLERead() should be changed to $this->_ole = new OLERead() as by reference assignment is deprecated.

  46. says

    I have special characters in columns

    col1 col2 col3 col4 col5
    1001 QUES Find the first 3 terms of a sequence whose nth term is n²/(n + 1) Q
    Given: For a sequence, tn = n²/(n+1) AS1
    To Find: t1, t2, t3 AS2
    Solution: tn = n²/(n+1) given AS3
    ∴ t1 = (1)²/ (1 + 1) substituting n = 1 AS4
    ∴ t1 = 1/ 2 AS5
    ∴ t2 = (2)²/ (2 + 1) substituting n = 2 AS6
    ∴ t1 = 4/ 3 AS7
    ∴ t3 = (3)²/ (3 + 1) substituting n = 3 AS8
    ∴ t3 = 9/ 4 AS9

    I am unable to import this data
    example
    ∴ t1 = (1)²/ (1 + 1) becomes ∴ t1 = (1)²/ (1 + 1)

    Note : In above line t1 is actually t1 in html

    However when i cut and paste in cuteeditor (text area)
    I could manage to get this data as it is using preg_replace

    Kindly suggest solution

    Thanks in advance

  47. paridhi says

    Warning: require_once(Spreadsheet/Excel/Reader/OLERead.php) [function.require-once]: failed to open stream: No such file or directory in /home/servel2h/public_html/schoolwork/xcel/reader.php on line 31

    Fatal error: require_once() [function.require]: Failed opening required ‘Spreadsheet/Excel/Reader/OLERead.php’ (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/servel2h/public_html/schoolwork/xcel/reader.php on line 31

  48. says

    hello friends i used the above code,but i get the following error “The filename test123.xls is not readable”
    plz some one help me

  49. MyoThein says

    // date for Unix function
    function date2Unix($excelDate) {
    return ($excelDate – 25569) * 86400;
    }

    // call function
    date2Unix($row[2]);

  50. says

    I have written this and getting an error as

    setOutputEncoding(‘CP1251′);
    $data->read(‘xltest.xls’);

    $conn = mysql_connect(“localhost”,”root”,””);
    mysql_select_db(“xldb”,$conn);

    for /* ($x = 2; $xsheets[1]["cells"]; $x++)*/
    ($x= 2; $x sheets[1]["cells"]); $x++) {
    $name = $data->sheets[1]["cells"][$x][1];
    $extension = $data->sheets[1]["cells"][$x][2];
    $email = $data->sheets[1]["cells"][$x][3];
    $sql = “INSERT INTO xltable (name,extension,email)
    VALUES (‘$name’,$extension,’$email’)”;
    echo $sql.”\n”;
    mysql_query($sql);
    }

    ?>

    error;-
    The filename xltest.xls is not readable

  51. Pkachhia says

    Hello Guys,

    This is very nice script, I have used it successfully into my application, but faced one problem.

    The excel file contains some fields blank, at that time I got error while import that excel file. I have tried to check that if field value is blank then assign 0(zero) but it throws error “Notice: Undefined offset:17 “.
    Please help me for how to handle blank columns?

  52. Anold Mathew says

    Hey
    I am trying to make it happen with the phpexcelreader but it keeps throwing an error ‘The filename is not readable’ with the other error ‘Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\Tutorial for exel-php-mysql\Excel\reader.php on line 261′ What might be the problem?

    My codes are down here, or would you please make for me downloadable working code source already configured up to that OLERead.php in one folder (Compressed folder) so that i can just create/import the database upon your working complete folder of scripts? If you do that i’ll appreciate much, then attach to my E-mail (anoldmathew@gmail.com)

    setOutputEncoding(‘CP1251′);
    $data->read(‘nolde.xlsx’);

    $db_name = “alexbigi”;
    $table_name = “students”;
    $conn = mysql_connect(“localhost”,”root”)or die(“could not connect to the DB!”);
    $db=mysql_select_db($db_name)or die (“couldn’t select the DB”);

    for ($x = 2; $x sheets[0]["cells"]); $x++) {
    $student_IDx = $data->sheets[0]["cells"][$x][1];
    $first_namex = $data->sheets[0]["cells"][$x][2];
    $sexx = $data->sheets[0]["cells"][$x][4];

    $sql = “INSERT INTO $table_name (student_ID, first_name, sex)
    VALUES (‘$student_IDx’,’$first_namex’,’$first_namex’)”;
    echo $sql.”\n”;
    mysql_query($sql);
    }

    ?>

    Thanks.!

  53. Xtian Noriell says

    Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\htdocs\Excel\Excel\reader.php on line 261

    Warning: require_once(Spreadsheet/Excel/Reader/OLERead.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Excel\Excel\reader.php on line 31

    Fatal error: require_once(): Failed opening required ‘Spreadsheet/Excel/Reader/OLERead.php’ (include_path=’.;C:\xampp\php\PEAR’) in C:\xampp\htdocs\Excel\Excel\reader.php on line 31

  54. afroz says

    i am getting an error which is

    The filename exceltestsheet.xls is not readable

    please help me

  55. Kavitha says

    Some time i got this error. The filename Registration_excel.xls is not readable.How to solve this error some one help me.

  56. Kavitha says

    $pho_ext = pathinfo($_FILES['filename']['name'],PATHINFO_EXTENSION);
    $photo_upload_dir = “Excel_export/”.$_FILES['filename']['name'].””;
    $pupload =move_uploaded_file($_FILES['filename']['tmp_name'],$photo_upload_dir);
    $data = new Spreadsheet_Excel_Reader();
    $data->setOutputEncoding(‘CP1251′);
    $data->read(‘Excel_export/’.$_FILES['filename']['name']);

    use this code (The filename Registration_excel.xls is not readable) not display this error.

  57. mageshwari says

    hi frds
    This code gives the clear idea about how to import excel file into MySQL.but I have doubt where to place the PHP-excel reader and excel writer,am think in www directory it is right ……

    thank u….

  58. jeepman28 says

    everything seams to work but when I run it I get this:
    Parse error: syntax error, unexpected end of file in /opt/lampp/htdocs/testrun.php on line 95

    Line 95 has this
    I am missing something?

  59. says

    when i tried the following code:

    require_once ‘Excel/reader.php';
    $data = new Spreadsheet_Excel_Reader();
    $data->setOutputEncoding(‘CP1251′);

    $data->read($_FILES['userfile']['name']);
    //columns:
    for ($x = 2; $x sheets[0]["cells"]); $x++) {
    $loan = $data->sheets[0]["cells"][$x][1];
    $grade = $data->sheets[0]["cells"][$x][2];
    $notes = $data->sheets[0]["cells"][$x][3];
    $sql = mysql_query(“INSERT INTO vtiger_leadsfc VALUES (‘$loan’,’$grade’,’$notes’)”);
    echo $sql.”\n”;
    if($sql){echo “successfully uploaded”;}

    The filename vtiger.xlsx is not readable. Please help me you save my life

  60. Allen says

    Follow instructions about downloading the files
    Change line 31 in reader.php to
    require_once ‘Excel/Reader/OLERead.php';

    Rename the folder names if you have to to reflect case sensitivity

    make your import.php file like below but using your own field names.

    Oh yeah. Make sure you have made the table you need with the required fields.

    require_once ‘Excel/reader.php';
    $data = new Spreadsheet_Excel_Reader();
    $data->setOutputEncoding(‘iso-8859-1′);// I want swedish letters to work too
    $data->read(‘my_excel_file.xls’);
    $conn = mysql_connect(“mysql_host”,”username”,”password”);
    mysql_select_db(“my_database”,$conn);
    for ($x=2; $xsheets[0]["cells"]); $x++) {
    $first_field = $data->sheets[0]["cells"][$x][1];
    $second_field= $data->sheets[0]["cells"][$x][2];
    $third_field= $data->sheets[0]["cells"][$x][2];
    $sql = “INSERT INTO myTable (first_field,second_field,third_field)
    VALUES (‘”.$first_field.”‘,'”.$second_field.”‘,'”.$third_field.”‘)”;
    mysql_query($sql);
    }
    echo “Done!”;

  61. Allen says

    $third_field= $data->sheets[0]["cells"][$x][2];

    should be

    $third_field= $data->sheets[0]["cells"][$x][3];

    I had something else there that was calculating from things I was reading from the excel file.

  62. Rejikanth says

    Deprecated: Assigning the return value of new by reference is deprecated in /Applications/XAMPP/xamppfiles/htdocs/PB-EIS/excelupload/Excel/reader.php on line 261
    INSERT INTO pbeis_student VALUES (‘Rani’,’51-160346′,’Green’,’Female’,’32952′,’reji2@gmail.com’,’8654071′,’AWEB’,’2′) INSERT INTO pbeis_student VALUES (‘Reji’,’51-160347′,’Green’,’Male’,’32952′,’reji3@gmail.com’,’8654071′,’ASWN’,’3′) INSERT INTO pbeis_student VALUES (‘Rifnaz’,’51-160348′,’Green’,’Male’,’32952′,’reji4@gmail.com’,’8654071′,’ADBF’,’4′) INSERT INTO pbeis_student VALUES (‘Ramzan’,’51-160349′,’Green’,’Male’,’32952′,’reji5@gmail.com’,’8654071′,’ABAC’,’5′)

    Error message got when check on Local Server. Please assist on this matter. When check the given coding in external server (free webhosting) its working.

  63. krsoni says

    i’m getting the same error as many of us are getting

    The filename xltest.xls is not readable

    please help how to resolve it.

    thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *