The example in this article describes the operation of the PHP implementation of the Excel class. Share to everyone for your reference, as follows:
<?phpclass excel{static $instance =null; Private $excel =null; Private $workbook =null; Private $workbookadd =null; Private $worksheet =null; Private $worksheetadd =null; Private $sheetnum = 1; Private $cells =array (); Private $fields =array (); Private $maxrows; Private $maxcols; Private $filename; constructor Private Function Excel () {$this->excel = new COM ("Excel.Application") or Die ("Do not Connect"); }//Class Entry public static function getinstance () {if (null = = self:: $instance) {self:: $instance = new Excel (); } return Self:: $instance; }//Set file address Public function Setfile ($filename) {return $this->filename= $filename; }//Open file Public function open () {$this->workbook= $this->excel->workbooks->open ($this->filename); }//Set sheet Public function Setsheet ($num =1) {if ($num >0) {$this->sheetnum= $num; $this->worksheet= $this->excel->worksheets[$this->sheetnum]; $this->maxcols= $thisMaxcols (); $this->maxrows= $this->maxrows (); $this->getcells (); }}//Get all values of the table and write into the array private function Getcells () {for ($i =1; $i < $this->maxcols; $i + +) {for ($j =2; $j < $th is->maxrows; $j + +) {$this->cells[$this->worksheet->cells (1, $i)->value][]= (string) $this->work Sheet->cells ($j, $i)->value; }} return $this->cells; }//Returns the table Content array public Function Getalldata () {return $this->cells; }//Returns the contents of the Public Function cell ($row, $col) {return $this->worksheet->cells ($row, $col)->value; }//Get table field an array group Public function GetFields () {for ($i =1; $i < $this->maxcols; $i + +) {$this->fields[]= $thi S->worksheet->cells (1, $i)->value; } return $this->fields; }//Modify to make cell contents public function Editcell ($row, $col, $value) {if ($this->workbook==null | | $this->worksheet==null) {echo "Error:did not connect!"; }else{$this->worksheet->cells ($row, $col)->value= $value; $this->workbook->save (); }}//modify one row of data public function Editonerow ($row, $arr) {if ($this->workbook==null | | $this->worksheet==null | | $r ow>=2) {echo "Error:did not connect!"; }else{if (count ($arr) = = $this->maxcols-1) {$i = 1; foreach ($arr as $val) {$this->worksheet->cells ($row, $i)->value= $val; $i + +; } $this->workbook->save (); }}}//Get total number of columns Private function Maxcols () {$i = 1; while (true) {if (0== $this->worksheet->cells (1, $i)) {return $i; Break } $i + +; }}//Get Total Row number Private function MaxRows () {$i = 1; while (true) {if (0== $this->worksheet->cells ($i, 1)) {return $i; Break } $i + +; }}//Read make row data public function Getonerow ($row =2) {if ($row >=2) {for ($i =1; $i < $this->maxcols; $i + +) {$arr []= $this-≫worksheet->cells ($row, $i)->value; } return $arr; }}//Close object public function close () {$this->excel->workbooks->close (); $this->excel=null; $this->workbook=null; $this->worksheet=null; Self:: $instance =null; }};/* $excel = new COM ("Excel.Application"); $workbook = $excel->workbooks->open (' d://apache2//htdocs//wwwroot/ /myexcel.xls '); $worksheet = $excel->worksheets (1); Echo $worksheet->cells (2,6)->value; $excel Workbooks->close (); */$excel =excel::getinstance (); $excel->setfile ("D://kaka.xls"); $excel->open (); $ Excel->setsheet (); for ($i =1; $i <16; $i + +) {$arr []= $i;} $excel->editonerow (2, $arr);//print_r ($excel->getalldata ()); $str = $excel->getalldata (); Include_once (' mail.class.php '); $smtpserver = "Smtp.yeah.net"; $smtpserverport = 25; $smtpuseremail = "Yanqihu58@yeah.net"; $smtpemailto = "yanqihu@139.com"; $smtpuser = "yanqihu58"; $smtppwd = "123456789"; $mailtype = "HTML"; $SMTP =new SMTP ($smtpserver, $smtpserverport, True, $smtpuser, $smtppwd); $message = "Hello"; $message. = "Home connection address:". $this->link_url. "
"; $message. = "E-mail:". $this->link_email. "
"; $message. = "Business Contact QQ:". $this->link_qq. "
"; $message. = "Business phone QQ:" $this->link_tel. "
"; $message. = "Contacts:" $this->link_people. "
"; $SMTP->debug=false; foreach ($str [' email '] as $key = + $value) {$smtpemailto = $value; @ $smtp->sendmail ($smtpemailto, $smtpuseremail, $mailsubject, $message, $mailtype); Exit }//exit; $excel->close ();? >
Read more about PHP operations in Excel related content readers can view this site: "PHP operation Office Document tips summary (including word,excel,access,ppt)"
I hope this article is helpful to you in PHP programming.
The above describes the PHP implementation of the operation of the Excel class, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.