s is second line”.”\t”; echo “Hi,pretty girl”.”\t”; echo “\t\n”; ?>
6、使用com 如果你的PHP可以开启com模块,就可以用它来导出Excel文件
PHP代码 <?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_result\n”; $Worksheet = $Workbook->Worksheets($sheet2); $Worksheet->activate; $excel_cell = $Worksheet->Range(”C4″); $excel_cell->activate; $excel_result = $excel_cell->value; print “$excel_result\n”; #To close all instances of excel: $Workbook->Close; unset($Worksheet); unset($Workbook); $excel_app->Workbooks->Close(); $excel_app->Quit(); unset($excel_app); ?>
一个更好的例子: http://blog.chinaunix.net/u/16928/showart_387171.html
一、PHP导入Excel
1:还是用PHPExcel,官方网站: http://www.codeplex.com/PHPExcel。
2:使用PHP-ExcelReader,下载地址: http://sourceforge.net/projects/phpexcelreader 举例:
PHP代码 <?php require_once ‘Excel/reader.php’; // ExcelFile($filename, $encoding); $data = new Spreadsheet_Excel_Reader(); // Set output Encoding. $data->setOutputEncoding(’utf8′); $data->read(’ jxlrwtest.xls’); error_reporting(E_ALL ^ E_NOTICE); for ($i = 1; $i <= $data->sheets[0][''numRows'']; $i++) { for ($j = 1; $j <= $data->sheets[0][''numCols'']; $j++) { echo “\”".$data->sheets[0][''cells''][$i][$j].”\”,”; } echo “\n”; } ?>
---------- 本站采用创作共享版权协议, 要求署名、非商业和保持一致. 本站欢迎任何非商业应用的转载, 但须注明出自" 膘叔 簡單人生", 保留原始链接, 此外还必须标注原文标题和链接. |