Domanda

I am using PHP Excel library. I want to show a error message to the user when user uploads an empty file for reading. I google'd for it but couldn't get relevant answer.

When a new excel file is created it has a default filesize of 9KB in windows. I cannot use filesize() to check for emptyness as suggested by some of the post here.

Is there any way using PHP Excel to check if the file is empty and return error message??

È stato utile?

Soluzione

Well, there is no direct method to tell that file is empty. You can tell that file is empty when its sheet contains no data.

You can test than in multiple ways, for example:

1) $objPHPExcel->getActiveSheet()->toArray() It will return sheet data as an array, if count = 0 - your sheet is empty.

2) $objPHPExcel->setActiveSheetIndex(0)->getHighestColumn();

and $objPHPExcel->setActiveSheetIndex(0)->getHighestRow();

If higest row = 1, and column = A - your sheet is empty.

Altri suggerimenti

In my case objPHPExcel->getActiveSheet()->toArray() - always return array count > 0. And I think in most cases count(array) will be greater than 0. And we need add more complex check.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top