【发布时间】:2017-02-27 10:42:08
【问题描述】:
我有一个名为:db 的 sqlite 数据库,其中的表名为 student,列:name 和 email。同样,我有 excel 文件 studentdb.xlsx 具有相似的列名和数千行。我想读取excel文件并通过php脚本将数据导入sqlite数据库。该怎么做?
【问题讨论】:
标签: php excel sqlite phpexcel phpdesktop
我有一个名为:db 的 sqlite 数据库,其中的表名为 student,列:name 和 email。同样,我有 excel 文件 studentdb.xlsx 具有相似的列名和数千行。我想读取excel文件并通过php脚本将数据导入sqlite数据库。该怎么做?
【问题讨论】:
标签: php excel sqlite phpexcel phpdesktop
为此,您必须使用像 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>';
?>
【讨论】: