fetch excel to database in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CKS421
    New Member
    • Mar 2014
    • 1

    fetch excel to database in php

    when use this code IN SERVER then found fatal error:

    Fatal error: Class 'COM' not found in /home/schoolsb/public_html/admin/admin/addexcelstudent .php on line 33

    PLEASE HELP ME

    <?php

    $excel_app = new COM("Excel.appl ication") or Die ("Did not connect");
    $Workbook = $excel_app->Workbooks->Open('C:\san1. xls') or Die('Did not open filename');
    $Worksheet = $Workbook->Worksheets(1 );
    $Worksheet->activate;



    $username = "root";
    $hostname = "localhost" ;

    //connection to the database
    $dbhandle = mysql_connect($ hostname, $username) or die("Unable to connect to MySQL");
    echo "Connected to MySQL<br>";


    //select a database to work with
    $selected = mysql_select_db ("academics",$d bhandle) or die("Could not select examples");

    echo "hi";
    $i=2;
    while($Workshee t->Cells->Item($i,1) != "")
    {
    $strSQL = "";
    $strSQL .= "INSERT INTO tbl";
    $strSQL .= "(rollno,crseno ,marks,grade,at t)";
    $strSQL .= "VALUES";
    $strSQL .= "('".$Works heet->Cells->Item($i,1)."', '".$Workshee t->Cells->Item($i,2)." ' ";
    #$strSQL .= ",'".$Works heet->Cells->Item($i,3)."', '".$Workshee t->Cells->Item($i,4)." ' ";
    $strSQL .= ",'".$Works heet->Cells->Item($i,3)."', '".$Workshee t->Cells->Item($i,4)." ') ";
    mysql_query($st rSQL);
    $i++;
    }

    //*** Close MySQL ***//
    @mysql_close($d bhandle);

    //*** Close & Quit ***//
    $excel_app->Application->Quit();
    $excel_app = null;
    $Workbook = null;
    $Worksheet = null;

    ?>
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    Please post your code so that we know where line 33 is.

    This website has a nice feature for it!, use the '[CODE/]' tags around your code......

    Comment

    Working...