分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

phpexce 表格上传与下载

发布时间:2023-09-06 02:26责任编辑:苏小强关键词:暂无标签

<?php
//每天更新商家
include_once(dirname(dirname(__FILE__))."/config/const_cron.php");
require_once(dirname(dirname(__FILE__))."/phpexcel/PHPExcel.php");
echo "Begin ---".date(‘Y-m-d H:i:s‘)."\n\n";

$objMysql = new Mysql($databaseInfo["INFO_CA_DB_NAME"], $databaseInfo["INFO_CA_DB_HOST"], $databaseInfo["INFO_CA_DB_USER"], $databaseInfo["INFO_CA_DB_PASS"]);
$objMysqlBackend = new Mysql($databaseInfo["INFO_BACKEND_DB_NAME"], $databaseInfo["INFO_BACKEND_DB_HOST"], $databaseInfo["INFO_BACKEND_DB_USER"], $databaseInfo["INFO_BACKEND_DB_PASS"]);
$objMerchant = new NormalMerchant($objMysql);

$url = dirname(__FILE__);
$fileMerchant = $url."/".MERCHANT_TXT.".xlsx";
$fileCate = $url."/".CATEGORY_TXT.".xlsx";

$PHPReader = new PHPExcel_Reader_Excel2007();
if(!$PHPReader->canRead($fileMerchant)){
???$PHPReader = new PHPExcel_Reader_Excel5();
???if(!$PHPReader->canRead($fileMerchant)){
???????echo $fileMerchant."\033[01;40;32m read xlsx fault :".date("Y-m-d H:i:s")."\033[0m",PHP_EOL;
???????exit;
???}
}

if(defined("IS_CATEGORY") && IS_CATEGORY ==‘1‘){
?if(!$PHPReader->canRead($fileCate)){
???$PHPReader = new PHPExcel_Reader_Excel5();
???if(!$PHPReader->canRead($fileCate)){
???????echo $fileCate."\033[01;40;32m read xlsx fault :".date("Y-m-d H:i:s")."\033[0m",PHP_EOL;
???????exit;
???}
?}
?$PHPExcelC = $PHPReader->load($fileCate);
?$currentSheetC = $PHPExcelC->getSheet(0);
?$currentRowC = 2;
?$totleRowC = $currentSheetC->getHighestRow();
?$cateArr = [];
?for($currentRowC;$currentRowC<=$totleRowC;$currentRowC++){
???$MerId = intval(trim($currentSheetC->getCell(‘A‘.$currentRowC)->getValue()));
???$CatId = intval(trim($currentSheetC->getCell(‘B‘.$currentRowC)->getValue()));
???$Type = trim($currentSheetC->getCell(‘C‘.$currentRowC)->getValue());
???$catprimary = trim($currentSheetC->getCell(‘D‘.$currentRowC)->getValue());
???$cateArr[$currentRowC][‘MerId‘] = $MerId;
???$cateArr[$currentRowC][‘CatId‘] = $CatId;
???$cateArr[$currentRowC][‘Type‘] = $Type;
???$cateArr[$currentRowC][‘catprimary‘] = $catprimary;
?} ?
}

$PHPExcelM = $PHPReader->load($fileMerchant);
$currentSheetM = $PHPExcelM->getSheet(0);
$currentRowM = 1;
$totleRowM = $currentSheetM->getHighestRow();
//print_r($totleRowM);
$excute_num = 0;

$sta = START_TIME;
$num = NUM_EVERYDAY;
$timmm = date(‘Y-m-d‘);
$exx = (strtotime($timmm) - strtotime($sta))/(24*3600) ;
if((int)($num) >0){
?$sss = $exx * $num ;
?$eee = $sss + ($num-1) ;
}else{
?$sss = $exx * 300 ;
?$eee = $sss + 299 ;
}
for($currentRowM;$currentRowM<=$totleRowM;$currentRowM++){
?
?if($currentRowM < $sss ){
???continue;
?}
?if($currentRowM >$eee){
???break;
?}

?$ID = intval(trim($currentSheetM->getCell(‘A‘.$currentRowM)->getValue()));
?$Name = trim($currentSheetM->getCell(‘B‘.$currentRowM)->getValue());
?$domain = trim($currentSheetM->getCell(‘C‘.$currentRowM)->getValue());
?$UrlName = trim($currentSheetM->getCell(‘D‘.$currentRowM)->getValue());
?$UrlName = $UrlName.strtolower(trim($domain))."/";
?$OriginalUrl = trim($currentSheetM->getCell(‘E‘.$currentRowM)->getValue());
?$rank = trim($currentSheetM->getCell(‘F‘.$currentRowM)->getValue());
?$mer_country = trim($currentSheetM->getCell(‘G‘.$currentRowM)->getValue());
?$grade = trim($currentSheetM->getCell(‘H‘.$currentRowM)->getValue());
?$long_name = trim($currentSheetM->getCell(‘I‘.$currentRowM)->getValue());
?$logo = trim($currentSheetM->getCell(‘J‘.$currentRowM)->getValue());
?$about = addslashes(trim($currentSheetM->getCell(‘K‘.$currentRowM)->getValue()));
?$tips = addslashes(trim($currentSheetM->getCell(‘L‘.$currentRowM)->getValue()));

?$sql = "select id from normalmerchant where domain = ‘".addslashes($domain)."‘ limit 1";
?$dadd = $objMysql -> getRows($sql);
?if($dadd){
???continue;
???echo $domain." exists\n";
?}
?
?$sql = "INSERT INTO normalmerchant (id,Name, Logo, MobileLogo, AddTime, Editor, IsActive, OriginalUrl, UrlName,rank,grade,country,domain,TermName,about,tips) VALUES(‘$ID‘,‘".addslashes($Name)."‘, ‘$logo‘, ‘$logo‘, ‘".date(‘Y-m-d H:i:s‘)."‘, ‘vickyzhang‘, ‘YES‘, ‘".addslashes($OriginalUrl)."‘, ‘".addslashes($UrlName)."‘,‘$rank‘,‘$grade‘,‘$mer_country‘,‘".addslashes($domain)."‘,‘".addslashes($long_name)."‘,‘$about‘,‘$tips‘)";

?$qryId = $objMysql->query($sql);
?$mid = $objMysql->getLastInsertId($qryId);
?if(!$mid) continue;

?$sql = "INSERT INTO normalmerchant_addinfo (ID) VALUES(‘$mid‘)";
?$objMysql->query($sql);

?$excute_num++;
???if($totleRowC > 1){
?????if($mid){
???????foreach ($cateArr as $key => $value) {
?????????if($value[‘MerId‘] == $ID){
???????????if(trim($value[‘Type‘]) == ‘yes‘){
?????????????$type = 0;
???????????}else{
?????????????$type = 1;
???????????}
?????????????$sql = "INSERT INTO r_mer_category (MerId, CatId, Type, catprimary) VALUES(‘{$value[‘MerId‘]}‘,‘{$value[‘CatId‘]}‘,‘{$type}‘, ‘{$value[‘catprimary‘]}‘)";
?????????????echo $sql;
???????????$objMysql->query($sql);
?????????}
???????}
?????}
???}
?echo $mid."\r\n";
}
echo "insert mer cnt :".$i."\r\n";

下载链接https://stuhausteducn-my.sharepoint.com/:u:/g/personal/141419030129_stu_haust_edu_cn/EWIuoOZOLGdAlWfJP3V43pcBMMTFig2uVhJEMDc_o2C1-g?e=AXJ3LV

phpexce 表格上传与下载

原文地址:https://www.cnblogs.com/yaradish/p/10139883.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved