質問

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??

役に立ちましたか?

解決

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.

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top