当前位置: 网学 > 编程文档 > PHP > 正文

php编程实现获取excel文档内容的代码实例

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/22
)
/**
* todo
*
* @access public
* @param offset
*/
function setRowColOffset($iOffset)
{
$this->_rowoffset = $iOffset;
$this->_coloffset = $iOffset;
}
// }}}
// {{{ setDefaultFormat()
/**
* Set the default number format
*
* @access public
* @param Default format
*/
function setDefaultFormat($sFormat)
{
$this->_defaultFormat = $sFormat;
}
// }}}
// {{{ setColumnFormat()
/**
* Force a column to use a certain format
*
* @access public
* @param integer Column number
* @param string Format
*/
function setColumnFormat($column, $sFormat)
{
$this->_columnsFormat[$column] = $sFormat;
}
// }}}
// {{{ read()
/**
* Read the spreadsheet file using OLE, then parse
*
* @access public
* @param filename
* @todo return a valid value
*/
function read($sFileName)
{
/*
require_once ''OLE.php'';
$ole = new OLE();
$ole->read($sFileName);
foreach ($ole->_list as $i => $pps) {
if (($pps->Name == ''Workbook'' || $pps->Name == ''Book'') &&
$pps->Size >= SMALL_BLOCK_THRESHOLD) {
$this->data = $ole->getData($i, 0, $ole->getDataLength($i));
} elseif ($pps->Name == ''Root Entry'') {
$this->data = $ole->getData($i, 0, $ole->getDataLength($i));
}
//var_dump(strlen($ole->getData($i, 0, $ole->getDataLength($i))), $pps->Name, md5($this->data), $ole->getDataLength($i));
}
//exit;
$this->_parse();
return sizeof($this->sheets) > 0;
*/
$res = $this->_ole->read($sFileName);
// oops, something goes wrong (Darko Miljanovic)
if($res === false) {
// check error code
if($this->_ole->error == 1) {
// bad file
die(''The filename '' . $sFileName . '' is not readable'');
}
// check other error codes here (eg bad fileformat, etc...)
}
$this->data = $this->_ole->getWorkBook();
/*
$res = $this->_ole->read($sFileName);
if ($this->isError($res)) {
// var_dump($res);
return $this->raiseError($res);
}
$total = $this->_ole->ppsTotal();
for ($i = 0; $i < $total; $i++) {
if ($this->_ole->isFile($i)) {
$type = unpack("v", $this->_ole->getData($i, 0, 2));
if ($type[''''] == 0x0809) { // check if it''s a BIFF stream
$this->_index = $i;
$this->data = $this->_ole->getData($i, 0, $this->_ole->getDataLength($i));
break;
}
}
}
if ($this->_index === null) {
return $this->raiseError("$file doesn''t seem to be an Excel file");
}
*/
//echo "data =".$this->data;
//$this->readRecords();
$this->_parse();
}
// }}}
// {{{ _parse()
/**
* Parse a workbook
*
* @access private
* @return bool
*/
function _parse()
{
$pos = 0;
$code = ord($this->data[$pos]) | ord($this->data[$pos+1])<<8;
$length = ord($this->data[$pos+2]) | ord($this->data[$pos+3])<<8;
$version = ord($this->data[$pos + 4]) | ord($this->data[$pos + 5])<<8;
$substreamType = ord($this->data[$pos + 6]) | ord($this->data[$pos + 7])<<8;
//echo "Start parse code=".base_convert($code,10,16)." version=".base_convert($version,10,16)." substreamType=".base_convert(
  • 上一篇资讯: PHP学习笔记之数组篇
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号