【问题标题】:How to read data from Excel files and insert into a Sqlite Database using PHP [duplicate]如何使用 PHP 从 Excel 文件中读取数据并插入 Sqlite 数据库 [重复]
【发布时间】:2017-02-27 10:42:08
【问题描述】:

我有一个名为:db 的 sqlite 数据库,其中的表名为 student,列:nameemail。同样,我有 excel 文件 studentdb.xlsx 具有相似的列名和数千行。我想读取excel文件并通过php脚本将数据导入sqlite数据库。该怎么做?

【问题讨论】:

    标签: php excel sqlite phpexcel phpdesktop


    【解决方案1】:

    为此,您必须使用像 SimpleExcel 这样的第三方库。

    解析 Excel 2003 XML 文件,简化:

    <?php
    
    use SimpleExcel\SimpleExcel;
    
    require_once('../your/project/directory/here/lib/SimpleExcel/SimpleExcel.php'); // load the main class file (if you're not using autoloader)
    
    $excel = new SimpleExcel('xml');                    // instantiate new object (will automatically construct the parser & writer type as XML)
    
    $excel->parser->loadFile('example.xml');            // load an XML file from server to be parsed
    
    $foo = $excel->parser->getField();                  // get complete array of the table
    $bar = $excel->parser->getRow(3);                   // get specific array from the specified row (3rd row)
    $baz = $excel->parser->getColumn(4);                // get specific array from the specified column (4th row)
    $qux = $excel->parser->getCell(2,1);                // get specific data from the specified cell (2nd row in 1st column)
    
    echo '<pre>';
    print_r($foo);                                      // echo the array
    echo '</pre>';
    ?>
    

    Reference

    【讨论】:

    • 您能否详细说明解决方案@Mayank Pandeyz
    • 大家好,问题已解决!我使用 PHPExcel 库将行从 xlsx 文件导入到 sqlite 数据库。我从这里获得了帮助:link
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多