新聞中心
php中如何將execl的數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫中
1.使用PHP
儀征網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、自適應(yīng)網(wǎng)站建設(shè)等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。創(chuàng)新互聯(lián)成立于2013年到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。
Excel
Parser
Pro軟件,但是這個(gè)軟件為收費(fèi)軟件;
2.可將EXCEL表保存為CSV格式,然后通過
phpmyadmin
或者SQLyog導(dǎo)入,SQLyog導(dǎo)入的方法為:
·將EXCEL表另存為CSV形式;
·打開SQLyog,對(duì)要導(dǎo)入的表格
右擊
,點(diǎn)擊“導(dǎo)入”-“導(dǎo)入使用加載本地CSV數(shù)據(jù)”;
·在彈出的對(duì)話框中,點(diǎn)擊“改變..”,把選擇“填寫excel友好值”,點(diǎn)擊確定;
·在“從文件導(dǎo)入”中選擇要導(dǎo)入的CSV文件路徑,點(diǎn)擊“導(dǎo)入”即可導(dǎo)入數(shù)據(jù)到表上;
3.一個(gè)比較笨的手工方法,就是先利用excel生成
sql語句
,然后再到mysql中運(yùn)行,這種方法適用于
excel表格
導(dǎo)入到各類
sql數(shù)據(jù)庫
:
·假設(shè)你的表格有A、B、C三
列數(shù)據(jù)
,希望導(dǎo)入到你的數(shù)據(jù)庫中表格tablename,對(duì)應(yīng)的字段分別是col1、col2、col3
·在你的表格中增加一列,利用excel的公式自動(dòng)生成sql語句,具體方法如下:
1)增加一列(假設(shè)是D列)
2)在第一行的D列,就是D1中輸入公式:
=CONCATENATE("insert
into
tablename
(col1,col2,col3)
values
(",A1,",",B1,",",C1,");")
3)此時(shí)D1已經(jīng)生成了如下的sql語句:
insert
into
table
(col1,col2,col3)
values
('a','11','33');
4)將D1的公式復(fù)制到所有行的D列(就是用鼠標(biāo)點(diǎn)住D1單元格的右下角一直拖拽下去啦)
5)此時(shí)D列已經(jīng)生成了所有的sql語句
6)把D列復(fù)制到一個(gè)純文本文件中,假設(shè)為sql.txt
·把sql.txt放到數(shù)據(jù)庫中運(yùn)行即可,你可以用命令行導(dǎo)入,也可以用phpadmin運(yùn)行。
如何用php實(shí)現(xiàn)將excel導(dǎo)入到數(shù)據(jù)庫中
把excel
改為
cvs文件
?
//連接數(shù)據(jù)庫文件
$connect=mysql_connect("localhost","admin","admin")
or
die("鏈接數(shù)據(jù)庫失??!");
//連接數(shù)據(jù)庫(test)
mysql_select_db("testcg",$connect)
or
die
(mysql_error());
$temp=file("test.csv");//連接EXCEL文件,格式為了.csv
for
($i=0;$i
count($temp);$i++)
{
$string=explode(",",$temp[$i]);//通過循環(huán)得到EXCEL文件中每行記錄的值
//將EXCEL文件中每行記錄的值插入到數(shù)據(jù)庫中
$q="insert
into
ceshi
(name,num,dom)
values('$string[0]','$string[1]','$string[2]');";
mysql_query($q)
or
die
(mysql_error());
if
(!mysql_error());
{
echo
"
成功導(dǎo)入數(shù)據(jù)!";
}
echo
$string[4]."\n";
unset($string);
}
?
php讀取excel并寫入到數(shù)據(jù)庫
用 php Win32 OLE
##Using OLE;
read('Book1.xls');
// print number of rows, columns and sheets
echo "Number of sheets: " . sizeof($excel-sheets) . "\n";
for ($x=0; $xsheets); $x++) {
echo "Number of rows in sheet " . ($x+1) . ": " . $excel-sheets[$x]["numRows"] . "\n";
echo "Number of columns in sheet " . ($x+1) . ": " . $excel-sheets[$x]["numCols"] . "\n";
excel 可以當(dāng)php數(shù)據(jù)庫嗎
PHP 如何利用phpexcel導(dǎo)入數(shù)據(jù)庫
廢話不多說,直接上代碼吧
?php
error_reporting(E_ALL); //開啟錯(cuò)誤
set_time_limit(0); //腳本不超時(shí)
date_default_timezone_set('Europe/London'); //設(shè)置時(shí)間
/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '');//設(shè)置環(huán)境變量
/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';
//$inputFileType = 'Excel5'; //這個(gè)是讀 xls的
$inputFileType = 'Excel2007';//這個(gè)是計(jì)xlsx的
//$inputFileName = './sampleData/example2.xls';
$inputFileName = './sampleData/book.xlsx';
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'br /';
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader-load($inputFileName);
/*
$sheet = $objPHPExcel-getSheet(0);
$highestRow = $sheet-getHighestRow(); //取得總行數(shù)
$highestColumn = $sheet-getHighestColumn(); //取得總列
*/
$objWorksheet = $objPHPExcel-getActiveSheet();//取得總行數(shù)
$highestRow = $objWorksheet-getHighestRow();//取得總列數(shù)
echo 'highestRow='.$highestRow;
echo "br";
$highestColumn = $objWorksheet-getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//總列數(shù)
echo 'highestColumnIndex='.$highestColumnIndex;
echo "br /";
$headtitle=array();
for ($row = 1;$row = $highestRow;$row++)
{
$strs=array();
//注意highestColumnIndex的列數(shù)索引從0開始
for ($col = 0;$col $highestColumnIndex;$col++)
{
$strs[$col] =$objWorksheet-getCellByColumnAndRow($col, $row)-getValue();
}
$info = array(
'word1'="$strs[0]",
'word2'="$strs[1]",
'word3'="$strs[2]",
'word4'="$strs[3]",
);
//在這兒,你可以連接,你的數(shù)據(jù)庫,寫入數(shù)據(jù)庫了
print_r($info);
echo 'br /';
}
?
網(wǎng)站題目:php用xls做數(shù)據(jù)庫 php數(shù)據(jù)庫怎么建
網(wǎng)頁URL:http://fisionsoft.com.cn/article/doipipi.html