navcat excel数据导入mysql的方法

Posted newmiracle宇宙

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了navcat excel数据导入mysql的方法相关的知识,希望对你有一定的参考价值。

navcat excel数据导入mysql的方法

先navcat导出 xls格式 然后把数据复制到往这个xls里 (按照这个xls格式) 然后导入mysql就行了

如果导入的过程无法识别excel里的内容 就想办法第一行能识别 自己重新输入下 就行 一般都是格式问题 第一行通过就行了

 

 

 

下面是通过phpexcel读取excel里的内容 然后存入数据库的

<pre>
public function daochuexcel()
{
set_time_limit(0);
ini_set("memory_limit","512M");
error_reporting(E_ALL);
ini_set(‘display_errors‘, TRUE);
ini_set(‘display_startup_errors‘, TRUE);
date_default_timezone_set(‘Asia/Shanghai‘);

if (PHP_SAPI == ‘cli‘)
die(‘This example should only be run from a Web Browser‘);

/** Include PHPExcel */
require_once dirname(__FILE__) . ‘/../../../Public/phpexcel/Classes/PHPExcel.php‘;


// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

// Set document properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");


// Add some data
$objPHPExcel->getActiveSheet()->getColumnDimension(‘B‘)->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension(‘C‘)->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension(‘f‘)->setWidth(20);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue(‘A1‘, ‘姓名‘)
->setCellValue(‘B1‘, ‘手机号‘)
->setCellValue(‘C1‘, ‘奖品名字‘);

$VModel = new HuanShanVoteModel();
$sql = "select u.name,u.phone,p.prize_id from guagua_prize as p left join guaguaka_userinfo as u on p.openid=u.openid";
$list = $VModel->query($sql);
foreach ($list as $k => $v) {
$prizeinfo = $this->prize_id($v[‘prize_id‘]);
$list[$k][‘prize_shortname‘] = $prizeinfo[‘prize_shortname‘];
}


$i = 1;
foreach ($list as $k => $v) {
$i++;
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue(‘A‘ . $i, $v[‘name‘])
->setCellValue(‘B‘ . $i, $v[‘phone‘])
->setCellValue(‘C‘ . $i, $v[‘prize_shortname‘]);
}


$objPHPExcel->getActiveSheet()->setTitle(‘Simple‘);


// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);


// Redirect output to a client’s web browser (Excel5)
header(‘Content-Type: application/vnd.ms-excel‘);
header(‘Content-Disposition: attachment;filename="01simple.xls"‘);
header(‘Cache-Control: max-age=0‘);
// If you‘re serving to IE 9, then the following may be needed
header(‘Cache-Control: max-age=1‘);

// If you‘re serving to IE over SSL, then the following may be needed
header(‘Expires: Mon, 26 Jul 1997 05:00:00 GMT‘); // Date in the past
header(‘Last-Modified: ‘ . gmdate(‘D, d M Y H:i:s‘) . ‘ GMT‘); // always modified
header(‘Cache-Control: cache, must-revalidate‘); // HTTP/1.1
header(‘Pragma: public‘); // HTTP/1.0

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, ‘Excel5‘);
$objWriter->save(‘php://output‘);
exit;
}
</pre>

 

以上是关于navcat excel数据导入mysql的方法的主要内容,如果未能解决你的问题,请参考以下文章

Navcat连接Mysql报错1521

navcat无法远程连接mysql数据库解决办法

将Excel数据导入mysql数据库的几种方法

mysql 数据库导入导出命令行

mysql 每个表只导出1000条数据

php导入Excel进mysql数据库