setLastModifiedBy("Maarten Ballia">
当前位置:Gxlcms > PHP教程 > phpexcel,该如何处理

phpexcel,该如何处理

时间:2021-07-01 10:21:17 帮助过:18人阅读

php excel
error_reporting(E_ALL);
date_default_timezone_set('Europe/London');
/** PHPExcel */
require_once '../Classes/PHPExcel.php';

// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

// Set properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");
$objPHPExcel->getActiveSheet()->mergeCells('A1:G1');
$objPHPExcel->getActiveSheet()->mergeCells('H1:W1');
$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('H1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);

// Add some data


$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'user-data')
->setCellValue('A2', 'username')
->setCellValue('B2', 'password')
->setCellValue('C2', 'sex')
->setCellValue('D2', 'grade')
->setCellValue('E2', 'age')
->setCellValue('F2', 'weight')
->setCellValue('G2', 'height')
->setCellValue('H1', 'Module1')
->setCellValue('I2', 'Q2')
->setCellValue('J2', 'Q3')
->setCellValue('K2', 'Q4')
->setCellValue('L2', 'Q5')
->setCellValue('M2', 'Q6')
->setCellValue('N2', 'Q7')
->setCellValue('O2', 'Q2')
->setCellValue('P2', 'Q3')
->setCellValue('Q2', 'Q4')
->setCellValue('R2', 'Q5')
->setCellValue('S2', 'Q6')
->setCellValue('T2', 'Q7')
->setCellValue('U2', 'Q2')
->setCellValue('V2', 'Q3')
->setCellValue('W2', 'Q4')
->setCellValue('X1', 'Module2')
->setCellValue('Y2', 'Q1')
->setCellValue('Z2', 'Q2');

//数据库连接
$db = mysql_connect("localhost", "root", "");
mysql_select_db("test",$db); //选择数据库,这里为"ywcl"。
mysql_query("SET NAMES UTF8"); //设定编码方式为UTF8

$sqlgroups="select * from user order by username";
$resultgroups=mysql_query($sqlgroups);

人气教程排行