
解析:
将下面的代码存为excel.php ,然后在页面中包括进来
然后调用
1. Call xlsBOF()
2. 将一些内容写入到xlswritenunber() 或者 xlswritelabel()中.
3.然后调用 Call xlsEOF()
也可以用 fwrite 函数直接写到服务器上,而不是用echo 仅仅在浏览器上显示。
<?php
----- begin of function library -----
Excel begin of file header
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0)
return
}
Excel end of file footer
function xlsEOF() {
echo pack("ss", 0x0A, 0x00)
return
}
Function to write a Number (double) into Row, Col
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0)
echo pack("d", $Value)
return
}
Function to write a label (text) into Row, Col
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value)
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L)
echo $Value
return
}
----- end of function library -----
?>
To display the contents directly in a MIME patible browser
add the following lines on TOP of your PHP file:
<?php
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT")
header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT")
header ("Cache-Control: no-cache, must-revalidate")
header ("Pragma: no-cache")
header ('Content-type: application/x-msexcel')
header ("Content-Disposition: attachmentfilename=EmplList.xls" )
header ("Content-Description: PHP/INTERBASE Generated Data" )
the next lines demonstrate the generation of the Excel stream
xlsBOF()begin Excel stream
xlsWriteLabel(0,0,"This is a label")write a label in A1, use for dates too
xlsWriteNumber(0,1,9999)write a number B1
xlsEOF()close the stream
?>
根据下列编码程序可以。
1./*** 批量导出数据* @param $arr 从数据库查询出来,即要导出的数据* $name excel表歌名*/
2.function expExcel($arr,$name){ require_once 'PHPExcel.php'
3. //实例化 $objPHPExcel = new PHPExcel() /*右键属性所显示的信息*/
4.$objPHPExcel->getProperties()->setCreator("zxf") // ->setLastModifiedBy("zxf") //最后一 ->setTitle('数据EXCEL导出') //标题->setSubject('数据EXCEL导出') //主题>setDescription('导出数据') //描>setKeywords("excel") //标记>setCategory("result file") //类别
5. //设置当前的表格 $objPHPExcel->setActiveSheetIndex(0)// 设置表格第一行显示内容$objPHPExcel->getActiveSheet() ->setCellValue('A1', '业主姓名') ->setCellValue('B1', '密码')->setCellValue('C1', '手机号码' ->setCellValue('D1', '地址')
6.//设置第一行为红色字体 ->getStyle('A1:D1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_RED)$key = 1 /*以下就是对处理Excel里的数据。
PHP读取excel的方法,如果你的服务器不支持COM组件,我就不好说了,下面的只是示范的例子。<?PHP$filename = "c:/spreadhseet/test.xls"
$sheet1 = 1
$sheet2 = "sheet2"
$excel_app = new COM("Excel.application") or Die ("Did not connect")
print "Application name: {$excel_app->Application->value}n"
print "Loaded version: {$excel_app->Application->version}n"
$Workbook = $excel_app->Workbooks->Open("$filename") or Die("Did not open $filename $Workbook")
$Worksheet = $Workbook->Worksheets($sheet1)
$Worksheet->activate
$excel_cell = $Worksheet->Range("C4")
$excel_cell->activate
$excel_result = $excel_cell->value
print "$excel_resultn"
$Worksheet = $Workbook->Worksheets($sheet2)
$Worksheet->activate
$excel_cell = $Worksheet->Range("C4")
$excel_cell->activate
$excel_result = $excel_cell->value
print "$excel_resultn"
#To close all instances of excel:
$Workbook->Close
unset($Worksheet)
unset($Workbook)
$excel_app->Workbooks->Close()
$excel_app->Quit()
unset($excel_app)
?>
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)