A: 

From where comes that html ? it's not from the code above.

Cesar
A: 

It looks like whatever would happen if $_POST['Submit'] != 'generateexcel' happens anyway - somewhere before the code you've posted. You'll need to do an if-else to make sure that the normal html display code doesn't also run.

Scott Saunders