Turn off zipping in phpexcel? - php

I am using phpexcel to create a xls file. I want to turn off zipping though. I don't have the php extension for zipping and I'd rather just send people the xlsx file unzipped. Is there a setting that would allow me to turn it off?

No. "zipping" in xlsx is not meant to provide compression and decrease file size, xlsx file is in fact zip file with proper directory structure inside and many xml files.

Related

PHPExcel Writer .xls file generates Excel error ... how can I change the extension to .csv?

I'm using a Wordpress plugin, wpdatatables, that uses PHPExcel to produce pdf, csv, and Excel file exports.
Anyway, when downloading an .xls file from my website, when I open it .. Excel gives me the error “The file format and extension of “blahblah.xls” don’t match. The file could be corrupted or unsafe. Unless you trust its source, don’t open it.”
Of course the file still opens fine, but I'd like to get rid of this error. One thing I noticed is the .CSV export is seemingly identical in all ways except the file extension, and opens without an error.
As someone who is not terribly familiar with PHP sadly, what direction should I look in to make PHPExcel produce .csv files only? Is there a specific function or directory in PHPExcel responsible for the Excel writer file output?

PHP not detecting XLS file as zip

I am using a library to read XLS files which internally uses PHP's zip_open() function. When creating the files locally and then uploading to my test server everything works fine. However, when I use the XLS files downloaded from a website (normal download via browser), it does not work, instead returning Error 19 meaning that the file is not seen as a zip file, which is incorrect. Excel opens the file without problems. If I re-save the file locally as an XLSX file and then upload it, I get the same error (in this instance the file is opened by the PHP's ZipArchive class). Any ideas what the reason could be? I checked that the files are not read only, possibly some Unix permissions could be set that are not displayed in Windows? (Doubt this, as the error code indicates that the file could be accessed, but could not be identified as XLS)
Using:
Apache under Windows (WAMP)
PHP 5.4.12
It seems I had misread a line of code, the zip check is only done to determine if the XLS file is an incorrectly named XLSX file. The problem with the XLS file is that it returns no sheets when parsing, I need to look into this still. I do not know why saving the XLS file as an XLSX file (using Excel) results in an incorrect ZIP archive though, but guessing it is related.

ZendService\LiveDocx returns zip file instead of docx

I'm using the ZendService\LiveDocx library, but when I run this on our stage server (Linux) and request the format to be docx, it returns me back a zip file rather than the actual document. The zip file consists of XML files describing the document. If I request the format to be PDF it works fine. This works fine in my local development environment (Windows 7) when I try to generate a docx document.
Any ideas why the LiveDocx service would return a zip file instead of the actual document?
The zip file consists of XML files describing the document.
That's how .docx files work.
A .docx in fact is a zip file, so you can simply rename them according to your needs.
You can try this by taking a "good looking" docx file and rename it to .zip, then extract.
The solution for your problem is to rename the file from .zip to .docx before exposing to the user as a download.

Force opening and reading zip files from php

This may be a simple question or a pretty complex one, ill let you be the deciders.
Using PHP To open a zip file, extract the files to a directory and close the zip file is not a complicated class to make.
But lets say that the file is not a zip, but yet is able to be read by WinRar, examples of these files are like exe's SFX archives etc.
What factors do all these files have in conmen to allow WinRar to browse the source of them.
Another example is Anti Virus Software, that individually scan files within an EXE ?
So what an example:
$handle = fopen("an_unknown_file.abc", "rb");
while (!feof($handle))
{
//What generic code could I use to determain weather the file can be extracted ?
}
fclose($handle);
Regards.
Zip's specifications allow the actual "zip" file portion to be embedded ANYWHERE within a file. It doesn't necessarily have to start at position '0' in the file. This is how self-extracting zips work. It's a small .exe stub program which has a larger .zip file appended to the end of it.
Finding a zip is mostly a matter of scanning for a zip file's "magic number" within a file, then doing a few heuristics to determine if it's really a zip file, or just something random that happens to contain a zip's magic number.
A .docx file is really just a .zip that contains various XML files representing a Word file's contents. Just like a .jar is a zip file that contains various different chunks of Java code.
Winrar's got a bunch of extra code within it to scan through a file and look for any identifiable "this is a compress archive" type signatures, one of which happens to be that of a zip file's.
There's nothing too magical about it. It's just a matter of scanning through a file and looking for signatures.
Not sure what exactly is your question, but I think you are confusing something here... File extension can be described as just a convenient way for humans and computers to relate file extensions to the type of the file/programs that work with them. WinRar (or any other program) reads what the file contains and if it can understand it - it works with it. The only important thing is that the file format (data in the file) is valid and that the program you are using can work with this file format.
So, if a file is in any format that WinRar can work with (.rar, .zip, .gz, etc.), it's extension could be .txt or .whatever and WinRar will still be able to work with it. Extension is just for convenience.

PHP: Zipping files as xlsx causes file to become invalid

I have to replace variables inside a user-submitted xlsx file and am doing it this way:
Rename the .xlsx to .zip
Unzip to a temp-folder
Make the necessary changes
Zip the files
Rename the .zip to .xslx
I am using plain ZipArchive in PHP. When I try to open the generated .xlsx in Excel, it fails with a message format or extension invalid. When I compress the temporary files with WinRAR (as zip), and rename the resulting file to .xlsx, it works. The zip files generated with both methods contain the same data structure and files, but the WinRAR file is slightly bigger (10.2K vs. 10.3K with normal compression).
When viewing the garbled code of the files, I could see that the files appear in a different order, but don't know if that's the cause. Any clue would be greatly appreciated.
I got it to work with another component, PclZip (phpconcept.net/pclzip). It is a class that apparently uses gzip, and renaming it's outputs to .xlsx are fine with Excel 2007.

Categories