forked from micw/php-java-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExcelTest.java
More file actions
55 lines (48 loc) · 1.5 KB
/
Copy pathExcelTest.java
File metadata and controls
55 lines (48 loc) · 1.5 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
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.*;
/*
* Used by bench.php
*
* Create a excel sheet and write it to the file "workbook.xls
*/
public class ExcelTest {
public static void main(String s[]) {
try {
createWorkbook("workbook.xls", 100, 100);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void createWorkbook(String name, int dx, int dy) throws Exception {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow(0);
//Aqua background
HSSFCellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(HSSFColor.AQUA.index);
style.setFillPattern(style.BIG_SPOTS);
HSSFCell cell = row.createCell((short)1);
cell.setCellValue("X");
cell.setCellStyle(style);
// Orange "foreground", foreground being the fill foreground not the font color.
style.setFillForegroundColor(HSSFColor.ORANGE.index);
style.setFillPattern(style.SOLID_FOREGROUND);
for (int x = 0; x < dx; x++) {
// Create a row and put some cells in it. Rows are 0 based.
row = sheet.createRow(x);
for (int y = 0; y < dy; y++) {
cell = row.createCell((short)y);
cell.setCellValue(String.valueOf(x) + " . " + String.valueOf(y));
cell.setCellStyle(style);
}
}
// Write the output to a file
try {
java.io.FileOutputStream fileOut = new java.io.FileOutputStream(name);
wb.write(fileOut);
fileOut.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}