XLSdef.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <?
  2. header("Expires: 0");
  3. session_start();
  4. require_once 'PHPExcel-1.8.2/Classes/PHPExcel.php';
  5. include 'auth.php';
  6. include 'functions.php';
  7. function cellColor($cells,$color){
  8. global $objPHPExcel;
  9. $objPHPExcel->getActiveSheet()->getStyle($cells)->getFill()->applyFromArray(array(
  10. 'type' => PHPExcel_Style_Fill::FILL_SOLID,
  11. 'startcolor' => array(
  12. 'rgb' => $color
  13. )
  14. ));
  15. }
  16. $styleBorder = array(
  17. 'borders' => array(
  18. 'allborders' => array(
  19. 'style' => PHPExcel_Style_Border::BORDER_THIN
  20. )
  21. )
  22. );
  23. foreach (array_keys($_REQUEST) as $var)
  24. {
  25. ${$var}=$_REQUEST[$var];
  26. //echo "<b>$var:</b> ${$var} <br>";
  27. }
  28. $array_children = $_SESSION['array_children'];
  29. $array_parent = $_SESSION['array_parent'];
  30. $activeid = $_SESSION['actid'];
  31. $res_parent = $array_parent[$activeid];
  32. $namedesc = GetTaskNameAndDesc($res_parent['type']);
  33. $proj = GetProject($res_parent['input_id']);
  34. $depo = $proj['depo'];
  35. $depo_service = $proj['depo_service'];
  36. $finished = $res_parent['created'];
  37. // Create new PHPExcel object
  38. $objPHPExcel = new PHPExcel();
  39. // Set document properties
  40. $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
  41. ->setLastModifiedBy("Maarten Balliauw")
  42. ->setTitle("Office 2007 XLSX Report Document")
  43. ->setSubject("Office 2007 XLSX Report Document")
  44. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  45. ->setKeywords("office 2007 openxml php")
  46. ->setCategory("Report result file");
  47. $styleCenter = array(
  48. 'alignment' => array(
  49. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  50. )
  51. );
  52. $styleLeft = array(
  53. 'alignment' => array(
  54. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
  55. )
  56. );
  57. $styleVertCenter = array(
  58. 'alignment' => array(
  59. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  60. )
  61. );
  62. $sheet = $objPHPExcel->getActiveSheet();
  63. $sheet->getDefaultStyle()->getFont()->setName('Times New Roman')->setSize(12);
  64. $sheet->mergeCells("A2:B2");
  65. $sheet->mergeCells("A3:B3");
  66. $sheet->mergeCells("A5:B5");
  67. $sheet->mergeCells("A19:B19");
  68. $sheet->mergeCells("A14:B14");
  69. $sheet->getStyle("A2:A3")->applyFromArray($styleCenter);
  70. $sheet->getStyle('A5')->getFont()->setUnderline(true);
  71. $sheet->getStyle('A14')->getFont()->setUnderline(true);
  72. $sheet->getStyle('A19')->getFont()->setUnderline(true);
  73. $sheet->getStyle("A5")->applyFromArray($styleCenter);
  74. $sheet->getStyle("A14")->applyFromArray($styleCenter);
  75. $sheet->getStyle("A19")->applyFromArray($styleCenter);
  76. $sheet->getStyle('A2')->getFont()->setBold(TRUE);
  77. $sheet->getStyle('A5')->getFont()->setBold(TRUE);
  78. $sheet->getStyle('A14')->getFont()->setBold(TRUE);
  79. $sheet->getStyle('A19')->getFont()->setBold(TRUE);
  80. $sheet->getStyle('A7:A12')->getFont()->setBold(TRUE);
  81. $sheet->getStyle("A2")->getFont()->setSize(18);
  82. $sheet->getStyle("A5")->getFont()->setSize(16);
  83. $sheet->getStyle("A14")->getFont()->setSize(16);
  84. $sheet->getStyle("A19")->getFont()->setSize(16);
  85. //$sheet->getStyle("A7:A9")->applyFromArray($style1);
  86. //$sheet->getDefaultStyle()->applyFromArray($style);
  87. // $sheet->getStyle('B11:D11')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
  88. $sheet->getStyle('A7:B12')->applyFromArray($styleBorder);
  89. $sheet->getStyle("A7:B12")->getAlignment()->setWrapText(true);
  90. $sheet->getStyle('A7:B12')->applyFromArray($styleVertCenter);
  91. $sheet->getStyle("A10:M10")->applyFromArray($styleVertCenter);
  92. $sheet->getStyle('A16:B17')->applyFromArray($styleBorder);
  93. //cellColor('B11:D11', 'f2f2f2');
  94. $sheet->getRowDimension('2')->setRowHeight(31.5);
  95. $sheet->getRowDimension('6')->setRowHeight(31.5);
  96. $sheet->getRowDimension('7')->setRowHeight(31.5);
  97. $sheet->getRowDimension('8')->setRowHeight(31.5);
  98. $sheet->getRowDimension('9')->setRowHeight(31.5);
  99. $sheet->getRowDimension('10')->setRowHeight(31.5);
  100. $sheet->getRowDimension('11')->setRowHeight(31.5);
  101. $sheet->getRowDimension('12')->setRowHeight(31.5);
  102. $sheet->getRowDimension('14')->setRowHeight(31.5);
  103. $sheet->getRowDimension('18')->setRowHeight(31.5);
  104. $sheet->getRowDimension('19')->setRowHeight(31.5);
  105. $sheet->setCellValue('A2', 'Дефектная Ведомость Инспекции');
  106. $sheet->setCellValue('A3', $proj['id'].' от '.$proj['created']);
  107. $sheet->setCellValue('A5', 'Общая информация');
  108. $sheet->setCellValue('A7', 'Пользователь Отчета об инспекции объекта осмотра:');
  109. $sheet->setCellValue('A8', 'Наименование Исполнителя:');
  110. $sheet->setCellValue('A9', 'ФИО Инспектора:');
  111. $sheet->setCellValue('A10', 'Дата проведения инспекции объекта осмотра:');
  112. $sheet->setCellValue('A11', 'Срок проведения инспекции объекта осмотра:');
  113. $sheet->setCellValue('A12', 'Дата составления Отчета об инспекции объекта осмотра:');
  114. $sheet->setCellValue('A14', 'Объект осмотра');
  115. $sheet->setCellValue('A16', 'Код объекта:');
  116. $sheet->setCellValue('A17', 'Наименование объекта:');
  117. $sheet->setCellValue('A19', 'Перечень выявленных дефектов');
  118. $sheet->setCellValue('B7', '<Компания - заказчик, заполняется вручную>');
  119. $sheet->setCellValue('B8', '<Компания - исполнитель, заполняется вручную>');
  120. $sheet->setCellValue('B10', date("d-m-Y", strtotime($finished)));
  121. $sheet->setCellValue('B11', "c ".date("d-m-Y", strtotime($finished))." по ".date("d-m-Y") );
  122. $sheet->setCellValue('B12', date("d-m-Y"));
  123. $sheet->setCellValue('B16', $proj['loco_number']);
  124. $sheet->getStyle("B16")->applyFromArray($styleLeft);
  125. $sheet->setCellValue('B17', "Локомотив серии ".$proj['loco_type']);
  126. $i=22;
  127. foreach ($array_children as $parent_id => $children)
  128. {
  129. if ($activeid != $parent_id)
  130. {
  131. continue;
  132. }
  133. foreach ($children as $res1) {
  134. $taskid = $res1['id'];
  135. $type = $res1['type'];
  136. $created = $res1['created'];
  137. $accepted = $res1['accepted_time'];
  138. $finished = $res1['finished_time'];
  139. $assignee = $res1['assignees_arr'];
  140. $assignee_names = GetAccount($assignee)['name'];
  141. if ($finished == '')
  142. $finished = 'не завершена';
  143. if ($accepted == '')
  144. $accepted = 'не принята';
  145. $namedesc = GetTaskNameAndDesc($type);
  146. $sheet->mergeCells("A$i:A".($i+2));
  147. $sheet->getStyle("A$i:B".($i+2))->applyFromArray($styleBorder);
  148. $sheet->getStyle("A$i")->applyFromArray($styleVertCenter);
  149. $sheet->getStyle("A$i")->getFont()->setBold(TRUE);
  150. $sheet->setCellValue("A$i", $namedesc[0]);
  151. $sheet->setCellValue("B".($i+1), "Замер:");
  152. $sheet->getStyle("A$i")->getAlignment()->setWrapText(true);
  153. // $sheet->setCellValueByColumnAndRow(0, $i, $taskid);
  154. // $sheet->setCellValueByColumnAndRow(1, $i, $namedesc[0]);
  155. // $sheet->setCellValueByColumnAndRow(2, $i, $namedesc[1]);
  156. // $sheet->setCellValueByColumnAndRow(3, $i, $finished);
  157. // $sheet->setCellValueByColumnAndRow(4, $i, $assignee_names);
  158. // $sheet->setCellValueByColumnAndRow(5, $i, $namedesc[1]);
  159. // $sheet->setCellValueByColumnAndRow(6, $i, $assignee_names);
  160. $notes = FindTaskNotes($taskid);
  161. if (sizeof($notes) > 0) {
  162. $nn = 1;
  163. foreach ($notes as $note) {
  164. $notedate = $note['date'];
  165. $noteid = $note['id'];
  166. $notetext = $note['text'];
  167. //$sheet->setCellValueByColumnAndRow($nn, $i, $noteid." [".$notedate."] ".$notetext);
  168. $b = $i+2;
  169. $imgpath = GetImagePathFromTask($res1);
  170. $files1 = scandir($imgpath);
  171. if (sizeof($files1) > 2)
  172. {
  173. $sheet->setCellValueByColumnAndRow($nn, $i, "Есть записи");
  174. }
  175. if (intval($notetext) > 0) //счетчик
  176. {
  177. $notetext = "Значение: ".$notetext;
  178. $b = $i;
  179. }
  180. else
  181. $notetext = "Выявлены недостатки: ".$notetext;
  182. $sheet->getStyle("B$b")->getAlignment()->setWrapText(true);
  183. $sheet->setCellValueByColumnAndRow($nn, $b, $notetext);
  184. $sheet->setCellValue("B".($i+1), "Замер:");
  185. continue;
  186. $nn++;
  187. }
  188. }
  189. $i+=3;
  190. }
  191. }
  192. $i+=2;
  193. $sheet->mergeCells("A$i:B$i");
  194. $sheet->getStyle("A$i")->getFont()->setSize(16);
  195. $sheet->getStyle("A$i")->getFont()->setBold(TRUE);
  196. $sheet->getStyle("A$i")->applyFromArray($styleCenter);
  197. $sheet->setCellValueByColumnAndRow(0, $i, 'Фотографии выявленных дефектов');
  198. $i++;
  199. foreach ($array_children as $parent_id => $children) {
  200. if ($activeid != $parent_id) {
  201. continue;
  202. }
  203. foreach ($children as $res1) {
  204. $imgpath = GetImagePathFromTask($res1);
  205. $files1 = scandir($imgpath);
  206. if (sizeof($files1) > 2)
  207. {
  208. $type = $res1['type'];
  209. $namedesc = GetTaskNameAndDesc($type);
  210. $sheet->mergeCells("A$i:B$i");
  211. $sheet->setCellValueByColumnAndRow(0, $i, $namedesc[0]);
  212. $i++;
  213. $k = 1;
  214. foreach ($files1 as $file )
  215. {
  216. $x = pathinfo($file)['extension'];
  217. if($file === '.' || $file === '..') {continue;}
  218. if ($x == 'jpg') {
  219. $objDrawing = new PHPExcel_Worksheet_Drawing();
  220. $objDrawing->setName('test_img');
  221. $objDrawing->setDescription('test_img');
  222. //$objDrawing->setPath('ProSysNew/logo.png');$imgpath$file
  223. $objDrawing->setPath("$imgpath$file");
  224. if ($k%2 == 0) {
  225. $objDrawing->setCoordinates("B$i");
  226. $i++;
  227. }
  228. else {
  229. $sheet->getRowDimension($i)->setRowHeight(200);
  230. $objDrawing->setCoordinates("A$i");
  231. }
  232. //setOffsetX works properly
  233. $objDrawing->setOffsetX(5);
  234. $objDrawing->setOffsetY(5);
  235. //set width, height
  236. $objDrawing->setWidth(250);
  237. $objDrawing->setHeight(200);
  238. $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
  239. $k++;
  240. }
  241. }
  242. }
  243. }
  244. }
  245. $i+=4;
  246. $sheet->mergeCells("A$i:B$i");
  247. $sheet->getStyle("A$i")->getFont()->setSize(16);
  248. $sheet->getStyle("A$i")->getFont()->setBold(TRUE);
  249. $sheet->getStyle("A$i")->applyFromArray($styleCenter);
  250. $sheet->setCellValueByColumnAndRow(0, $i, 'Приемная комиссия');
  251. $i++;
  252. $sheet->getStyle("A$i:B".($i+5))->applyFromArray($styleBorder);
  253. $sheet->setCellValueByColumnAndRow(0, $i, 'ФИО');
  254. $sheet->setCellValueByColumnAndRow(1, $i, 'Подпись');
  255. $sheet->getStyle("A".$i)->getFont()->setBold(TRUE);
  256. $sheet->getStyle("B".$i)->getFont()->setBold(TRUE);
  257. $sheet->setCellValueByColumnAndRow(0, $i+1, $assignee_names);
  258. //$i+=2;
  259. //$sheet->getRowDimension($i)->setRowHeight(30);
  260. //$sheet->setCellValueByColumnAndRow(2, $i, 'Исполнитель: '.$assignee_names);
  261. $sheet->setCellValue('B9', $assignee_names);
  262. // Rename worksheet
  263. $sheet->setTitle('Report');
  264. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  265. $objPHPExcel->setActiveSheetIndex(0);
  266. $sheet->getColumnDimension('A')->setWidth(50);
  267. $sheet->getColumnDimension('B')->setWidth(50);
  268. $sheet->getColumnDimension('C')->setAutoSize(true);
  269. $sheet->getColumnDimension('D')->setAutoSize(true);
  270. $sheet->getColumnDimension('E')->setAutoSize(true);
  271. $sheet->getColumnDimension('F')->setAutoSize(true);
  272. $sheet->getColumnDimension('G')->setAutoSize(true);
  273. $sheet->getColumnDimension('H')->setAutoSize(true);
  274. $sheet->getColumnDimension('I')->setAutoSize(true);
  275. $sheet->getColumnDimension('J')->setAutoSize(true);
  276. $sheet->getColumnDimension('K')->setAutoSize(true);
  277. $sheet->getColumnDimension('L')->setAutoSize(true);
  278. $sheet->getColumnDimension('M')->setAutoSize(true);
  279. $styleBorder = array('font' => array('bold' => true));
  280. $sheet->getStyle('B1:F1')->applyFromArray($styleBorder);
  281. $sheet->getStyle('A1')->getFont()->setBold(TRUE);
  282. //$sheet->getStyle('B1')->getFont()->getColor()->setRGB('FFFFFF');
  283. // Redirect output to a client’s web browser (Excel5)
  284. header('Content-Type: application/vnd.ms-excel');
  285. $date1 = date('d.m.Y-H.i', strtotime($finished));
  286. header('Content-Disposition: attachment;filename="task-'.$activeid.'-defects.xls');
  287. header('Cache-Control: max-age=0');
  288. // If you're serving to IE 9, then the following may be needed
  289. header('Cache-Control: max-age=1');
  290. // If you're serving to IE over SSL, then the following may be needed
  291. header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  292. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  293. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  294. header ('Pragma: public'); // HTTP/1.0
  295. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  296. //$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  297. $objWriter->save('php://output');
  298. ?>