|
@@ -812,7 +812,7 @@ class Database
|
|
|
|
|
|
# 增加下载报表按钮
|
|
|
if (isset($config['manage']['excel'])) {
|
|
|
- $config['manage']['button']['导出数据'] = 'onclick="$(\'#form1\').attr(\'action\', \'' . $this->url('excel') . '\');list_search($(this))"';
|
|
|
+ $config['manage']['button']['导出数据'] = 'onclick="location.href=\''.$this->url('excel').'\'"';
|
|
|
}
|
|
|
# 增加回收站
|
|
|
if (isset($config['struct']['state']) && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete'] && isset($config['manage']['_list']['value']['delete'])))) {
|
|
@@ -1188,94 +1188,141 @@ class Database
|
|
|
|
|
|
if ($data) {
|
|
|
$config = $this->config();
|
|
|
+ if (isset($config['manage']['excel']) && $config['manage']['excel']) {
|
|
|
+ $method = 'excel_' . $config['manage']['excel'];
|
|
|
+ $info = $this->info();
|
|
|
+ $data = $this->getAdminInfo($data);
|
|
|
+ $this->$method($info, $data, $config);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- $xls = new \PHPExcel();
|
|
|
+ //print_r($data);die;
|
|
|
+ }
|
|
|
|
|
|
- /*
|
|
|
- if(class_exists('\\PHPExcel'))
|
|
|
- {
|
|
|
- $xls = new \PHPExcel();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Dever::debug('Class \'PHPExcel\' not found');
|
|
|
- die;
|
|
|
+ private function excel_csv($info, $data, $config)
|
|
|
+ {
|
|
|
+ $file = $info['list_header'] . '的' . $info['list_desc'] . '-' . $info['project_name'] . '.csv';
|
|
|
+
|
|
|
+ $header = $body = array();
|
|
|
+ $i = 0;
|
|
|
+ foreach ($config['struct'] as $k => $v) {
|
|
|
+ if (isset($v['list']) && $v['list']) {
|
|
|
+ # 处理权限
|
|
|
+ if (isset($v['auth'])) {
|
|
|
+ $auth = $this->value($v['auth'], $data);
|
|
|
+ if (!$auth) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $v['name'] = mb_convert_encoding($v['name'],'gb2312','utf-8');
|
|
|
+ $header[$i] = $v['name'];
|
|
|
+ $i++;
|
|
|
+ $j = 0;
|
|
|
+ foreach ($data as $ki => $vi) {
|
|
|
+ if (isset($vi[$k])) {
|
|
|
+ $value = $vi[$k];
|
|
|
+
|
|
|
+ if (is_string($v['list'])) {
|
|
|
+ $value = $this->value($v['list'], $data[$ki], $config['struct']);
|
|
|
+ }
|
|
|
+ if (isset($v['option'])) {
|
|
|
+ $v['option'] = $this->option($v['option']);
|
|
|
+
|
|
|
+ if (isset($v['option'][$value])) {
|
|
|
+ if (is_array($v['option'][$value])) {
|
|
|
+ $value = $v['option'][$value]['name'];
|
|
|
+ } else {
|
|
|
+ $value = $v['option'][$value];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $value = mb_convert_encoding($value,'gb2312','utf-8');
|
|
|
+
|
|
|
+ $body[$j][] = $value;
|
|
|
+ $j++;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- */
|
|
|
+ }
|
|
|
+ //print_r($header);
|
|
|
+ //print_r($body);die;
|
|
|
|
|
|
- $xls->getProperties()->setCreator("Dever Excel")
|
|
|
- ->setLastModifiedBy("Dever Excel")
|
|
|
- ->setTitle("Office 2007 XLSX Analysis Document")
|
|
|
- ->setSubject("Office 2007 XLSX Analysis Document")
|
|
|
- ->setDescription("Dever Excel")
|
|
|
- ->setKeywords("Dever Excel")
|
|
|
- ->setCategory("Dever Excel");
|
|
|
+ Dever::csv($body, $header, $file);
|
|
|
+ }
|
|
|
|
|
|
- $info = $this->info();
|
|
|
+ private function excel_phpexcel($info, $data, $config)
|
|
|
+ {
|
|
|
+ $xls = new \PHPExcel();
|
|
|
|
|
|
- $name = $info['list_header'] . '的' . $info['list_desc'] . '-' . $info['project_name'];
|
|
|
- # 全局导出
|
|
|
- $start = 65;
|
|
|
- $act = $xls->setActiveSheetIndex(0);
|
|
|
+ $xls->getProperties()->setCreator("Dever Excel")
|
|
|
+ ->setLastModifiedBy("Dever Excel")
|
|
|
+ ->setTitle("Office 2007 XLSX Analysis Document")
|
|
|
+ ->setSubject("Office 2007 XLSX Analysis Document")
|
|
|
+ ->setDescription("Dever Excel")
|
|
|
+ ->setKeywords("Dever Excel")
|
|
|
+ ->setCategory("Dever Excel");
|
|
|
|
|
|
- $act->setTitle($name);
|
|
|
+ $name = $info['list_header'] . '的' . $info['list_desc'] . '-' . $info['project_name'];
|
|
|
+ # 全局导出
|
|
|
+ $start = 65;
|
|
|
+ $act = $xls->setActiveSheetIndex(0);
|
|
|
|
|
|
- $i = 0;
|
|
|
+ $act->setTitle($name);
|
|
|
|
|
|
- $data = $this->getAdminInfo($data);
|
|
|
- foreach ($config['struct'] as $k => $v) {
|
|
|
- if (isset($v['list']) && $v['list']) {
|
|
|
- # 处理权限
|
|
|
- if (isset($v['auth'])) {
|
|
|
- $auth = $this->value($v['auth'], $data);
|
|
|
- if (!$auth) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ $i = 0;
|
|
|
+
|
|
|
+ foreach ($config['struct'] as $k => $v) {
|
|
|
+ if (isset($v['list']) && $v['list']) {
|
|
|
+ # 处理权限
|
|
|
+ if (isset($v['auth'])) {
|
|
|
+ $auth = $this->value($v['auth'], $data);
|
|
|
+ if (!$auth) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- $num = 1;
|
|
|
- $cell = $this->_getChr($start, $i);
|
|
|
- $act->setCellValue($cell . '' . $num, $v['name']);
|
|
|
- $act->getColumnDimension($cell)->setWidth(20);
|
|
|
- $i++;
|
|
|
+ }
|
|
|
+ $num = 1;
|
|
|
+ $cell = $this->_getChr($start, $i);
|
|
|
+ $act->setCellValue($cell . '' . $num, $v['name']);
|
|
|
+ $act->getColumnDimension($cell)->setWidth(20);
|
|
|
+ $i++;
|
|
|
|
|
|
- foreach ($data as $ki => $vi) {
|
|
|
- if (isset($vi[$k])) {
|
|
|
- $num += 1;
|
|
|
-
|
|
|
- $value = $vi[$k];
|
|
|
-
|
|
|
- if (is_string($v['list'])) {
|
|
|
- $value = $this->value($v['list'], $data[$ki], $config['struct']);
|
|
|
- } elseif (isset($v['option'])) {
|
|
|
- $v['option'] = $this->option($v['option']);
|
|
|
- if (isset($v['option'][$value])) {
|
|
|
- if (is_array($v['option'][$value])) {
|
|
|
- $value = $v['option'][$value]['name'];
|
|
|
- } else {
|
|
|
- $value = $v['option'][$value];
|
|
|
- }
|
|
|
+ foreach ($data as $ki => $vi) {
|
|
|
+ if (isset($vi[$k])) {
|
|
|
+ $num += 1;
|
|
|
+
|
|
|
+ $value = $vi[$k];
|
|
|
+
|
|
|
+ if (is_string($v['list'])) {
|
|
|
+ $value = $this->value($v['list'], $data[$ki], $config['struct']);
|
|
|
+ }
|
|
|
+ if (isset($v['option'])) {
|
|
|
+ $v['option'] = $this->option($v['option']);
|
|
|
+ if (isset($v['option'][$value])) {
|
|
|
+ if (is_array($v['option'][$value])) {
|
|
|
+ $value = $v['option'][$value]['name'];
|
|
|
+ } else {
|
|
|
+ $value = $v['option'][$value];
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- $act->setCellValue($cell . $num, $value);
|
|
|
}
|
|
|
+
|
|
|
+ $act->setCellValue($cell . $num, $value);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- //$act->getStyle('A1:'.$k.'20')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); // 垂直居中
|
|
|
- //$act->getStyle('A1:'.$k.'20')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);// 水平居中
|
|
|
-
|
|
|
- $filename = $name . '.xlsx';
|
|
|
- header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
|
- header('Content-Disposition: attachment;filename="' . $filename . '"');
|
|
|
- header('Cache-Control: max-age=0');
|
|
|
+ //$act->getStyle('A1:'.$k.'20')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); // 垂直居中
|
|
|
+ //$act->getStyle('A1:'.$k.'20')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);// 水平居中
|
|
|
|
|
|
- $write = \PHPExcel_IOFactory::createWriter($xls, 'Excel2007');
|
|
|
- $write->save('php://output');
|
|
|
- }
|
|
|
+ $filename = $name . '.xlsx';
|
|
|
+ header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
|
+ header('Content-Disposition: attachment;filename="' . $filename . '"');
|
|
|
+ header('Cache-Control: max-age=0');
|
|
|
|
|
|
- //print_r($data);die;
|
|
|
+ $write = \PHPExcel_IOFactory::createWriter($xls, 'Excel2007');
|
|
|
+ $write->save('php://output');
|
|
|
}
|
|
|
|
|
|
private function _getChr($start, $num)
|
|
@@ -2429,7 +2476,7 @@ class Database
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * stat 为主动统计提供导出数据
|
|
|
+ * stat 为主动统计提供导出数据 后续优化
|
|
|
*
|
|
|
* @return array
|
|
|
*/
|