导出
This commit is contained in:
+4
-22
@@ -631,44 +631,26 @@ abstract class QfShop
|
|||||||
->setDescription("Export by qfshop"); //设置备注
|
->setDescription("Export by qfshop"); //设置备注
|
||||||
|
|
||||||
$PHPSheet = $PHPExcel->getActiveSheet();
|
$PHPSheet = $PHPExcel->getActiveSheet();
|
||||||
$PHPSheet->setTitle($this->excelTitle); //给当前活动sheet设置名称
|
|
||||||
|
|
||||||
$PHPSheet->mergeCells('A1:' . $this->excelCells[count($excelField) - 1] . "1");
|
|
||||||
$PHPSheet->setCellValue('A1', $this->excelTitle);
|
|
||||||
$PHPSheet->getRowDimension(1)->setRowHeight(40);
|
|
||||||
$PHPSheet->getStyle('A1')->getFont()->setSize(16)->setBold(true); //字体大小
|
|
||||||
|
|
||||||
$PHPSheet->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); //水平方向上对齐
|
|
||||||
$PHPSheet->getStyle('A1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); //垂直方向上中间居中
|
|
||||||
$PHPSheet->getStyle('A1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); //垂直方向上中间居中
|
|
||||||
|
|
||||||
if (count($excelField) > count($this->excelCells)) {
|
if (count($excelField) > count($this->excelCells)) {
|
||||||
echo 'Error and you need check Excel Cells Keys...';
|
echo 'Error and you need check Excel Cells Keys...';
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
$PHPSheet->getRowDimension(2)->setRowHeight(30);
|
$PHPSheet->getRowDimension(1)->setRowHeight(30);
|
||||||
for ($column = 0; $column < count($excelField); $column++) {
|
for ($column = 0; $column < count($excelField); $column++) {
|
||||||
$PHPSheet->setCellValue($this->excelCells[$column] . "2", $excelField[$column][1]);
|
$PHPSheet->setCellValue($this->excelCells[$column] . "1", $excelField[$column][1]);
|
||||||
$PHPSheet->getStyle($this->excelCells[$column])->getNumberFormat()
|
$PHPSheet->getStyle($this->excelCells[$column])->getNumberFormat()
|
||||||
->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
|
->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
|
||||||
for ($line = 0; $line < count($datalist); $line++) {
|
for ($line = 0; $line < count($datalist); $line++) {
|
||||||
$string = $datalist[$line][$excelField[$column][0]];
|
$string = $datalist[$line][$excelField[$column][0]];
|
||||||
$PHPSheet->getColumnDimension($this->excelCells[$column])->setWidth(20);
|
$PHPSheet->getColumnDimension($this->excelCells[$column])->setWidth(20);
|
||||||
$PHPSheet->setCellValueExplicit($this->excelCells[$column] . ($line + 3), $string, \PHPExcel_Cell_DataType::TYPE_STRING);
|
$PHPSheet->setCellValueExplicit($this->excelCells[$column] . ($line + 2), $string, \PHPExcel_Cell_DataType::TYPE_STRING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//***********************画出单元格边框*****************************
|
//***********************画出单元格边框*****************************
|
||||||
$styleArray = array(
|
$styleArray = array(
|
||||||
'borders' => array(
|
|
||||||
'inside' => array(
|
|
||||||
'style' => \PHPExcel_Style_Border::BORDER_THIN, //细边框
|
|
||||||
//'color' => array('argb' => 'FFFF0000'),
|
|
||||||
),
|
|
||||||
'outline' => array(
|
|
||||||
'style' => \PHPExcel_Style_Border::BORDER_THICK, //边框是粗的
|
|
||||||
//'color' => array('argb' => 'FFFF0000'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
$PHPSheet->getStyle('A2:' . $this->excelCells[count($excelField) - 1] . (count(
|
$PHPSheet->getStyle('A2:' . $this->excelCells[count($excelField) - 1] . (count(
|
||||||
$datalist
|
$datalist
|
||||||
|
|||||||
@@ -217,16 +217,15 @@ class Source extends QfShop
|
|||||||
|
|
||||||
//删除这个文件
|
//删除这个文件
|
||||||
unlink("./uploads/".$saveName);
|
unlink("./uploads/".$saveName);
|
||||||
|
|
||||||
// 生成二维码
|
// 生成二维码
|
||||||
foreach ($excel_array as $k => $v) {
|
foreach ($excel_array as $k => $v) {
|
||||||
$patterns = '/^\d+\.|\d+\-/';
|
$patterns = '/^\d+\.|\d+\-/';
|
||||||
$title = '';
|
$title = '';
|
||||||
if (preg_match('/http[^ ]+/', $v[2], $matches)) {
|
if (!empty($v[2]) && preg_match('/http[^ ]+/', $v[2], $matches)) {
|
||||||
$title = preg_replace($patterns, '', $v[1]);
|
$title = preg_replace($patterns, '', $v[1]);
|
||||||
$url = $matches[0];
|
$url = $matches[0];
|
||||||
} else {
|
} else {
|
||||||
if (preg_match('/http[^ ]+/', $v[3], $matches)) {
|
if (!empty($v[3]) && preg_match('/http[^ ]+/', $v[3], $matches)) {
|
||||||
$title = preg_replace($patterns, '', $v[2]);
|
$title = preg_replace($patterns, '', $v[2]);
|
||||||
$url = $matches[0];
|
$url = $matches[0];
|
||||||
} else {
|
} else {
|
||||||
@@ -421,4 +420,54 @@ class Source extends QfShop
|
|||||||
return jok('获取成功',$res['data']);
|
return jok('获取成功',$res['data']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function excel()
|
||||||
|
{
|
||||||
|
$error = $this->access();
|
||||||
|
if ($error) {
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询数据
|
||||||
|
$map = [];
|
||||||
|
$filter = input('');
|
||||||
|
foreach ($filter as $k => $v) {
|
||||||
|
if ($k == 'filter') {
|
||||||
|
$k = input('filter');
|
||||||
|
$v = input('keyword');
|
||||||
|
}
|
||||||
|
if ($v === '' || $v === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (array_key_exists($k, $this->searchFilter)) {
|
||||||
|
switch ($this->searchFilter[$k]) {
|
||||||
|
case "like":
|
||||||
|
array_push($map, [$k, 'like', "%" . $v . "%"]);
|
||||||
|
break;
|
||||||
|
case "=":
|
||||||
|
array_push($map, [$k, '=', $v]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$field = 'title,url';
|
||||||
|
$dataList = $this->model->field($field)->where($map)->select();
|
||||||
|
$excelField = [
|
||||||
|
"title" => "资源名称",
|
||||||
|
"url" => "资源地址",
|
||||||
|
];
|
||||||
|
$data = $dataList->toArray();
|
||||||
|
|
||||||
|
$this->excelField = $excelField;
|
||||||
|
$this->exportExcelData($dataList);
|
||||||
|
print_r(12);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button icon="el-icon-plus" size="small" @click="clickAdd" plain>添加资源</el-button>
|
<el-button icon="el-icon-plus" size="small" @click="clickAdd" plain>添加资源</el-button>
|
||||||
<el-button icon="el-icon-plus" size="small" @click="ImportShow" plain>导入资源</el-button>
|
<el-button icon="el-icon-plus" size="small" @click="ImportShow" plain>导入资源</el-button>
|
||||||
|
<el-button icon="el-icon-document-copy" size="small" @click="getExport" plain>导出资源</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<div style="float:right">
|
<div style="float:right">
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
@@ -312,6 +313,18 @@
|
|||||||
this.$refs.ImportUpload.submit();
|
this.$refs.ImportUpload.submit();
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
//数据导出
|
||||||
|
getExport(){
|
||||||
|
var that = this;
|
||||||
|
var filters = Object.assign({}, PostBase, that.search);
|
||||||
|
var url = '/admin/source/excel?';
|
||||||
|
for (let key in filters) {
|
||||||
|
url += key + "=" + filters[key] + "&";
|
||||||
|
}
|
||||||
|
window.open(url);
|
||||||
|
that.$message.success('数据导出成功');
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user