IOFActory loaded filetype

Topics: User Forum
Mar 21, 2010 at 5:12 PM

Hello,

 

Is there a way i can get file type when using automagic IOFactory file type judging?

I want to set read options for different file types, e.g. if file is CSV,  then set delimiter property,

if it's excel, set readDataOnly and so on.

Thanks.

 

Coordinator
Mar 22, 2010 at 10:40 PM

Not directly, though using the file extension might be an option.

You can check by instantiating each reader in turn, and then calling the canRead() method for the class. Unset each instance that returns a false before testing the next, otherwise it might be a bit costly in terms of memory.

Mar 22, 2010 at 11:36 PM

Hi,

 

Thanks for your reply.

 

Is there any sense of feature request for reader to return  file type, or for loader to accept only those parameters that are accepted by reader?

 

Sorry for offtopic, Is there any faster way to tell number of rows & cells ?

It takes me nearly same time to output highest row & col and draw a table with file contents using examples provided in manual.

 

Thanks.

Coordinator
Mar 23, 2010 at 12:59 AM
ArZ wrote:

Is there any sense of feature request for reader to return  file type, or for loader to accept only those parameters that are accepted by reader?

If you believe that it would be a useful feature, there's no harm in raising it as a request.
It would be a lot easier for the IOFactory to detect the filetype (it's doing that already, though there's no built-in mechanism to retrieve the filetype detected) than to accept only those parameters that are accepted by reader

ArZ wrote:

Sorry for offtopic, Is there any faster way to tell number of rows & cells ?

It takes me nearly same time to output highest row & col and draw a table with file contents using examples provided in manual.

$PHPExcelObject->getActiveSheet()->getHighestColumn() and $PHPExcelObject->getActiveSheet()->getHighestRow() might be what you're looking for.

Developer
Mar 26, 2010 at 8:01 AM

We also have the createReaderForFile( ) method:

$file = 'file.ext';

$reader = PHPExcel_IOFactory::createReaderForFile($file);
switch (get_class($reader)) {
case PHPExcel_Reader_CSV;
$reader->setInputEncoding('CP1252');
$reader->setDelimiter(';');
...
break;
default:
break;
}