当前位置:网站首页>[TP5 online export picture generation excel detailed explanation example]
[TP5 online export picture generation excel detailed explanation example]
2022-06-11 06:16:00 【Results of persistence and effort】
public function excel()
{
$list = Db::table('news')->select();
// Exported file name
$file_name = date('Y-m-d_H:i:s') . ' form ' . '.xls';
$PHPExcel=new \PHPExcel();
$PHPSheet = $PHPExcel->getActiveSheet();
$PHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$PHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$PHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$PHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
// Set a table title
$PHPSheet->setTitle(" Agent ");
$PHPSheet->setCellValue("A1", "ID");
$PHPSheet->setCellValue("B1", " title ");
$PHPSheet->setCellValue("C1", " classification ");
$PHPSheet->setCellValue("D1", " Picture address ");
// Set table width
$PHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
$PHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
$PHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
$PHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(80);
// Set vertical center
$PHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$PHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$PHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$PHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$i = 2;
foreach ($list as $k => $v) {
$PHPSheet->setCellValue('A' . $i, '' . $v['id']);
$PHPSheet->setCellValue('B' . $i, '' . $v['title']);
$PHPSheet->setCellValue('C' . $i, '' . $v['category']);
// Get picture information
if ($v['thumbnail_pic_s']) {
// Image generation
$objDrawing[$k] = new \PHPExcel_Worksheet_MemoryDrawing();
// The format of the intercepted picture , In a different way
$end[$k] = substr($v['thumbnail_pic_s'], -3);
if ($end[$k] == 'jpg' || $end[$k] == 'peg') {
$img[$k] = @imagecreatefromjpeg($v['thumbnail_pic_s']);
} else if ($end[$k] == 'png') {
$img[$k] = @imagecreatefrompng($v['thumbnail_pic_s']);
} else if ($end[$k] == 'gif') {
$img[$k] = @imagecreatefromgif($v['thumbnail_pic_s']);
}
$objDrawing[$k]->setImageResource($img[$k]);
$objDrawing[$k]->setRenderingFunction(\PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT);// rendering method
$objDrawing[$k]->setMimeType(\PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
}
$objDrawing[$k]->setHeight(20);// The height of the picture
$objDrawing[$k]->setWidth(70); // Photo width
$objDrawing[$k]->setCoordinates('D' . $i);
// Image offset distance
$objDrawing[$k]->setOffsetX(12);
$objDrawing[$k]->setOffsetY(12);
$objDrawing[$k]->setWorksheet($PHPExcel->getActiveSheet());
// $PHPSheet->setCellValue('D'.$i,''.$value['image_input']);
$i++;
}
$PHPExcel->setActiveSheetIndex(0);
$objWriter = \PHPExcel_IOFactory::createWriter($PHPExcel, "Excel2007");
header('Content-Disposition: attachment;filename=' . $file_name);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Cache-Control: max-age=0');
$objWriter->save("php://output"); // The file is downloaded through the browser
}
边栏推荐
- SQLI_ LIBS range construction and 1-10get injection practice
- Devsecops in Agile Environment
- Instanceof and type conversion
- Topic collection of FIFO minimum depth calculation
- Quantitative understanding (Quantitative deep revolutionary networks for effective information: a whitepaper)
- NLP-D46-nlp比赛D15
- Shandong University machine learning experiment VI k-means
- Delegation agreement, data source agreement and advanced view in view
- Which company is better in JIRA organizational structure management?
- Review XML and JSON
猜你喜欢

Verilog realizes binocular camera image data acquisition and Modelsim simulation, and finally matlab performs image display

Compliance management 101: processes, planning and challenges

Record the first data preprocessing process

Convert multiple pictures into one NPY file storage

FPGA面试题目笔记(四)—— 序列检测器、跨时钟域中的格雷码、乒乓操作、降低静动态损耗、定点化无损误差、恢复时间和移除时间

Global case | how an airline with a history of 100 years can expand and transform to promote innovation in the aviation industry

FIFO最小深度计算的题目合集

Global case | how Capgemini connects global product teams through JIRA software and confluence

This point of arrow function

JIRA software annual summary: release of 12 important functions
随机推荐
Shandong University machine learning final 2021
[IOS development interview] operating system learning notes
Basic usage of MySQL
URL in flask_ for
Squid agent
Graphsage paper reading
Simple understanding of pseudo elements before and after
Observer mode (listener mode) + thread pool to realize asynchronous message sending
This is probably the most comprehensive project about Twitter information crawler search on the Chinese Internet
Ethical discussion on reptile Technology
Principle of copyonwritearraylist copy on write
ThymeleafEngine模板引擎
What is a thread pool?
go的fmt包使用和字符串的格式化
Analyze the capacity expansion mechanism of ArrayList
Sqli-labs less-01
All questions and answers of database SQL practice niuke.com
Linux Installation redis
Experimental report on information management and information system [information security and confidentiality] of Huazhong Agricultural University
What do you need to know about Amazon evaluation?