Menu

[r720]: / trunk / php-java-bridge / examples / php+jsp / excel.php  Maximize  Restore  History

Download this file

24 lines (19 with data), 712 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php require_once("java/Java.inc");
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=downloaded.xls");
// create a 50x40 excel sheet and return it to the client
$workbook = new java("org.apache.poi.hssf.usermodel.HSSFWorkbook");
$sheet = $workbook->createSheet("new sheet");
for($y=0; $y<40; $y++) {
$row = $sheet->createRow($y);
for($x=0; $x<50; $x++) {
$cell = $row->createCell($x);
$cell->setCellValue("cell $x/$y");
}
}
// create and return the excel sheet to the client
$memoryStream = new java("java.io.ByteArrayOutputStream");
$workbook->write($memoryStream);
$memoryStream->close();
echo java_values($memoryStream->toByteArray());
?>