PHP生成Excel报表
<?php
$path = '/usr/share/pear'; // 你自定义的 PEAR 路径
set_include_path(get_include_path() . PATH_SEPARATOR . $path); // 设置 PHP 环境变量路径为除 php.ini 默认的以外, 再加上你自定义的 PEAR 路径
require '/usr/share/pear/Spreadsheet/Excel/Writer.php'; // 包含 PEAR::Spreadsheet_Excel_Writer 类文件
$name = 'atyu30';
$work = $_POST['file_body'];
$num = '10';
$filename = $_POST['file_name'];
$name_suffix01 = '_报告.xls';
$name_suffix02 = iconv('utf-8','gb2312',$name_suffix01);
$workbook = new Spreadsheet_Excel_Writer(); // 实例化 PEAR::Spreadsheet_Excel_Writer 类
$workbook->send($filename.$name_suffix02); // 发送 Excel 文件名供下载
$workbook->setVersion(8);
$worksheet =& $workbook->addWorksheet('sheet-1'); // 加入一个工作表 sheet-1
$worksheet->setInputEncoding('utf-8'); // 指定行编码
$data = array(
array('姓名', '节目清单', '上传数量'),
array($name, $work, $num),
array($name, $work, $num),
);
for ($row = 0; $row < count($data); $row ++) {
for ($col = 0; $col < count($data[0]); $col ++) {
$worksheet->writeString($row, $col, $data[$row][$col]); // 在 sheet-1 中写入数据
}
}
$worksheet =& $workbook->addWorksheet('sheet-2'); // 加入一个工作表 sheet-2
$worksheet->setInputEncoding('utf-8'); // 指定行编码
$data = array(
array('姓名', '节目清单', '上传数量'),
array($name, $work, $num),
array($name, $work, $num),
);
for ($row = 0; $row < count($data); $row ++) {
for ($col = 0; $col < count($data[0]); $col ++) {
$worksheet->writeString($row, $col, $data[$row][$col]); // 在 sheet-2 中写入数据
}
}
$workbook->close(); // 完成下载
echo $name;
?>
更新日志
- 道王:掌门修仙记高级弟子获取方法介绍【详解】
- LOL9.12强势刺客刀锋之影玩法介绍【详解】
- LOL9.12高Ban率希维尔玩法介绍【详解】
- LOL9.12热门中单疾风剑豪玩法介绍【详解】
- LOL云顶之弈换形师阵容玩法推荐【详解】
- LOL9.12高胜率打野蔚玩法介绍【详解】
- LOL9.12克制强势上单武器大师玩法介绍【详解】
- LOL9.12高Ban率悠米玩法介绍【详解】
- LOL9.12热门ADC虚空之女玩法介绍【详解】
- LOL9.12高胜率德莱文玩法介绍【详解】
- LOL9.12高胜率打野努努玩法介绍【详解】
- LOL9.12克制强势打野无极剑圣玩法介绍【详解】
- LOL云顶之弈虚空刺阵容玩法推荐【详解】
- LOL9.12热门辅助光辉女郎玩法介绍【详解】
- LOL9.12高胜率娑娜玩法介绍【详解】