Skip to content

Commit 483a31c

Browse files
author
Saravana Kumar M
committed
Nothing Special
1 parent 39074f4 commit 483a31c

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

Excel/src/org/apache/poi/hssf/usermodel/examples/XSSFReadWrite.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22

33
import java.io.File;
44
import java.io.FileInputStream;
5+
import java.io.FileOutputStream;
56
import java.io.IOException;
67

78
import org.apache.poi.ss.usermodel.Cell;
89
import org.apache.poi.ss.usermodel.Row;
910
import org.apache.poi.ss.usermodel.WorkbookFactory;
11+
import org.apache.poi.ss.util.CellRangeAddress;
1012
import org.apache.poi.xssf.usermodel.XSSFCell;
13+
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
14+
import org.apache.poi.xssf.usermodel.XSSFFont;
15+
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
16+
import org.apache.poi.xssf.usermodel.XSSFRow;
17+
import org.apache.poi.xssf.usermodel.XSSFSheet;
1118
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
1219

1320
/**
@@ -34,7 +41,7 @@ private static XSSFWorkbook readFile(String filename) throws IOException
3441
* given a filename this outputs a sample sheet with just a set of
3542
* rows/cells.
3643
*/
37-
/*private static void testCreateSampleSheet(String outputFilename) throws IOException
44+
private static void testCreateSampleSheet(String outputFilename) throws IOException
3845
{
3946
int rownum;
4047
XSSFWorkbook wb = new XSSFWorkbook();
@@ -58,7 +65,7 @@ private static XSSFWorkbook readFile(String filename) throws IOException
5865
cs2.setFillForegroundColor((short) 0xA);
5966
cs2.setFont(f2);
6067
wb.setSheetName(0, "XSSF Test");
61-
for (rownum = 0; rownum < 300; rownum++) {
68+
for (rownum = 0; rownum < 10; rownum++) {
6269
XSSFRow r = s.createRow(rownum);
6370
if ((rownum % 2) == 0) {
6471
r.setHeight((short) 0x249);
@@ -84,26 +91,26 @@ private static XSSFWorkbook readFile(String filename) throws IOException
8491
// draw a thick black border on the row at the bottom using BLANKS
8592
rownum++;
8693
rownum++;
87-
XSSFRow r = s.createRow(rownum);
94+
/*XSSFRow r = s.createRow(rownum);
8895
cs3.setBorderBottom(XSSFCellStyle.BORDER_THICK);
8996
for (int cellnum = 0; cellnum < 50; cellnum++) {
9097
XSSFCell c = r.createCell(cellnum);
9198
c.setCellStyle(cs3);
92-
}
99+
}*/
93100
s.addMergedRegion(new CellRangeAddress(0, 3, 0, 3));
94101
s.addMergedRegion(new CellRangeAddress(100, 110, 100, 110));
95102

96103
// end draw thick black border
97104
// create a sheet, set its title then delete it
98-
s = wb.createSheet();
99-
wb.setSheetName(1, "DeletedSheet");
100-
wb.removeSheetAt(1);
105+
//s = wb.createSheet();
106+
//wb.setSheetName(1, "DeletedSheet");
107+
//wb.removeSheetAt(1);
101108

102109
// end deleted sheet
103110
FileOutputStream out = new FileOutputStream(outputFilename);
104111
wb.write(out);
105112
out.close();
106-
}*/
113+
}
107114

108115
/**
109116
* Method main
@@ -124,10 +131,13 @@ private static XSSFWorkbook readFile(String filename) throws IOException
124131
* spreadsheet, deletes rows 0-24, 74-99. Changes cell at row 39, col 3 to
125132
* "MODIFIED CELL" then writes it out. Hence this is "modify test 1". If you
126133
* take the output from the write test, you'll have a valid scenario.
134+
* @throws IOException
127135
*/
128-
public static void main(String[] args) {
136+
public static void main(String[] args) throws IOException {
129137

130-
File fileName = new File("d:\\book1.xlsx");
138+
File fileName = new File("e:\\book1.xlsx");
139+
testCreateSampleSheet("e:\\test.xlsx");
140+
System.exit(0);
131141
try {
132142
if (args.length < 2) {
133143

0 commit comments

Comments
 (0)