include ‘…/extend/PHPExcel-1.8/Classes/PHPExcel.php’;
include ‘…/extend/PHPExcel-1.8/Classes/PHPExcel/Writer/Excel2007.php’;
require("…/class/connect.php");
require("…/class/db_sql.php");
$link=db_connect();
$empire=new mysqlquery();
$sql=‘select * from phome_enewsfeedback where bid=1 order by id desc’;
r
e
s
u
l
t
=
result=
result=empire->query($sql);
//数据
$data=[];
k
e
y
=
0
;
w
h
i
l
e
(
key=0; while(
key=0;while(r=
e
m
p
i
r
e
−
>
f
e
t
c
h
(
empire->fetch(
empire−>fetch(result)) {
d
a
t
a
[
data[
data[key][‘id’]=$r[‘id’];
d
a
t
a
[
data[
data[key][‘title’]=$r[‘title’];
d
a
t
a
[
data[
data[key][‘sex’]=$r[‘sex’];
d
a
t
a
[
data[
data[key][‘idnum’]=$r[‘idnum’];
d
a
t
a
[
data[
data[key][‘mycall’]=$r[‘mycall’];
d
a
t
a
[
data[
data[key][‘email’]=$r[‘email’];
d
a
t
a
[
data[
data[key][‘company’]=$r[‘company’];
d
a
t
a
[
data[
data[key][‘address’]=$r[‘address’];
d
a
t
a
[
data[
data[key][‘name’]=$r[‘name’];
d
a
t
a
[
data[
data[key][‘leixing’]=$r[‘leixing’];
d
a
t
a
[
data[
data[key][‘cptime’]=$r[‘cptime’];
d
a
t
a
[
data[
data[key][‘shichang’]=$r[‘shichang’];
d
a
t
a
[
data[
data[key][‘sbtime’]=$r[‘sbtime’];
d
a
t
a
[
data[
data[key][‘pingtai’]=$r[‘pingtai’];
d
a
t
a
[
data[
data[key][‘daoyan’]=$r[‘daoyan’];
d
a
t
a
[
data[
data[key][‘bianju’]=$r[‘bianju’];
d
a
t
a
[
data[
data[key][‘zhipian’]=$r[‘zhipian’];
d
a
t
a
[
data[
data[key][‘zhujue’]=$r[‘zhujue’];
d
a
t
a
[
data[
data[key][‘hjqingkuang’]=$r[‘hjqingkuang’];
d
a
t
a
[
data[
data[key][‘yunpan’]=$r[‘yunpan’];
d
a
t
a
[
data[
data[key][‘yunpanm’]=$r[‘yunpanm’];
d
a
t
a
[
data[
data[key][‘saytext’]=$r[‘saytext’];
KaTeX parse error: Expected 'EOF', got '}' at position 8: key++; }̲ // //print_r(data);
//设置表头:
$headArr = [‘编号’,‘申报人’,‘性别’,‘证件号码’,‘电话’,‘邮箱’,‘申报单位’,‘通讯地址’,‘作品名称’,‘作品类型’,‘成片时间’,‘时长’,‘首播时间’,‘播出平台’,‘导演’,‘编剧’,‘制片人’,‘主演’,‘获奖情况’,‘云盘链接’,‘云盘密码’,‘作品简介’];
//excel表名
$name=‘报名信息’;
$filename=‘报名信息.xlsx’;
//$headArr=[‘AAA’,‘BBB’,‘CCCC’,‘DDD’];
// $data=[
// 0=>[‘aaa’,‘bb’,‘cc’,‘dd’],
// 1=>[‘aaa1’,‘bb1’,‘cc1’,‘dd1’],
// 2=>[‘aaa2’,‘bb2’,‘cc2’,‘dd2’],
// 3=>[‘aaa3’,‘bb3’,‘cc3’,‘dd3’],
// ];
c
o
u
n
t
=
c
o
u
n
t
(
count =count(
count=count(data);
set_time_limit(0);
ini_set(‘memory_limit’,‘10240M’);
// 数据量大时,导出失败, 压缩一下,减少内存使用
include ‘…/extend/PHPExcel-1.8/Classes/PHPExcel/Settings.php’;
if (!PHPExcel_Settings::setCacheStorageMethod(‘MemoryGZip’)) {
die(‘MemoryGZip’ . " 缓存方法不可用" );
}
$callStartTime = microtime ( true);
$objPHPExcel=new PHPExcel();
$objPHPExcel->getProperties()->setCreator(‘test’)
->setLastModifiedBy(‘test’)
->setTitle(‘test’)
->setSubject(‘test’)->setDescription(‘test.’)->setKeywords(‘test’)->setCategory(‘test’);
//print_r($headArr);
//设置表头
k
e
y
=
o
r
d
(
"
A
"
)
;
f
o
r
e
a
c
h
(
key = ord("A"); foreach (
key=ord("A");foreach(headArr as $v)
{
c
o
l
u
m
=
c
h
r
(
colum = chr(
colum=chr(key);
$v = iconv(“gb2312”, “utf-8”, $v);
o
b
j
P
H
P
E
x
c
e
l
−
>
s
e
t
A
c
t
i
v
e
S
h
e
e
t
I
n
d
e
x
(
0
)
−
>
s
e
t
C
e
l
l
V
a
l
u
e
(
objPHPExcel->setActiveSheetIndex(0)->setCellValue(
objPHPExcel−>setActiveSheetIndex(0)−>setCellValue(colum . ‘1’, $v);
$key += 1;
}
//设置数据
$column = 2;
$objActSheet =
o
b
j
P
H
P
E
x
c
e
l
−
>
g
e
t
A
c
t
i
v
e
S
h
e
e
t
(
)
;
f
o
r
e
a
c
h
(
objPHPExcel->getActiveSheet(); foreach (
objPHPExcel−>getActiveSheet();foreach(data as $key => $rows)
{
//行写入
s
p
a
n
=
o
r
d
(
"
A
"
)
;
f
o
r
e
a
c
h
(
span = ord("A"); foreach (
span=ord("A");foreach(rows as $keyName => $value)
{
// 列写入
j
=
c
h
r
(
j = chr(
j=chr(span);
o
b
j
A
c
t
S
h
e
e
t
−
>
s
e
t
C
e
l
l
V
a
l
u
e
(
objActSheet->setCellValue(
objActSheet−>setCellValue(j . KaTeX parse error: Double superscript at position 11: column, ' '̲.value);
$span++;
}
$column++;
}
//设置宽度
//$objPHPExcel->getActiveSheet()->getColumnDimension(‘D’)->setWidth(‘300’);
$objPHPExcel->getActiveSheet()->getColumnDimension(‘e’)->setWidth(‘40’);
$objPHPExcel->getActiveSheet()->setTitle($name); $objPHPExcel->setActiveSheetIndex(0); $callEndTime=microtime( true); $callTime= $callEndTime - $callStartTime;
// echo $callTime;
ob_end_clean(); ob_start(); header('Content-type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Cache-Control: max-age=0'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: cache, must-revalidate'); header('Pragma: public'); $objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output');
db_close(); //关闭MYSQL链接
$empire=null; //注消 *** 作类变量
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)