Bom seguinte, me pediram aqui na empresa uma página em php que carregasse um arquivo em .xls e que retirasse as linhas em branco, deixando assim o arquivo mais compacto.
Já tentei de tudo, mas não consegui se alguém que já tenha experiência nesse tipo de coisa pude me ajuda ficarei muito grato.
excelwriter.inc.php
<?php Class ExcelWriter
{
var $fp=null;
var $error;
var $state="CLOSED";
var $newRow=false;
function ExcelWriter($file="")
{
return $this->open($file);
}
function open($file)
{
if($this->state!="CLOSED")
{
$this->error="Error : Another file is opend .Close it to save the file";
return false;
}
if(!empty($file))
{
$this->fp=@fopen($file,"w+");
}
else
{
$this->error="Usage : New ExcelWriter('fileName')";
return false;
}
if($this->fp==false)
{
$this->error="Error: Unable to open/create File.You may not have permmsion to write the file.";
return false;
}
$this->state="OPENED";
fwrite($this->fp,$this->GetHeader());
return $this->fp;
}
function close()
{
if($this->state!="OPENED")
{
$this->error="Error : Please open the file.";
return false;
}
if($this->newRow)
{
fwrite($this->fp,"</tr>");
$this->newRow=false;
}
fwrite($this->fp,$this->GetFooter());
fclose($this->fp);
$this->state="CLOSED";
return;
}
function deleteRow()
{
$value=NULL;
if($this->state!="OPENED")
{
$this->error="Error : Please open the file.";
return false;
}
if($this->fp=="<td class=xl24 width=64>$value</td>"){
fwrite($this->fp,"");
}
if($this->fp=="<tr>$value</tr>"){
fwrite($this->fp,"");
}
}
}?>
Excel_TiraLinha.php(Resultado ele limpa o arquivo, e não retira apenas as linhas em branco)
Pergunta
JapZ
Bom seguinte, me pediram aqui na empresa uma página em php que carregasse um arquivo em .xls e que retirasse as linhas em branco, deixando assim o arquivo mais compacto.
Já tentei de tudo, mas não consegui se alguém que já tenha experiência nesse tipo de coisa pude me ajuda ficarei muito grato.
excelwriter.inc.php
<?php Class ExcelWriter { var $fp=null; var $error; var $state="CLOSED"; var $newRow=false; function ExcelWriter($file="") { return $this->open($file); } function open($file) { if($this->state!="CLOSED") { $this->error="Error : Another file is opend .Close it to save the file"; return false; } if(!empty($file)) { $this->fp=@fopen($file,"w+"); } else { $this->error="Usage : New ExcelWriter('fileName')"; return false; } if($this->fp==false) { $this->error="Error: Unable to open/create File.You may not have permmsion to write the file."; return false; } $this->state="OPENED"; fwrite($this->fp,$this->GetHeader()); return $this->fp; } function close() { if($this->state!="OPENED") { $this->error="Error : Please open the file."; return false; } if($this->newRow) { fwrite($this->fp,"</tr>"); $this->newRow=false; } fwrite($this->fp,$this->GetFooter()); fclose($this->fp); $this->state="CLOSED"; return; } function deleteRow() { $value=NULL; if($this->state!="OPENED") { $this->error="Error : Please open the file."; return false; } if($this->fp=="<td class=xl24 width=64>$value</td>"){ fwrite($this->fp,""); } if($this->fp=="<tr>$value</tr>"){ fwrite($this->fp,""); } } }?>Excel_TiraLinha.php(Resultado ele limpa o arquivo, e não retira apenas as linhas em branco)<?php include("excelwriter.inc.php"); $excel=new ExcelWriter("myXls.xls"); if($excel==false) echo $excel->error; $excel->deleteRow(); $excel->close(); ?>Editado por JapZLink para o comentário
Compartilhar em outros sites
1 resposta a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.