正在显示
1 个修改的文件
包含
91 行增加
和
1 行删除
@@ -11,7 +11,11 @@ namespace app\portal\controller; | @@ -11,7 +11,11 @@ namespace app\portal\controller; | ||
11 | 11 | ||
12 | use app\portal\model\EquipmentModel; | 12 | use app\portal\model\EquipmentModel; |
13 | use cmf\controller\AdminBaseController; | 13 | use cmf\controller\AdminBaseController; |
14 | +use PHPExcel; | ||
14 | use PHPExcel_IOFactory; | 15 | use PHPExcel_IOFactory; |
16 | +use PHPExcel_Style_Alignment; | ||
17 | +use PHPExcel_Worksheet_Drawing; | ||
18 | +use PHPExcel_Writer_Excel2007; | ||
15 | use QRcode; | 19 | use QRcode; |
16 | use think\Db; | 20 | use think\Db; |
17 | 21 | ||
@@ -60,7 +64,7 @@ class AdminEquipmentController extends AdminBaseController{ | @@ -60,7 +64,7 @@ class AdminEquipmentController extends AdminBaseController{ | ||
60 | 64 | ||
61 | return $this->fetch(); | 65 | return $this->fetch(); |
62 | } | 66 | } |
63 | - | 67 | + //批量导入设备信息 |
64 | public function batch_addPost(){ | 68 | public function batch_addPost(){ |
65 | //上传excel文件 | 69 | //上传excel文件 |
66 | $file = $this->request->file('myfile'); | 70 | $file = $this->request->file('myfile'); |
@@ -111,7 +115,93 @@ class AdminEquipmentController extends AdminBaseController{ | @@ -111,7 +115,93 @@ class AdminEquipmentController extends AdminBaseController{ | ||
111 | } | 115 | } |
112 | } | 116 | } |
113 | 117 | ||
118 | + //批量导出 | ||
119 | + public function batch_export(){ | ||
120 | + $data= Db::name('equipment')->select(); | ||
121 | + | ||
122 | + // 导出Exl | ||
123 | + vendor("VENDOR_PATH/phpoffice/phpexcel/Classes/PHPExcel"); | ||
124 | + vendor("VENDOR_PATH/phpoffice/phpexcel/Classes/PHPExcel/Worksheet/Drawing"); | ||
125 | + vendor("VENDOR_PATH/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel2007"); | ||
126 | + $objPHPExcel = new PHPExcel(); | ||
127 | + | ||
128 | + $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel); | ||
129 | + | ||
130 | + $objActSheet = $objPHPExcel->getActiveSheet(); | ||
131 | + | ||
132 | + // 水平居中(位置很重要,建议在最初始位置) | ||
133 | + $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); | ||
134 | + $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); | ||
135 | + $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); | ||
136 | + $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); | ||
137 | + $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); | ||
138 | + $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); | ||
139 | + | ||
140 | + $objActSheet->setCellValue('A1', '商品货号'); | ||
141 | + $objActSheet->setCellValue('B1', '商品名称'); | ||
142 | + $objActSheet->setCellValue('C1', '商品图'); | ||
143 | + $objActSheet->setCellValue('D1', '商品条码'); | ||
144 | + $objActSheet->setCellValue('E1', '商品属性'); | ||
145 | + $objActSheet->setCellValue('F1', '报价(港币)'); | ||
146 | + // 设置个表格宽度 | ||
147 | + $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(16); | ||
148 | + $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(80); | ||
149 | + $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15); | ||
150 | + $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20); | ||
151 | + $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(12); | ||
152 | + $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(12); | ||
153 | + | ||
154 | + // 垂直居中 | ||
155 | + $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); | ||
156 | + $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); | ||
157 | + $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); | ||
158 | + $objPHPExcel->getActiveSheet()->getStyle('E')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); | ||
159 | + $objPHPExcel->getActiveSheet()->getStyle('F')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); | ||
114 | 160 | ||
161 | + foreach($data as $k=>$v){ | ||
162 | + $k +=2; | ||
163 | + $objActSheet->setCellValue('A'.$k, $v['mac_address']); | ||
164 | + $objActSheet->setCellValue('B'.$k, $v['ame']); | ||
165 | + | ||
166 | + $img = Db::name('equipment')->where('id',$v['id'])->find(); | ||
167 | + // 图片生成 | ||
168 | + $objDrawing[$k] = new PHPExcel_Worksheet_Drawing(); | ||
169 | + $objDrawing[$k]->setPath('./Upload/'.$img['qr_code']); | ||
170 | + // 设置宽度高度 | ||
171 | + $objDrawing[$k]->setHeight(80);//照片高度 | ||
172 | + $objDrawing[$k]->setWidth(80); //照片宽度 | ||
173 | + /*设置图片要插入的单元格*/ | ||
174 | + $objDrawing[$k]->setCoordinates('C'.$k); | ||
175 | + // 图片偏移距离 | ||
176 | + $objDrawing[$k]->setOffsetX(12); | ||
177 | + $objDrawing[$k]->setOffsetY(12); | ||
178 | + $objDrawing[$k]->setWorksheet($objPHPExcel->getActiveSheet()); | ||
179 | + | ||
180 | + // 表格内容 | ||
181 | + $objActSheet->setCellValue('D'.$k, $v['hospital']); | ||
182 | + $objActSheet->setCellValue('E'.$k, $v['key']); | ||
183 | + $objActSheet->setCellValue('F'.$k, $v['note']); | ||
184 | + | ||
185 | + // 表格高度 | ||
186 | + $objActSheet->getRowDimension($k)->setRowHeight(80); | ||
187 | + | ||
188 | + } | ||
189 | + | ||
190 | + $fileName = '报价表'; | ||
191 | + $date = date("Y-m-d",time()); | ||
192 | + $fileName .= "_{$date}.xls"; | ||
193 | + $fileName = iconv("utf-8", "gb2312", $fileName); | ||
194 | + //重命名表 | ||
195 | + // $objPHPExcel->getActiveSheet()->setTitle('test'); | ||
196 | + //设置活动单指数到第一个表,所以Excel打开这是第一个表 | ||
197 | + $objPHPExcel->setActiveSheetIndex(0); | ||
198 | + header('Content-Type: application/vnd.ms-excel'); | ||
199 | + header("Content-Disposition: attachment;filename=\"$fileName\""); | ||
200 | + header('Cache-Control: max-age=0'); | ||
201 | + $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); | ||
202 | + $objWriter->save('php://output'); //文件通过浏览器下载 | ||
203 | + // END | ||
204 | + } | ||
115 | 205 | ||
116 | //生成二维码 | 206 | //生成二维码 |
117 | public function createQrCode($value){ | 207 | public function createQrCode($value){ |
-
请 注册 或 登录 后发表评论