This repository was archived by the owner on May 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.php
More file actions
123 lines (113 loc) · 5.13 KB
/
Copy pathexport.php
File metadata and controls
123 lines (113 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
require_once("php/sql.php");
require_once("php/output.php");
include "php/PHPExcel.php";
include "php/PHPExcel/Writer/Excel2007.php";
session_start();
if(!isset($_SESSION['valid_user'])) exit;
$username=$_SESSION['valid_user'];
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="courses_scheudle_'.$username.'.xlsx"');
$WEEK = array("周一", "周二", "周三", "周四", "周五", "周六", "周日");
$objPHPExcel=new PHPExcel();
$objPHPExcel->getDefaultStyle()->getFont()->setSize(10);
$raw_cls=$_GET['cls'];
$raw_ins=$_GET['ins'];
$mysql=connect_db($username);
$query="select * from info where ID=0";
$result=sql_query($mysql, $query);
$row=$result->fetch_object();
$day=$row->Day;
$offset=$row->Offset;
function doSheet($objPHPExcel, $type, $id)
{
global $WEEK, $mysql, $day, $offset;
$objPHPExcel->getActiveSheet()->mergeCells("A1:H1");
$objPHPExcel->getActiveSheet()->getStyle('A1:H'.($day+2))->
getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('A1:H'.($day+2))->
getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$name=get_name_by_id($mysql, $type?"instructors":"classes", $id);
$objPHPExcel->getActiveSheet()->setTitle(($type?"教师":"班级 ").$name);
$objPHPExcel->getActiveSheet()->setCellValue('A1', ($type?"教师":"班级 ").$name);
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
for ($i=-1; $i<$day; $i++)
{
$objPHPExcel->getActiveSheet()->getRowDimension($i+3)->setRowHeight(18);
if($i==-1)
{
$objPHPExcel->getActiveSheet()->setCellValue('A'.($i+3), '');
if(!$offset)
{
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(24);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(24);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(24);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(24);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(24);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(24);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(24);
$objPHPExcel->getActiveSheet()->setCellValue('B'.($i+3), $WEEK[0]);
$objPHPExcel->getActiveSheet()->setCellValue('C'.($i+3), $WEEK[1]);
$objPHPExcel->getActiveSheet()->setCellValue('D'.($i+3), $WEEK[2]);
$objPHPExcel->getActiveSheet()->setCellValue('E'.($i+3), $WEEK[3]);
$objPHPExcel->getActiveSheet()->setCellValue('F'.($i+3), $WEEK[4]);
$objPHPExcel->getActiveSheet()->setCellValue('G'.($i+3), $WEEK[5]);
$objPHPExcel->getActiveSheet()->setCellValue('H'.($i+3), $WEEK[6]);
}
else
{
$objPHPExcel->getActiveSheet()->setCellValue('B'.($i+3), $WEEK[6]);
$objPHPExcel->getActiveSheet()->setCellValue('C'.($i+3), $WEEK[0]);
$objPHPExcel->getActiveSheet()->setCellValue('D'.($i+3), $WEEK[1]);
$objPHPExcel->getActiveSheet()->setCellValue('E'.($i+3), $WEEK[2]);
$objPHPExcel->getActiveSheet()->setCellValue('F'.($i+3), $WEEK[3]);
$objPHPExcel->getActiveSheet()->setCellValue('G'.($i+3), $WEEK[4]);
$objPHPExcel->getActiveSheet()->setCellValue('H'.($i+3), $WEEK[5]);
}
}
else
{
$objPHPExcel->getActiveSheet()->setCellValue('A'.($i+3), $i+1);
$objPHPExcel->getActiveSheet()->setCellValue('B'.($i+3),
get_course($mysql, 0, $i, $id, $type).get_classroom($mysql, 0, $i, $id, $type));
$objPHPExcel->getActiveSheet()->setCellValue('C'.($i+3),
get_course($mysql, 1, $i, $id, $type).get_classroom($mysql, 1, $i, $id, $type));
$objPHPExcel->getActiveSheet()->setCellValue('D'.($i+3),
get_course($mysql, 2, $i, $id, $type).get_classroom($mysql, 2, $i, $id, $type));
$objPHPExcel->getActiveSheet()->setCellValue('E'.($i+3),
get_course($mysql, 3, $i, $id, $type).get_classroom($mysql, 3, $i, $id, $type));
$objPHPExcel->getActiveSheet()->setCellValue('F'.($i+3),
get_course($mysql, 4, $i, $id, $type).get_classroom($mysql, 4, $i, $id, $type));
$objPHPExcel->getActiveSheet()->setCellValue('G'.($i+3),
get_course($mysql, 5, $i, $id, $type).get_classroom($mysql, 5, $i, $id, $type));
$objPHPExcel->getActiveSheet()->setCellValue('H'.($i+3),
get_course($mysql, 6, $i, $id, $type).get_classroom($mysql, 6, $i, $id, $type));
}
}
return $objPHPExcel;
}
$sheet_no=0;
$cls=preg_split("/,/", $raw_cls);
$i=0;
while(isset($cls[$i])&$cls[$i]!=null)
{
$objPHPExcel->createSheet($sheet_no);
$objPHPExcel->setActiveSheetIndex($sheet_no);
doSheet($objPHPExcel, 0, $cls[$i]);
$sheet_no++;
$i++;
}
$ins=preg_split("/,/", $raw_ins);
$i=0;
while(isset($ins[$i])&$ins[$i]!=null)
{
$objPHPExcel->createSheet($sheet_no);
$objPHPExcel->setActiveSheetIndex($sheet_no);
doSheet($objPHPExcel, 1, $ins[$i]);
$sheet_no++;
$i++;
}
$mysql->close();
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save("php://output");
?>