-
-
//Load the PHPExcel class - require './phpexcel/PHPExcel.php';
//Create an excel object instance
- $objPHPExcel = new PHPExcel();
//Set the basic properties of the document
- $objProps = $objPHPExcel->getProperties();
- $objProps->setCreator("Lao Mao" );
- $objProps->setLastModifiedBy("Lao Mao");
- $objProps->setTitle("Office XLS Test Document");
- $objProps->setSubject("Office XLS Test Document, Demo");
- $objProps->setDescription("Test document, generated by PHPExcel.");
- $objProps->setKeywords("office excel PHPExcel");
- $objProps->setCategory("Test"); p>
//Set the current sheet index for subsequent content operations.
- //Generally, display calls are only needed when using multiple sheets.
- //By default, PHPExcel will automatically create the first sheet with SheetIndex=0
- $objPHPExcel->setActiveSheetIndex(0);
//Set the name of the current active sheet
- $objActSheet = $objPHPExcel->getActiveSheet();
- $objActSheet->setTitle('Test Sheet');
//Set cell content
- //The data here can Read from the database and then perform loop processing
- //by bbs.it-home.org
- $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'a1');
- $objPHPExcel-> ;getActiveSheet()->SetCellValue('A2', 'a2');
- $objPHPExcel->getActiveSheet()->SetCellValue('A3', 'a3');
- $objPHPExcel->getActiveSheet() ->SetCellValue('A4', 'a4');
- $objPHPExcel->getActiveSheet()->SetCellValue('A5', 'a5');
$objPHPExcel- >getActiveSheet()->SetCellValue('B1', 'b1');
- $objPHPExcel->getActiveSheet()->SetCellValue('B2', 'b2');
- $objPHPExcel->getActiveSheet( )->SetCellValue('B3', 'b3');
- $objPHPExcel->getActiveSheet()->SetCellValue('B4', 'b4');
- $objPHPExcel->getActiveSheet()-> SetCellValue('B5', 'b5');
$objPHPExcel->getActiveSheet()->SetCellValue('C1', 'c1');
- $objPHPExcel->getActiveSheet ()->SetCellValue('C2', 'c2');
- $objPHPExcel->getActiveSheet()->SetCellValue('C3', 'c3');
- $objPHPExcel->getActiveSheet()-> ;SetCellValue('C4', 'c4');
- $objPHPExcel->getActiveSheet()->SetCellValue('C5', 'c5');
//Output document
- $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
//Set the header information and output it to the browser
- //header('Content-Type: application/vnd.ms-excel ');
- //header("Content-Disposition:attachment; filename=demo.xls");
- //header('Cache-Control: max-age=0');
- //$objWriter->save ('php://output');
//Save to a certain location
- $objWriter->save(dirname(__FILE__) . '/demo.xls');< /p>
-
Copy code
|