Home >php教程 >php手册 >PHP操作excel的一个例子(原创)

PHP操作excel的一个例子(原创)

WBOY
WBOYOriginal
2016-06-21 09:11:341669browse

excel|原创

这是对于那些只喜欢简单处理一下excel朋友来说的


//定义一个excel文件
$workbook = "C:/My Documents/test.xls";
$sheet = "Sheet1";

//生成一个com对象$ex
$ex = new COM("Excel.sheet") or Die ("连不上!!!");

//打开一个excel文件
$book = $ex->application->Workbooks->Open($workbook) or Die ("打不开!!!");

$sheets = $book->Worksheets($sheet);
$sheets->activate;

//获取一个单元格
$cell = $sheets->Cells(5,5);
$cell->activate;
//给该单元格赋值
$cell->value = 999;

//保存为另一文件newtest.xls
$ex->Application->ActiveWorkbook->SaveAs("newtest.xls");

//关掉excel,如果想看效果,则注释掉下面两行,由用户手动关掉excel
$ex->Application->ActiveWorkbook->Close("False");
unset ($ex);

?>



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