Menu

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

Download this file

27 lines (22 with data), 844 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php require_once("java/Java.inc");
java_autoload();
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 org_apache_poi_hssf_usermodel_HSSFWorkbook();
$sheet = $workbook->createSheet("new sheet");
java_begin_document(); // send the following as a streamed XML document
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");
}
}
java_end_document(); // back to "normal" protocol mode
// create and return the excel sheet to the client
$memoryStream = new java_io_ByteArrayOutputStream();
$workbook->write($memoryStream);
$memoryStream->close();
echo java_values($memoryStream->toByteArray());
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.