如何使用PHP

时间:2017-02-27 10:42:08

标签: php excel sqlite phpexcel phpdesktop

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

1 个答案:

答案 0 :(得分: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>';
?>

Reference