PHP用PHPExcel 对excel进行读写并写入到mysql数据库

这篇博客详细介绍了如何利用PHP的PHPExcel库来读取Excel文件,处理数据,并将这些数据有效地写入到MySQL数据库中,实现数据的导入与导出功能。
摘要由CSDN通过智能技术生成
//先下载好PHPExcel 放在与脚本同目录中
<?php
//ini_set("memory_limit","4096M");
//ini_set(”memory_limit”,”4096M”);

header("Content-Type: text/html;charset=utf-8"); 
$serverName = "";
$username = "root";//linux数据库名称
$password = "ssdddd";//数据库密码
$dbname = "jenkinsdata";//自己创建的数据库名
// 创建连接
ini_set('memory_limit', '512M');
$conn = new mysqli($serverName,$username, $password, $dbname);
// 检测连接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}	

//开始用PHPExcel进行读写
$tmp_name = './新建 Microsoft Excel 工作表.xlsx';
$uploadfile = 'C:\\wamp64\\www\\dist\\aa.xlsx';
error_reporting(E_ALL);
/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '../phpexcel/');
/** PHPExcel */
include 'PHPExcel.php';
/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';
/** PHPExcel_Reader */
include 'PHPExcel/Reader/Excel5.php';
include 'PHPExcel/Reader/Excel2007.php';
		//var_dump($filename);
		 // if($extend==".xlsx"){
			 //PHPExcel_CachedObjectStorageFactory::cache_in_memory_serialized; 
			 //$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory;  
			$cacheMethod =PHPExcel_CachedObjectStorageFactory::cache_in_memory; 

            PHPExcel_Settings::setCacheStorageMethod($cacheMethod);  
			   $objReader = PHPExcel_IOFactory::createReader('Excel2007');//use excel2007 for 2007 format 
		//}
		//else{
		//		$objReader = PHPExcel_IOFactory::createReader('Excel5');//use excel2007 for 2007 format 
		//}
        $objPHPExcel = $objReader->load($uploadfile); 
        $sheet = $objPHPExcel->getSheet(0); 
        $highestRow = $sheet->getHighestRow();           //取得总行数 
        $highestColumn = $sheet->getHighestColumn(); //取得总列数
		//var_dump($highestRow);
		//var_dump($highestColumn);
       
        $objWorksheet = $objPHPExcel->getActiveSheet();
		//var_dump($objWorksheet);
        $highestRow = $objWorksheet->getHighestRow(); 
       // echo 'highestRow='.$highestRow;
       // echo "<br>";
        $highestColumn = $objWorksheet->getHighestColumn();
        $highestColumnIndex = PH
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值