1

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

4

1 回答 1

0

为此,您必须使用第三方库,例如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>';
?>

参考

于 2017-02-27T10:47:16.037 回答