本文整理匯總了PHP中Import::excel方法的典型用法代碼示例。如果您正苦於以下問題:PHP Import::excel方法的具體用法?PHP Import::excel怎麽用?PHP Import::excel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Import
的用法示例。
在下文中一共展示了Import::excel方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: ajax_upload_vgoods_sn
function ajax_upload_vgoods_sn($filename = "", $rt = array())
{
@set_time_limit(600);
//最大運行時間
$gid = $rt['gid'];
$fop = Import::fileop();
unset($rt);
$vgoods_type = $this->App->findvar("SELECT vgoods_type FROM `{$this->App->prefix()}userconfig` WHERE type = 'basic' LIMIT 1");
if (!empty($_FILES[$filename]['tmp_name'])) {
$yuming = str_replace(array('www', '.'), '', $_SERVER["HTTP_HOST"]);
if (!empty($yuming)) {
$yuming = $yuming . DS;
}
$fn = SYS_PATH . 'cache' . DS . $yuming . 'vgoods' . DS . 'vgoodssn.xls';
if (file_exists($fn)) {
unlink($fn);
}
//刪除原來文件
$fop->copyfile($filename, $fn);
//複製文件到服務器
if (!file_exists($fn)) {
$fop->copyfile($filename, $fn);
if (!file_exists($fn)) {
echo '<script> alert("上傳時發生意外錯誤!"); </script>';
return false;
}
}
$data = Import::excel();
$data->read($fn);
//讀取文件
$importkey = $data->sheets[0]['cells'][1];
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
$rD = array();
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
$rD[] = $data->sheets[0]['cells'][$i][$j];
}
if (empty($rD[0])) {
continue;
}
$rtd = array();
$rtd['goods_id'] = $gid;
if ($vgoods_type == '2') {
$rtd['goods_pass'] = $rD[0];
$sn = $rD[0];
} else {
$rtd['goods_pass'] = $rD[1];
$rtd['goods_sn'] = $rD[0];
$sn = $rD[1];
}
$rtd['addtime'] = mktime();
$sql = "SELECT id FROM `{$this->App->prefix()}goods_sn` WHERE goods_id='{$gid}' AND goods_pass='{$sn}' LIMIT 1";
$id = $this->App->findvar($sql);
if ($id > 0) {
continue;
}
$this->App->insert('goods_sn', $rtd);
}
echo '<script> alert("上傳成功!");</script>';
return false;
}
echo '<script> alert("上傳失敗!");</script>';
return true;
}
示例2: ajax_upload
function ajax_upload($filename = "")
{
$uid = $this->Session->read('User.uid');
$rank = $this->Session->read('User.rank');
$active = $this->App->findvar("SELECT active FROM `{$this->App->prefix()}user` WHERE user_id='{$uid}'");
$this->Session->write('User.active', $active);
if ($active != '1') {
echo '<script> alert("抱歉,你賬戶處於失活狀態,請聯係管理員激活!"); </script>';
return false;
}
if (!($uid > 0) || $rank != '10') {
echo '<script> alert("抱歉,你沒有權限上傳!"); </script>';
return false;
}
$fop = Import::fileop();
$fn = SYS_PATH . 'cache' . DS . 'admin-' . $uid . '.php';
$fop->writefile($fn, "");
$tw_s = intval($GLOBALS['LANG']['th_width_s']) > 0 ? intval($GLOBALS['LANG']['th_width_s']) : 200;
$th_s = intval($GLOBALS['LANG']['th_height_s']) > 0 ? intval($GLOBALS['LANG']['th_height_s']) : 200;
$tw_b = intval($GLOBALS['LANG']['th_width_b']) > 0 ? intval($GLOBALS['LANG']['th_width_b']) : 450;
$th_b = intval($GLOBALS['LANG']['th_height_b']) > 0 ? intval($GLOBALS['LANG']['th_height_b']) : 450;
if (!empty($_FILES[$filename]['tmp_name'])) {
$fn = SYS_PATH . 'cache' . DS . 'admin-upload-' . $uid . '.xls';
if (file_exists($fn)) {
unlink($fn);
}
//刪除原來文件
$fop->copyfile($filename, $fn);
//複製文件到服務器
if (!file_exists($fn)) {
$fop->copyfile($filename, $fn);
if (!file_exists($fn)) {
echo '<script> alert("上傳時發生意外錯誤!"); </script>';
return false;
}
}
$data = Import::excel();
$data->read($fn);
//讀取文件
$importkey = $data->sheets[0]['cells'][1];
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
//以下注釋的for循環打印excel表數據
$this->rtData = array();
//商品數據
$this->rtData_gallery = array();
//商品相冊
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
$this->goods_key($importkey[$j], $data->sheets[0]['cells'][$i][$j]);
//傳送 鍵=>值 處理
}
$this->rtData['is_on_sale'] = '0';
$this->rtData['add_time'] = mktime();
$this->rtData['uid'] = $uid;
$inData = $this->rtData;
//print_r($inData); exit;
$goods_id = 0;
//檢查該商品已經存在數據庫中
$sn = $inData['goods_sn'];
//優先級是商品條形碼檢查
if (!empty($sn)) {
$sql = "SELECT goods_id FROM `{$this->App->prefix()}goods` WHERE goods_sn='{$sn}'";
$goods_id = $this->App->findvar($sql);
//if(!empty($snvar)) continue;
}
/*else{
$sa = $inData['goods_name']; //商品名稱檢查是否該商品已經存在
if(!empty($sa)){ //最後更新:2012-12-11 10:26
$sql = "SELECT goods_id FROM `{$this->App->prefix()}goods` WHERE goods_name='$sa'";
$goods_id = $this->App->findvar($sql);
//if(!empty($savar)) continue;
}
}*/
if (!empty($inData['goods_name'])) {
//商品圖片
$val = $inData['original_img'];
if (!empty($val)) {
$pa = dirname($val);
$thumb = basename($val);
if (is_file(SYS_PATH . $pa . DS . 'thumb_s' . DS . $thumb)) {
$pp = SYS_PATH . $pa . DS . 'thumb_s' . DS . mktime() . $thumb;
$pps = $pa . '/thumb_s/' . mktime() . $thumb;
} else {
$pp = SYS_PATH . $pa . DS . 'thumb_s' . DS . $thumb;
$pps = $pa . '/thumb_s/' . $thumb;
}
Import::img()->thumb(SYS_PATH . $val, $pp, $tw_s, $th_s);
//小縮略圖
$inData['goods_thumb'] = $pps;
if (is_file(SYS_PATH . $pa . DS . 'thumb_b' . DS . $thumb)) {
$pp = SYS_PATH . $pa . DS . 'thumb_b' . DS . mktime() . $thumb;
$pps = $pa . '/thumb_b/' . mktime() . $thumb;
} else {
$pp = SYS_PATH . $pa . DS . 'thumb_b' . DS . $thumb;
$pps = $pa . '/thumb_b/' . $thumb;
}
Import::img()->thumb(SYS_PATH . $val, $pp, $tw_b, $th_b);
//大縮略圖
$inData['goods_img'] = $pps;
}
if ($goods_id > 0) {
//.........這裏部分代碼省略.........