程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> phpexcel讀寫xls文件實現程序

phpexcel讀寫xls文件實現程序

編輯:關於PHP編程

文章介紹了關於phpexcel讀寫xls文件的方法代碼,有需要了解的同學可以參考一下本教程哦。  代碼如下 復制代碼

<?php
include_once('PHPExcel.php');
//read excel file;
$PHPExcel = new PHPExcel();    
$PHPReader = new PHPExcel_Reader_Excel5();
$PHPExcel = $PHPReader->load('/home/yuanjianjun/taobao_cat.xls');
$currentSheet = $PHPExcel->getSheet(0);
$allColumn = $currentSheet->getHighestColumn();
$allRow = $currentSheet->getHighestRow();
for($currentRow = 1; $currentRow<=$allRow; $currentRow++){
   for($currentColumn='A'; $currentColumn<=$allColumn; $currentColumn++){  
    $address = $currentColumn.$currentRow;  
    echo $currentSheet->getCell($address)->getValue()."t";  
   }
   echo "n";
}


//write excel file
$objExcel = new PHPExcel();
$objWriter = new PHPExcel_Writer_Excel5($objExcel);
$objProps = $objExcel->getProperties();  
$objProps->setCreator("yuan");
$objProps->setLastModifiedBy("yuan");
$objProps->setTitle("excel test");  
$objProps->setSubject("my excel test");
$objProps->setDescription("hello world.");  
$objProps->setKeywords("PHPExcel");
$objProps->setCategory("EXCEL");
$objExcel->setActiveSheetIndex(0);
$objActSheet = $objExcel->getActiveSheet();
$objActSheet->setTitle('TEST1');
$objActSheet->setCellValue('A1', '字符串內容');
$objActSheet->setCellValue('A2', 26);
$objActSheet->setCellValue('A3', true);
$objActSheet->setCellValue('A4', '=A2+A2');
$objWriter->save('/home/yuanjianjun/helloworld.xls');  


//copy excel format
$objReader = PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel = $objReader->load('/home/yuanjianjun/20100301.xls');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->_phpExcel->setActiveSheetIndex(0);
$objWriter->_phpExcel->getActiveSheet()->setCellValue('A1', 'FESDF');
$objWriter->_phpExcel->getActiveSheet()->setCellValue('B1', 'S');
$objWriter->_phpExcel->getActiveSheet()->setCellValue('C1', 'FEFSD');
$objWriter->_phpExcel->getActiveSheet()->setCellValue('D1', 'SDFD');
$objWriter->_phpExcel->getActiveSheet()->setCellValue('E1', '淘寶CPS');
$objWriter->save('/home/yuanjianjun/copy.xls');

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved