标签word下载成功

This commit is contained in:
cxdbz committed 2018-11-20 21:01:49 +08:00
1 parent 5bb024de9a
commit 521db936c4
6 files changed
+58 -68

No files matched your search

+9
View File
@@ -30,4 +30,13 @@ class Chengji extends Base
// 返回班级名称
return $bj->title;
}
// 班级名称(数字)获取器
public function getBanjiNumnameAttr()
{
$bj = Banji::get($this->banji);
// 返回班级名称
return $bj->numTitle;
}
}
+1
View File
@@ -27,6 +27,7 @@ class Banji extends Base
}
// 获取班级信息列表
public function ajaxData()
{
+21 -63
View File
@@ -15,7 +15,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
// use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
// use PhpOffice\PhpSpreadsheet\IOFactory;
use Endroid\QrCode\QrCode;
use \Endroid\QrCode\QrCode;
class Kaoshi extends Base
{
@@ -363,53 +363,15 @@ class Kaoshi extends Base
}
// 生成二维码基础信息
public function ma($users_id=1)
{
$this->create_qrcode();
$qrCode = new QrCode('Life is too short to be generating QR codes');
header('Content-Type: '.$qrCode->getContentType());
// 保存文件
$filename = '试卷标签.docx';
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $filename . '"');
header('Cache-Control: max-age=0');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('php://output');
}
/**
* 生成指定网址的二维码
* @param string $url 二维码中所代表的网址
*/
public function create_qrcode($url='')
public function create_qrcode($url='127.0.0.1')
{
$url = $url ? $url : input('param.url');
$qrCode = new QrCode;;//创建生成二维码对象
$qrCode->setText($url)
->setSize(150)
->setPadding(10)
->setErrorCorrection('high')
->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))
->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0))
->setImageType(\Endroid\QrCode\QrCode::IMAGE_TYPE_PNG);
//>>>>>>>直接输出到浏览器>>>>>>>>>>
header("Content-type: image/png");
$qrCode->render(); //输入到浏览器
//>>>>>>>直接输出到浏览器>>>>>>>>>>
//>>>>>>>>>保存文件>>>>>>>>>>>
//$qrCode->save('ziyuanniao.png'); //保存文件
//>>>>>>>>>保存文件>>>>>>>>>>>
$qrCode = new QrCode($url);
header("Content-type: image/jpg");
return $qrCode->writeString();
}
@@ -419,10 +381,10 @@ class Kaoshi extends Base
public function biaoqian()
{
$id = 1;
$id = 2;
// 获取数据库信息
$chengjiinfo = Chengji::where('kaoshi',$id)
->append(['studentname','schooljian','banjiname'])
->append(['studentname','schooljian','banjiNumname'])
->select();
// 获取学科信息
@@ -430,7 +392,7 @@ class Kaoshi extends Base
$xks = $xks->Subjectids;
$subject = new \app\teach\model\Subject();
$xks = $subject->where('id','in',$xks)->column('id,leiming,title');
$xks = $subject->where('id','in',$xks)->column('id,title');
// Word处理
// 实例化类
@@ -442,23 +404,23 @@ class Kaoshi extends Base
'pageSizeW'=>2*567,
'pageSizeH'=>3*567,
'orientation'=>'landscape',
'marginLeft'=>100,
'marginRight'=>100,
'marginTop'=>200,
'marginLeft'=>80,
'marginRight'=>80,
'marginTop'=>100,
'marginBottom'=>100
);
$section = $phpWord->createSection($sectionStyle);
// 设置图片格式
$imageStyle = array('width'=>40,'height'=>40,'align'=>'left');
$imageStyle = array('width'=>42,'height'=>42,'align'=>'left');
// 学生信息样式
$myStyle = 'myStyle';
$phpWord->addFontStyle(
$myStyle,
[
'name' => 'Verdana',
'name' => '宋体',
'size' => 6.5,
'color' => '000000',
'bold' => true,
@@ -467,17 +429,20 @@ class Kaoshi extends Base
// 循环写出信息
foreach ($chengjiinfo as $key => $value) {
foreach ($xks as $key => $val) {
foreach ($xks as $xkkey => $val) {
// 创建表格
$table = $section->addTable($key);
$table->addRow(1500);
$table->addCell(700)->addImage('aaaa.jpg',$imageStyle);
$img = $this->create_qrcode($value['id'].','.$xkkey);
$table->addCell(850)->addImage($img,$imageStyle);
// $table->addCell(700)->addImage('aaaa.jpg',$imageStyle);
$info = $table->addCell(700);
$info = $table->addCell(650);
$info->addText($value['schooljian'],$myStyle);
$info->addText($value['banjiname'],$myStyle);
$info->addText($value['banjiNumname'],$myStyle);
$info->addText($value['studentname'],$myStyle);
$info->addText($val['title'],$myStyle);
$info->addText($val,$myStyle);
}
}
@@ -532,11 +497,4 @@ class Kaoshi extends Base
}
// 生成表格录入成绩表
public function biaolu()
{
return $this->fetch();
}
}
Loaded 3 of 6 files, more files were not shown because too many files have changed in this diff. Show more