Menu

[r107]: / trunk / php-java-bridge / tests.php5 / excel_antitest.php  Maximize  Restore  History

Download this file

55 lines (48 with data), 1.6 kB

 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/*
* This file is part of bench.php.
*
* Create a 200x200 excel sheet and write it to the file
* "workbook_php.xls
*
* It is called "antitest" because it shows how the PHP/Java bridge
* should _not_ be used:
*
* This test generates 40000 cells using more than n*40000 java reflection
* calls (n is ~ 3..5). The code is a) interpreted and b) calls are routed
* through the java reflection machinery and through the methods in
* JavaBridge.java.
*
* PHP code which does this will execute 10 times slower
* than native, java JIT compiled, code.
*/
function createWorkbook($name, $dx, $dy) {
$wb = new java("org.apache.poi.hssf.usermodel.HSSFWorkbook");
$sheet = $wb->createSheet("new sheet");
$row = $sheet->createRow(0);
//Aqua background
$style = $wb->createCellStyle();
$aqua = new java ('org.apache.poi.hssf.util.HSSFColor$AQUA');
$style->setFillBackgroundColor($aqua->index);
$style->setFillPattern($style->BIG_SPOTS);
$cell = $row->createCell(1);
$cell->setCellValue("X");
$cell->setCellStyle($style);
//Orange "foreground", foreground being the fill foreground not the font color.
$orange = new java ('org.apache.poi.hssf.util.HSSFColor$ORANGE');
$style->setFillForegroundColor($orange->index);
$style->setFillPattern($style->SOLID_FOREGROUND);
for ($x = 0; $x < $dx; $x++) {
$row = $sheet->createRow($x);
for ($y = 0; $y < $dy; $y++) {
$cell = $row->createCell($y);
$cell->setCellValue("$x . $y");
$cell->setCellStyle($style);
}
}
// Write the output to a file
$fileOut = new java ("java.io.FileOutputStream", $name);
$wb->write($fileOut);
$fileOut->close();
}
?>
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.