Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Fala galera faz tempo que num posto por aqui...
Bem é o seguinte eu estou querendo ler uma planilha de Excel, Lembrando que eu estou usando um servidor LINUX. então a função COM() num rola em linux. e nem o ODBC pelo - nesse servidor que eu estou criando o aplicativo não tem a biblioteca relacionado ao MS-ODBC.
Queria ver se alguem tem um documento que informa o layout do aquivo do excel.. pois tendo o layout eu posso produzir uma classe para ler o EXCEL.
Ou se alguem tiver algum script "FUNCIONAL" para está me passando estarei grato tbm. mais a principio eu gostaria mesmo era do layout do ACIISS do EXCEL pois assim posso interpretar ela melhor e poder criar uma classe legal e deixo disponivel ae para a galera...
Valeu
Sim se for um CVS é a coisa mais facil que tem de trabalhar... mais o problema que eles aqui no trampo querem que a gente lé o Excel... ja dei a ideia de exportar por cvs mais num querem... eles num querem trabalho... fogo trabalhar com a diretoria dá nisso. querem que crie o mundo pra ontem :P
Eu tava procurando isso tambem e acharam pra mim. uma classe pronta.
não cheguei a usar ainda..
que ainda to me acostumando a usar classe :D
mais parece que faz o que você quer.
vese ela. te ajuda.
PHP
<?php/**
* MS-Excel stream handler
* This class read/writes a data stream directly
* from/to a Microsoft Excel spreadsheet
* opened with the xlsfile:// protocol
* This is used to export associative array data directly to MS-Excel
* @requires PHP 4 >= 4.3.2
* @author Ignatius Teo <ignatius@act28.com>
* @copyright ©2004 act28.com <[http://act28.com>](http://act28.com)
* @version 0.3
* @date 20 Jan 2005
* $Id: excel.php,v 1.3 2005/01/20 09:58:58 Owner Exp $
*/
class xlsStream
{
/ private /
var $position = 0; // stream pointer
var $mode = "rb"; // default stream open mode
var $xlsfilename = null; // stream name
var $fp = null; // internal stream pointer to physical file
var $buffer = null; // internal write buffer
var $endian = "unknown"; // little | unknown | big endian mode
var $bin = [array](http://br.php.net/array)(
"big" => "v",
"little" => "s",
"unknown" => "s",
);
/**
* detect server endian mode
* thanks to Charles Turner for picking this one up
* @access private
* @params void
* @returns void
* @see <a href="[http://www.phpdig.net/ref/rn45re877.html"](http://www.phpdig.net/ref/rn45re877.html) target="_blank">[http://www.phpdig.net/ref/rn45re877.html](http://www.phpdig.net/ref/rn45re877.html)
*/
function _detect()
{
// A hex number that may represent 'abyz'
$abyz = 0x6162797A;
// Convert $abyz to a binary string containing 32 bits
// Do the conversion the way that the system architecture wants to
switch ([pack](http://br.php.net/pack) ('L', $abyz))
{
// Compare the value to the same value converted in a Little-Endian fashion
case [pack](http://br.php.net/pack) ('V', $abyz):
$this->endian = "little";
break;
// Compare the value to the same value converted in a Big-Endian fashion
case [pack](http://br.php.net/pack) ('N', $abyz):
$this->endian = "big";
break;
default:
$this->endian = "unknown";
break;
}
}
/**
* called by fopen() to the stream
* @param (string) $path file path
* @param (string) $mode stream open mode
* @param (int) $options stream options (STREAM_USE_PATH |
* STREAM_REPORT_ERRORS)
* @param (string) $opened_path stream opened path
*/
function stream_open($path, $mode, $options, &$opened_path)
{
$url = [parse_url](http://br.php.net/parse_url)($path);
$this->xlsfilename = '/' . $url['host'] . $url['path'];
$this->position = 0;
$this->mode = $mode;
$this->_detect(); // detect endian mode
//@TODO: test for invalid mode and trigger error if required
// open underlying resource
$this->fp = @[fopen](http://br.php.net/fopen)($this->xlsfilename, $this->mode);
if ([is_resource](http://br.php.net/is_resource)($this->fp))
{
// empty the buffer
$this->buffer = "";
if ([preg_match](http://br.php.net/preg_match)("/^w|x/", $this->mode))
{
// write an Excel stream header
$str = [pack](http://br.php.net/pack)([str_repeat](http://br.php.net/str_repeat)($this->bin[$this->endian], 6), 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
[fwrite](http://br.php.net/fwrite)($this->fp, $str);
$opened_path = $this->xlsfilename;
$this->position = [strlen](http://br.php.net/strlen)($str);
}
}
return [is_resource](http://br.php.net/is_resource)($this->fp);
}
/**
* read the underlying stream resource (automatically called by fread/fgets)
* @todo modify this to convert an excel stream to an array
* @param (int) $byte_count number of bytes to read (in 8192 byte blocks)
*/
function stream_read($byte_count)
{
if ([is_resource](http://br.php.net/is_resource)($this->fp) && ($this->fp))
{
$data .= [fread](http://br.php.net/fread)($this->fp, $byte_count);
$this->position = [strlen](http://br.php.net/strlen)($data);
}
return $data;
}
/**
* called automatically by an fwrite() to the stream
* @param (string) $data serialized array data string
* representing a tabular worksheet
*/
function stream_write($data)
{
// buffer the data
$this->buffer .= $data;
$bufsize = [strlen](http://br.php.net/strlen)($data);
return $bufsize;
}
/**
* pseudo write function to manipulate the data
* stream before writing it
* modify this to suit your data array
* @access private
* @param (array) $data associative array representing
* a tabular worksheet
*/
function _xls_stream_write($data)
{
if ([is_array](http://br.php.net/is_array)($data) && ($data))
{
$row = 0;
foreach ([array_values](http://br.php.net/array_values)($data) as $_data)
{
if ([is_array](http://br.php.net/is_array)($_data) && ($_data))
{
if ($row == 0)
{
// write the column headers
foreach ([array_keys](http://br.php.net/array_keys)($_data) as $col => $val)
{
// next line intentionally commented out
// since we don't want a warning about the
// extra bytes written
// $size += $this->write($row, $col, $val);
$this->_xlsWriteCell($row, $col, $val);
}
$row++;
}
foreach ([array_values](http://br.php.net/array_values)($_data) as $col => $val)
{
$size += $this->_xlsWriteCell($row, $col, $val);
}
$row++;
}
}
}
return $size;
}
/**
* Excel worksheet cell insertion
* (single-worksheet supported only)
* @access private
* @param (int) $row worksheet row number (0...65536)
* @param (int) $col worksheet column number (0..255)
* @param (mixed) $val worksheet row number
*/
function _xlsWriteCell($row, $col, $val)
{
if ([is_float](http://br.php.net/is_float)($val) || [is_int](http://br.php.net/is_int)($val))
{
// doubles, floats, integers
$str = [pack](http://br.php.net/pack)([str_repeat](http://br.php.net/str_repeat)($this->bin[$this->endian], 5), 0x203, 14, $row, $col, 0x0);
$str .= [pack](http://br.php.net/pack)("d", $val);
}
else
{
// everything else is treated as a string
$l = [strlen](http://br.php.net/strlen)($val);
$str = [pack](http://br.php.net/pack)([str_repeat](http://br.php.net/str_repeat)($this->bin[$this->endian], 6), 0x204, 8 + $l, $row, $col, 0x0, $l);
$str .= $val;
}
[fwrite](http://br.php.net/fwrite)($this->fp, $str);
$this->position += [strlen](http://br.php.net/strlen)($str);
return [strlen](http://br.php.net/strlen)($str);
}
/**
* called by an fclose() on the stream
*/
function stream_close()
{
if ([preg_match](http://br.php.net/preg_match)("/^w|x/", $this->mode))
{
// flush the buffer
$bufsize = $this->_xls_stream_write([unserialize](http://br.php.net/unserialize)($this->buffer));
// ...and empty it
$this->buffer = null;
// write the xls EOF
$str = [pack](http://br.php.net/pack)([str_repeat](http://br.php.net/str_repeat)($this->bin[$this->endian], 2), 0x0A, 0x00);
$this->position += [strlen](http://br.php.net/strlen)($str);
[fwrite](http://br.php.net/fwrite)($this->fp, $str);
}
// ...and close the internal stream
return [fclose](http://br.php.net/fclose)($this->fp);
}
function stream_eof()
{
$eof = true;
if ([is_resource](http://br.php.net/is_resource)($this->fp))
{
$eof = [feof](http://br.php.net/feof)($this->fp);
}
return $eof;
}
}
stream_wrapper_register("xlsfile", "xlsStream")
or [die](http://br.php.net/die)("Failed to register protocol: xlsfile");
?>
a font disso é
http://www.phpclasses.org/browse/package/1...wnload/zip.html
se essa não te servr da uma olhada la. que derrepnte achaalguma.
blzz.
Vou dar uma olhada valeu ;)
Eu utilizei uma classe pronta pra ler um excel mas mesmo assim dá muito trabalho se você tiver como simplificar exporte em CSV separado por virgula e da um explode() no arquivo (foi a solução simples e arcaica que eu usei)