M
M
Mr. Abdu Jan2013-12-20 06:59:42
PHP
Mr. Abdu Jan, 2013-12-20 06:59:42

How to open excel file in browser?

Hello,
There is a card.xlsx file . I open it with PHPExcel and add data to certain cells.

/** PHPExcel */
include ('classes/PHPExcel.php');
/** PHPExcel_Writer_Excel2007 */
include ('classes/PHPExcel/Writer/Excel2007.php');
include ('classes/PHPExcel/IOFactory.php');

// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

$objPHPExcel = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objPHPExcel->load("card.xlsx");
$objPHPExcel->setActiveSheetIndex(0);

// Add some data
$objPHPExcel->setActiveSheetIndex(0);

$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'world!');
$objPHPExcel->getActiveSheet()->SetCellValue('A2', 'Hello');
$objPHPExcel->getActiveSheet()->SetCellValue('D1', 'world!');

// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle('Simple');

// Save Excel 2007 file
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save(time().".xlsx");

Now you need to give this file to the user, open it in the browser. I think it is done using the header() function .
Does anyone know how this is done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2013-12-20
@Abdukhafiz

header('Location: /'.time().".xlsx");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question