Use PHPExcel to export files
PHPExcel to export mysql database data
The above article is for reference
The following is the code for PHPExcel style setting:
<span style="font-size:24px;"><?php $dir = dirname(__FILE__); require $dir."/db.php"; require $dir."/PHPExcel.php"; $db = new db($phpexcel); $objPHPExcel = new PHPExcel(); for($i=0; $i<3; $i++){ if($i>0){ $objPHPExcel->createSheet(); } $objPHPExcel->setActiveSheetIndex($i); $objSheet = $objPHPExcel->getActiveSheet(); $objSheet->getColumnDimension('D')->setWidth(21); //设置列宽 $objSheet->getColumnDimension('E')->setWidth(16); $objSheet->getColumnDimension('F')->setWidth(21); $objSheet->getRowDimension('1')->setRowHeight(80); //设置行高 $objSheet->getRowDimension('2')->setRowHeight(29); $objSheet->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER) ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); //设置水平垂直居中 $objSheet->getDefaultStyle()->getFont()->setName("微软雅黑")->setSize(12); //设置默认字体大小 $objSheet->getStyle("A1:F1")->getFont()->setSize(20)->setBold(true); //标题字体 $objSheet->getStyle('A1:F1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID) ->getStartColor()->setARGB('FFFF0000'); //设置标题背景颜色 $objSheet->getStyle("A1:F1")->applyFromArray(getBorderStyle("#66FF99")); //设置标题边框 $data = $db->getUserinfo(); $j = 1; $objSheet->setCellValue("A".$j,"****\n****"); $objSheet->getStyle('A1')->getAlignment()->setWrapText(true); //设置换行 $objSheet->mergeCells("A".$j.":F".$j); //合并单元格 $j++; $objSheet->setCellValue("A".$j,"编号")->setCellValue("B".$j,"登陆名") ->setCellValue("C".$j,"昵称")->setCellValue("D".$j,"电子邮箱") ->setCellValue("E".$j,"学校")->setCellValue("F".$j,"最后登陆时间") ->setCellValue("G".$j,"随机数"); $j++; foreach ($data as $key => $value) { # code... $objSheet->setCellValue("A".$j,$value['id'])->setCellValue("B".$j,$value['user_login']) ->setCellValue("C".$j,$value['user_nicename'])->setCellValue("D".$j,$value['user_email']) ->setCellValue("E".$j,$value['sch_name'])->setCellValue("F".$j,$value['last_login_time']) //显示数字的方法 1.指定为字符串 2.设置格式 //->setCellValueExplicit("G".$j,rand(1000000000,9999999999),PHPExcel_Cell_DataType::TYPE_STRING); ->setCellValue("G".$j,rand(100000000,999999999)); //下面以文本格式显示数字 $objSheet->getStyle('G'.$j)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT); $j++; } } $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,"Excel5"); // $objWriter->save($dir.'/export.xls'); //生成excel文件 browser_export("Excel5","browser_excel03.xls"); //浏览器输出 $objWriter->save("php://output"); function browser_export($type, $filename){ if($type == "Excel5"){ header('Content-Type: application/vnd.ms-excel'); //excel2003 }else{ header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); //excel2007 } header('Content-Disposition: attachment;filename="'.$filename.'"'); header('Cache-Control: max-age=0'); } /* *获得不同颜色的边框 */ function getBorderStyle($color){ $styleArray = array( 'borders' => array( 'outline' => array( 'style' => PHPExcel_Style_Border::BORDER_THICK, 'color' => array('rgb' => $color), ), ), ); return $styleArray; } </span>PHPExcel style function can refer to programming Document

For example, the number format we used above displays:
Ctrl + left mouse button to open
The code is all written, we Just use it, it's very convenient. There are all the setting functions in the document, and you can look it up when needed.
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above has introduced PHPExcel style control, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

To protect the application from session-related XSS attacks, the following measures are required: 1. Set the HttpOnly and Secure flags to protect the session cookies. 2. Export codes for all user inputs. 3. Implement content security policy (CSP) to limit script sources. Through these policies, session-related XSS attacks can be effectively protected and user data can be ensured.

Methods to optimize PHP session performance include: 1. Delay session start, 2. Use database to store sessions, 3. Compress session data, 4. Manage session life cycle, and 5. Implement session sharing. These strategies can significantly improve the efficiency of applications in high concurrency environments.

Thesession.gc_maxlifetimesettinginPHPdeterminesthelifespanofsessiondata,setinseconds.1)It'sconfiguredinphp.iniorviaini_set().2)Abalanceisneededtoavoidperformanceissuesandunexpectedlogouts.3)PHP'sgarbagecollectionisprobabilistic,influencedbygc_probabi

In PHP, you can use the session_name() function to configure the session name. The specific steps are as follows: 1. Use the session_name() function to set the session name, such as session_name("my_session"). 2. After setting the session name, call session_start() to start the session. Configuring session names can avoid session data conflicts between multiple applications and enhance security, but pay attention to the uniqueness, security, length and setting timing of session names.

The session ID should be regenerated regularly at login, before sensitive operations, and every 30 minutes. 1. Regenerate the session ID when logging in to prevent session fixed attacks. 2. Regenerate before sensitive operations to improve safety. 3. Regular regeneration reduces long-term utilization risks, but the user experience needs to be weighed.

Setting session cookie parameters in PHP can be achieved through the session_set_cookie_params() function. 1) Use this function to set parameters, such as expiration time, path, domain name, security flag, etc.; 2) Call session_start() to make the parameters take effect; 3) Dynamically adjust parameters according to needs, such as user login status; 4) Pay attention to setting secure and httponly flags to improve security.

The main purpose of using sessions in PHP is to maintain the status of the user between different pages. 1) The session is started through the session_start() function, creating a unique session ID and storing it in the user cookie. 2) Session data is saved on the server, allowing data to be passed between different requests, such as login status and shopping cart content.

How to share a session between subdomains? Implemented by setting session cookies for common domain names. 1. Set the domain of the session cookie to .example.com on the server side. 2. Choose the appropriate session storage method, such as memory, database or distributed cache. 3. Pass the session ID through cookies, and the server retrieves and updates the session data based on the ID.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools