Home  >  Article  >  Backend Development  >  PHPExcel 导入导出 excel 文件 范例

PHPExcel 导入导出 excel 文件 范例

WBOY
WBOYOriginal
2016-06-13 11:58:09783browse

PHPExcel 导入导出 excel 文件 实例

public static function exportExcel($fileName,$displayFields,$exportList)

{

$objExcel = new PHPExcel();

//set document Property

$objWriter = PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');

$objActSheet = $objExcel->getActiveSheet();

$key = ord("A");

foreach ($displayFields as $filedValue)

{

$colum = chr($key);

$objActSheet->setCellValue($colum.'1', $filedValue);

$key += 1;

}

$column = 2;

foreach($exportList as $key => $rows){

$span = ord("A");

foreach($rows as $keyName=>$value){

$j = chr($span);

$objActSheet->setCellValue($j.$column, $value);

$span++;

}

$column++;

}

//*************************************

$outfile = $fileName.".xls";

//export to exploer

header("Content-Type: application/force-download");

header("Content-Type: application/octet-stream");

header("Content-Type: application/download");

header('Content-Disposition:inline;filename="'.$outfile.'"');

header("Content-Transfer-Encoding: binary");

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

header("Pragma: no-cache");

$objWriter->save('php://output');

exit;

}


这是我编程的时候一个小实例,在这里mark下, 如果你也想做一个简单的实例的话,可以直接拿来用,主要是对行,列的读取。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn