7

how to open excel file in browser ,

i dont want some thing like force download dialog ,

i want to open excel in browser somthing like in gmail when u click the excel file in the inbox, it will show browser itself,

same like , how to do in php.

5
  • 2
    You mean when it opens in Google Docs? That's an entire Excel clone for the web. Commented Oct 5, 2010 at 7:07
  • 3
    Afaik, you need extensions/addons for every browser that is supposed to open Office documents (just like you need for Adobe Reader). I am not sure how available these are in anything but IE. Commented Oct 5, 2010 at 7:26
  • well there is an online mixrosoft office solution. but i don't know how to give documents to it and then show it to someone else because it requires a Live account. the thing in gmail is a full grown solution made by google. Commented Oct 5, 2010 at 8:10
  • Do you need to actually open the file in Excel itself, allowing the user to edit cells? Or do you simply need to display data from an Excel file in a (read-only) grid? Commented Oct 5, 2010 at 8:28
  • @Bharanikumar - In that case, why not look at a library such as PHPExcel that can read your Excel file and then write out a formatted, static HTML version of those worksheets Commented Oct 5, 2010 at 8:42

1 Answer 1

10

Using PHPExcel:

include 'PHPExcel/IOFactory.php';
$inputFileType = 'Excel5';
$inputFileName = 'MyExcelFile.xls';

$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objWriter->save('php://output');
exit;

EDIT

If your Excel file is Excel 2007 (xlsx) or later rather than Excel 2003 (xls) or earlier

include 'PHPExcel/IOFactory.php';
$inputFileType = 'Excel2007';
$inputFileName = 'MyExcelFile.xlsx';

$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objWriter->save('php://output');
exit;
Sign up to request clarification or add additional context in comments.

4 Comments

am getting error Fatal error: Uncaught exception 'Exception' with message 'The filename test.xlsx is not recognised as an
@Bharanikumar - If your file is Excel 2007 (xlsx) OpenXML format, then you need to use the appropriate reader, not the Excel5 BIFF reader of my initial example... see edit.
For exact desig aspect like gmail, we should use any css or i should call any php classes (like excel grid )
@Bharanikumar - Write your own variant of the HTML Writer then, the existing code should provide the basis for what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.