vendor('PHPExcel.PHPExcel');
$objPHPExcel
=
new
PHPExcel();
$objPHPExcel
->getProperties()
->setCreator(
"web100.cc"
)
->setLastModifiedBy(
"web100.cc"
)
->setTitle(
"Office 2007 XLSX Test Document"
)
->setSubject(
"Office 2007 XLSX Test Document"
)
->setDescription(
"Test document generated using PHP classes."
)
->setKeywords(
"office 2007 openxml php"
)
->setCategory(
"Test result file"
);
$objPHPExcel
->setActiveSheetIndex(0);
$objActSheet
=
$objPHPExcel
->11getActiveSheet();
$objActSheet
->setTitle('phpexcel demo');
$objActSheet
->getDefaultRowDimension()->setRowHeight(15);
$objActSheet
->setCellValue('A1',
"Firstname"
);
$objActSheet
->setCellValue('B1',
"Lastname"
);
$objActSheet
->setCellValue('C1',
"Phone"
);
$objActSheet
->setCellValue('D1',
"Fax"
);
$objActSheet
->setCellValue('E1',
"Address"
);
$objActSheet
->setCellValue('F1',
"ZIP"
);
$objActSheet
->setCellValue('G1',
"DATE"
);
$objActSheet
->setCellValueByColumnAndRow(0, 8, 'firstname');
$objActSheet
->setCellValueByColumnAndRow(1, 8, 'lastname');
$objActSheet
->setCellValue('A2',
"小风"
);
$objActSheet
->setCellValue('B2',
"wang"
);
$objActSheet
->getColumnDimension('C')->setWidth('20');
$objActSheet
->getRowDimension('9')->setRowHeight(20);
$objActSheet
->getStyle('A1')->getFont()->setName('宋体');
$objActSheet
->getStyle('A1')->getFont()->setSize(12);
$objActSheet
->getStyle('A1')->getFont()->setBold(true);
$objActSheet
->getCell('C2')->setValueExplicit('861391327543258', PHPExcel_Cell_DataType::TYPE_NUMERIC);
$objActSheet
->setCellValue('G2', '2008-12-31');
$objActSheet
->getStyle('G2')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH);
$time
=
gmmktime
(0,0,0,12,31,2008);
$objActSheet
->setCellValue('G3', PHPExcel_Shared_Date::PHPToExcel(
$time
));
$objActSheet
->getStyle('G3')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH);
$objActSheet
->setCellValue('G11', 'www.spalybow.com');
$objActSheet
->getCell('G11')->getHyperlink()->setUrl('http:
$objActSheet
->setCellValue('G12', 'sheetb');
$objActSheet
->getCell('G12')->getHyperlink()->setUrl(
"sheet://'sheetb'!A1"
);
$objActSheet
->getStyle('A9:B9')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
$objActSheet
->getStyle('G2:G3')->getAlignment()->setWrapText(true);
$objActSheet
->mergeCells('A18:E22');
$objActSheet
->getColumnDimension('D')->setVisible(false);
$objActSheet
->getColumnDimension('E')->setOutlineLevel(1);
$objActSheet
->getColumnDimension('E')->setVisible(false);
$objActSheet
->getColumnDimension('F')->setOutlineLevel(1);
$objActSheet
->getColumnDimension('F')->setVisible(false);
$objActSheet
->getColumnDimension('F')->setCollapsed(true);
$objActSheet
->freezePane('A2');
$objActSheet
->getProtection()->setPassword('PHPExcel');
$objActSheet
->getProtection()->setSheet(true);
$objActSheet
->getProtection()->setSort(true);
$objActSheet
->getProtection()->setInsertRows(true);
$objActSheet
->getProtection()->setFormatCells(true);
$sharedStyle1
=
new
PHPExcel_Style();
$sharedStyle1
->applyFromArray(
array
('borders' =>
array
(
'left' =>
array
('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
)
));
$objActSheet
->setSharedStyle(
$sharedStyle1
,
"B1:B10"
);
$objWorksheet1
=
$objPHPExcel
->createSheet();
$objWorksheet1
->setTitle('sheetb');
$objPHPExcel
->setActiveSheetIndex(1);
$gdImage
= @imagecreatetruecolor(200, 20)
or
die
('Cannot Initialize
new
GD image stream');
$textColor
= imagecolorallocate(
$gdImage
, 255, 255, 255);
imagestring(
$gdImage
, 1, 5, 5, 'Created with PHPExcel (c1gstudio.com)',
$textColor
);
$objDrawing
=
new
PHPExcel_Worksheet_MemoryDrawing();
$objDrawing
->setName('Sample image');
$objDrawing
->setDescription('Sample image');
$objDrawing
->setImageResource(
$gdImage
);
$objDrawing
->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing
->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing
->setHeight(36);
$objDrawing
->setWorksheet(
$objActSheet
);
$objPHPExcel
->setActiveSheetIndex(0);
$objWriter
= PHPExcel_IOFactory::createWriter(
$objPHPExcel
, 'Excel5');
$objWriter
->save('testexcel'.time().'.xls');