当前位置:网站首页>Phpexcel export with picture Excel
Phpexcel export with picture Excel
2022-06-23 02:13:00 【It workers】
<?php
// Used here PHPExcel The version number is 1.8.0
// Download address https://github.com/PHPOffice/PHPExcel download ZIP Compressed package
// After downloading Classes Folders are extracted for subsequent use
/*
The directory structure of the original plug-in
The root directory Classes
--PHPExcel Folder
--PHPExcel.php file
*/
/** Include PHPExcel */
require_once '/Classes/PHPExcel.php';
/*
stay thinkPHP in take Classes Rename the folder to PHPExcel, Put it in the catalog ThinkPHP/Library/Vendor Next
Store in thinkPHP Middle and rear directory structure
The root directory ThinkPHP
--Library
--Vendor
--PHPExcel
--PHPExcel Folder
--PHPExcel.php file
*/
// stay thinkPHP Contained in the PHPExcel.php File mode
// vendor('PHPExcel.PHPExcel');
// And in thinkPHP Add a backslash before all the class names of the calling plug-ins in \
// Create new PHPExcel object
$objPHPExcel = new \PHPExcel ();
// Set document properties
$objPHPExcel->getProperties ()->setCreator ( "zend" )-> // author
setLastModifiedBy ( "zend" )-> // Last saved by
setTitle ( "Office 2007 XLSX Document" )-> // title
setSubject ( "Office 2007 XLSX Document" )-> // The theme
setDescription ( "document for Office 2007 XLSX, generated using PHP classes." )-> // remarks
setKeywords ( "office 2007 openxml php" )-> // Mark
setCategory ( "result file" ); // Category
$objPHPExcel->getActiveSheet ()->getColumnDimension ( 'A' )->setWidth ( '15' ); // Set column width
$objPHPExcel->getActiveSheet ()->getColumnDimension ( 'B' )->setWidth ( '30' );
$objPHPExcel->getActiveSheet ()->getColumnDimension ( 'C' )->setWidth ( '30' );
$objPHPExcel->getActiveSheet ()->getColumnDimension ( 'D' )->setWidth ( '20' );
// Add some data
$objPHPExcel->setActiveSheetIndex ( 0 )
->setCellValue ( 'A1', ' Phone number ' ) // first line A The column value
->setCellValue ( 'B1', ' full name ' ) // first line B The column value
->setCellValue ( 'C1', ' picture ' ) // first line C The column value
->setCellValue ( 'D1', ' Submission time ' ); // first line D The column value
// From this point on, the number of rows can be accumulated in the loop
$objPHPExcel->setActiveSheetIndex ( 0 )
->setCellValue ( 'A' . '2', ' ' . '12345678910' ) // The second line A The column value
->setCellValue ( 'B' . '2', ' ' . ' user name ' ); // The second line B The column value
/* Instantiate the insert picture class */
$objDrawing = new \PHPExcel_Worksheet_Drawing ();
/* Set the image path Bear in mind : Only local pictures */
$objDrawing->setPath ( './img/test.jpg' );
/* Set the image height */
$objDrawing->setHeight ( 100 );
/* Set the position of the cell where the picture is to be inserted */
$objDrawing->setCoordinates ( 'C' . '2' ); // The second line here C Column
// Write the... Of the picture in the specified grid X Coordinate value
$objDrawing->setOffsetX ( 20 );
// Write the... Of the picture in the specified grid Y Coordinate value
$objDrawing->setOffsetY ( 20 );
// Set the rotation angle
// $objDrawing->setRotation(20);
$objDrawing->getShadow ()->setVisible ( true );
$objDrawing->getShadow ()->setDirection ( 50 );
$objDrawing->setWorksheet ( $objPHPExcel->getActiveSheet () );
// Set cell height
$objPHPExcel->getActiveSheet ()->getRowDimension ( $key + 2 )->setRowHeight ( 100 );
$objPHPExcel->setActiveSheetIndex ( 0 )->setCellValue ( 'D' . '2', ' ' . '2017-08-24 16:01' ); // The second line D The column value
// If adding rows circularly , Then the loop ends here
// Rename worksheet
$objPHPExcel->getActiveSheet ()->setTitle ( 'Simple' );
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex ( 0 );
// Redirect output to the client Web browser (Excel2007)
header ( 'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' );
header ( 'Content-Disposition: attachment;filename=" Test filename .xlsx"' );
header ( 'Cache-Control: max-age=0' );
// If it is IE9 browser , You need the following
header ( 'Cache-Control: max-age=1' );
// If it's a belt SSL Of IE, You may use the following
header ( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); // Past date
header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s' ) . ' GMT' ); // Real time
header ( 'Cache-Control: cache, must-revalidate' ); // HTTP/1.1
header ( 'Pragma: public' ); // HTTP/1.0
$objWriter = \PHPExcel_IOFactory::createWriter ( $objPHPExcel, 'Excel2007' );
$objWriter->save ( 'php://output' );边栏推荐
- An interesting example of relaxed memory models
- Application and challenge of ten billion level map data in Kwai security intelligence
- Rebirth -- C language and the story I have to tell (text)
- Cmake passing related macros to source code
- Summary of the first week of winter vacation
- 1. introduction to MySQL database connection pool function technology points
- 1. Mx6u bare metal program (4) - GPIO module
- Uniapp View Horizontal Center
- Three methods for solving Fibonacci sequence feibonacci (seeking rabbit) - program design
- Array part
猜你喜欢

Byte order: big endian vs little endian

Questions not written in the monthly contest

C language games: sanziqi (simple version) implementation explanation

5g access network and base station evolution

Google account cannot be logged in & external links cannot be opened automatically & words with words cannot be used

Rebirth -- C language and the story I have to tell (text)

1. Mx6u bare metal program (2) - Lighting master (imitating 32 register version)

5. explain function overloading

Three methods for solving Fibonacci sequence feibonacci (seeking rabbit) - program design

JS to realize the rotation chart (riding light). Pictures can be switched left and right. Moving the mouse will stop the rotation
随机推荐
1. Mx6u bare metal program (1) - Lighting master
//1.14 comma operator and comma expression
Error C2061 syntax error: identifier ‘PreparedStatement‘
Common mistakes in C language (sizeof and strlen)
Branch and loop statements (including goto statements) -part1
Bc117 xiaolele walks up the steps
Deep learning environment configuration (III) pytorch GPU under Anaconda
//1.17 printf function
Why is BeanUtils not recommended?
1. Mx6u bare metal program (5) - external interrupt
"Initial C language" (Part 2)
Ch340 and PL2303 installation (with link)
Cmake simple usage
Arm assembly syntax
Ugui empty button implementation
//1.10 initial value of variable
Custom shapes for ugui skill learning
3. compilation and linking principle
Cmake passing related macros to source code
Digital integrated circuit design process