You haven't described what you have tried so far, so here's just two links to good libraries for generating those files via php: Excel: http://phpexcel.codeplex.com/ MSWord: http://phpword.codeplex.com/
Read More Information on Excel: http://phpexcel.codeplex.com/ MSWord: http://phpword.codeplex.com/
You can get your answer ,for exporting data into those files using php, in detail from following links . Excel: http://phpexcel.codeplex.com MSWord: http://phpword.codeplex.com