Fixed deprecated references to HSSFSheet.getRow(short) etc. Removed all deprecated warnings from hssf.usermodel.examples.*
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@740179 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4f24467f20
commit
d7c95a10c8
@ -29,27 +29,23 @@ import java.io.IOException;
|
|||||||
*
|
*
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public class Alignment
|
public class Alignment {
|
||||||
{
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet("new sheet");
|
HSSFSheet sheet = wb.createSheet("new sheet");
|
||||||
HSSFRow row = sheet.createRow((short) 2);
|
HSSFRow row = sheet.createRow(2);
|
||||||
createCell(wb, row, (short) 0, HSSFCellStyle.ALIGN_CENTER);
|
createCell(wb, row, 0, HSSFCellStyle.ALIGN_CENTER);
|
||||||
createCell(wb, row, (short) 1, HSSFCellStyle.ALIGN_CENTER_SELECTION);
|
createCell(wb, row, 1, HSSFCellStyle.ALIGN_CENTER_SELECTION);
|
||||||
createCell(wb, row, (short) 2, HSSFCellStyle.ALIGN_FILL);
|
createCell(wb, row, 2, HSSFCellStyle.ALIGN_FILL);
|
||||||
createCell(wb, row, (short) 3, HSSFCellStyle.ALIGN_GENERAL);
|
createCell(wb, row, 3, HSSFCellStyle.ALIGN_GENERAL);
|
||||||
createCell(wb, row, (short) 4, HSSFCellStyle.ALIGN_JUSTIFY);
|
createCell(wb, row, 4, HSSFCellStyle.ALIGN_JUSTIFY);
|
||||||
createCell(wb, row, (short) 5, HSSFCellStyle.ALIGN_LEFT);
|
createCell(wb, row, 5, HSSFCellStyle.ALIGN_LEFT);
|
||||||
createCell(wb, row, (short) 6, HSSFCellStyle.ALIGN_RIGHT);
|
createCell(wb, row, 6, HSSFCellStyle.ALIGN_RIGHT);
|
||||||
|
|
||||||
// Write the output to a file
|
// Write the output to a file
|
||||||
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,12 +56,11 @@ public class Alignment
|
|||||||
* @param column the column number to create the cell in
|
* @param column the column number to create the cell in
|
||||||
* @param align the alignment for the cell.
|
* @param align the alignment for the cell.
|
||||||
*/
|
*/
|
||||||
private static void createCell(HSSFWorkbook wb, HSSFRow row, short column, short align)
|
private static void createCell(HSSFWorkbook wb, HSSFRow row, int column, int align) {
|
||||||
{
|
|
||||||
HSSFCell cell = row.createCell(column);
|
HSSFCell cell = row.createCell(column);
|
||||||
cell.setCellValue("Align It");
|
cell.setCellValue("Align It");
|
||||||
HSSFCellStyle cellStyle = wb.createCellStyle();
|
HSSFCellStyle cellStyle = wb.createCellStyle();
|
||||||
cellStyle.setAlignment(align);
|
cellStyle.setAlignment((short)align);
|
||||||
cell.setCellStyle(cellStyle);
|
cell.setCellStyle(cellStyle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,7 +15,6 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel.examples;
|
package org.apache.poi.hssf.usermodel.examples;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.*;
|
import org.apache.poi.hssf.usermodel.*;
|
||||||
@ -31,12 +29,9 @@ import java.io.IOException;
|
|||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
* @author Andrew Oliver (acoliver at apache.org)
|
* @author Andrew Oliver (acoliver at apache.org)
|
||||||
*/
|
*/
|
||||||
public class BigExample
|
public class BigExample {
|
||||||
{
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args)
|
int rownum;
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
short rownum;
|
|
||||||
|
|
||||||
// create a new file
|
// create a new file
|
||||||
FileOutputStream out = new FileOutputStream("workbook.xls");
|
FileOutputStream out = new FileOutputStream("workbook.xls");
|
||||||
@ -59,7 +54,7 @@ public class BigExample
|
|||||||
//set font 1 to 12 point type
|
//set font 1 to 12 point type
|
||||||
f.setFontHeightInPoints((short) 12);
|
f.setFontHeightInPoints((short) 12);
|
||||||
//make it red
|
//make it red
|
||||||
f.setColor((short) HSSFColor.RED.index);
|
f.setColor(HSSFColor.RED.index);
|
||||||
// make it bold
|
// make it bold
|
||||||
//arial is the default font
|
//arial is the default font
|
||||||
f.setBoldweight(f.BOLDWEIGHT_BOLD);
|
f.setBoldweight(f.BOLDWEIGHT_BOLD);
|
||||||
@ -67,7 +62,7 @@ public class BigExample
|
|||||||
//set font 2 to 10 point type
|
//set font 2 to 10 point type
|
||||||
f2.setFontHeightInPoints((short) 10);
|
f2.setFontHeightInPoints((short) 10);
|
||||||
//make it the color at palette index 0xf (white)
|
//make it the color at palette index 0xf (white)
|
||||||
f2.setColor((short) HSSFColor.WHITE.index);
|
f2.setColor(HSSFColor.WHITE.index);
|
||||||
//make it bold
|
//make it bold
|
||||||
f2.setBoldweight(f2.BOLDWEIGHT_BOLD);
|
f2.setBoldweight(f2.BOLDWEIGHT_BOLD);
|
||||||
|
|
||||||
@ -79,9 +74,9 @@ public class BigExample
|
|||||||
//set a thin border
|
//set a thin border
|
||||||
cs2.setBorderBottom(cs2.BORDER_THIN);
|
cs2.setBorderBottom(cs2.BORDER_THIN);
|
||||||
//fill w fg fill color
|
//fill w fg fill color
|
||||||
cs2.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
|
cs2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
|
||||||
// set foreground fill to red
|
// set foreground fill to red
|
||||||
cs2.setFillForegroundColor((short) HSSFColor.RED.index);
|
cs2.setFillForegroundColor(HSSFColor.RED.index);
|
||||||
|
|
||||||
// set the font
|
// set the font
|
||||||
cs2.setFont(f2);
|
cs2.setFont(f2);
|
||||||
@ -89,7 +84,7 @@ public class BigExample
|
|||||||
// set the sheet name to HSSF Test
|
// set the sheet name to HSSF Test
|
||||||
wb.setSheetName(0, "HSSF Test");
|
wb.setSheetName(0, "HSSF Test");
|
||||||
// create a sheet with 300 rows (0-299)
|
// create a sheet with 300 rows (0-299)
|
||||||
for (rownum = (short) 0; rownum < 300; rownum++)
|
for (rownum = 0; rownum < 300; rownum++)
|
||||||
{
|
{
|
||||||
// create a row
|
// create a row
|
||||||
r = s.createRow(rownum);
|
r = s.createRow(rownum);
|
||||||
@ -102,7 +97,7 @@ public class BigExample
|
|||||||
|
|
||||||
//r.setRowNum(( short ) rownum);
|
//r.setRowNum(( short ) rownum);
|
||||||
// create 50 cells (0-49) (the += 2 becomes apparent later
|
// create 50 cells (0-49) (the += 2 becomes apparent later
|
||||||
for (short cellnum = (short) 0; cellnum < 50; cellnum += 2)
|
for (int cellnum = 0; cellnum < 50; cellnum += 2)
|
||||||
{
|
{
|
||||||
// create a numeric cell
|
// create a numeric cell
|
||||||
c = r.createCell(cellnum);
|
c = r.createCell(cellnum);
|
||||||
@ -119,12 +114,12 @@ public class BigExample
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create a string cell (see why += 2 in the
|
// create a string cell (see why += 2 in the
|
||||||
c = r.createCell((short) (cellnum + 1));
|
c = r.createCell(cellnum + 1);
|
||||||
|
|
||||||
// set the cell's string value to "TEST"
|
// set the cell's string value to "TEST"
|
||||||
c.setCellValue("TEST");
|
c.setCellValue("TEST");
|
||||||
// make this column a bit wider
|
// make this column a bit wider
|
||||||
s.setColumnWidth((short) (cellnum + 1), (short) ((50 * 8) / ((double) 1 / 20)));
|
s.setColumnWidth(cellnum + 1, (int)((50 * 8) / ((double) 1 / 20)));
|
||||||
|
|
||||||
// on every other row
|
// on every other row
|
||||||
if ((rownum % 2) == 0)
|
if ((rownum % 2) == 0)
|
||||||
@ -149,8 +144,7 @@ public class BigExample
|
|||||||
cs3.setBorderBottom(cs3.BORDER_THICK);
|
cs3.setBorderBottom(cs3.BORDER_THICK);
|
||||||
|
|
||||||
//create 50 cells
|
//create 50 cells
|
||||||
for (short cellnum = (short) 0; cellnum < 50; cellnum++)
|
for (int cellnum =0; cellnum < 50; cellnum++) {
|
||||||
{
|
|
||||||
//create a blank type cell (no value)
|
//create a blank type cell (no value)
|
||||||
c = r.createCell(cellnum);
|
c = r.createCell(cellnum);
|
||||||
// set it to the thick black border style
|
// set it to the thick black border style
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,7 +15,6 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel.examples;
|
package org.apache.poi.hssf.usermodel.examples;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.*;
|
import org.apache.poi.hssf.usermodel.*;
|
||||||
@ -30,19 +28,16 @@ import java.io.IOException;
|
|||||||
*
|
*
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public class Borders
|
public class Borders {
|
||||||
{
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet("new sheet");
|
HSSFSheet sheet = wb.createSheet("new sheet");
|
||||||
|
|
||||||
// Create a row and put some cells in it. Rows are 0 based.
|
// Create a row and put some cells in it. Rows are 0 based.
|
||||||
HSSFRow row = sheet.createRow((short) 1);
|
HSSFRow row = sheet.createRow(1);
|
||||||
|
|
||||||
// Create a cell and put a value in it.
|
// Create a cell and put a value in it.
|
||||||
HSSFCell cell = row.createCell((short) 1);
|
HSSFCell cell = row.createCell(1);
|
||||||
cell.setCellValue(4);
|
cell.setCellValue(4);
|
||||||
|
|
||||||
// Style the cell with borders all around.
|
// Style the cell with borders all around.
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel.examples;
|
package org.apache.poi.hssf.usermodel.examples;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.*;
|
import org.apache.poi.hssf.usermodel.*;
|
||||||
@ -42,7 +43,7 @@ public class CellComments {
|
|||||||
HSSFPatriarch patr = sheet.createDrawingPatriarch();
|
HSSFPatriarch patr = sheet.createDrawingPatriarch();
|
||||||
|
|
||||||
//create a cell in row 3
|
//create a cell in row 3
|
||||||
HSSFCell cell1 = sheet.createRow(3).createCell((short)1);
|
HSSFCell cell1 = sheet.createRow(3).createCell(1);
|
||||||
cell1.setCellValue(new HSSFRichTextString("Hello, World"));
|
cell1.setCellValue(new HSSFRichTextString("Hello, World"));
|
||||||
|
|
||||||
//anchor defines size and position of the comment in worksheet
|
//anchor defines size and position of the comment in worksheet
|
||||||
@ -59,7 +60,7 @@ public class CellComments {
|
|||||||
cell1.setCellComment(comment1);
|
cell1.setCellComment(comment1);
|
||||||
|
|
||||||
//create another cell in row 6
|
//create another cell in row 6
|
||||||
HSSFCell cell2 = sheet.createRow(6).createCell((short)1);
|
HSSFCell cell2 = sheet.createRow(6).createCell(1);
|
||||||
cell2.setCellValue(36.6);
|
cell2.setCellValue(36.6);
|
||||||
|
|
||||||
|
|
||||||
@ -85,7 +86,7 @@ public class CellComments {
|
|||||||
/**
|
/**
|
||||||
* The second way to assign comment to a cell is to implicitly specify its row and column.
|
* The second way to assign comment to a cell is to implicitly specify its row and column.
|
||||||
* Note, it is possible to set row and column of a non-existing cell.
|
* Note, it is possible to set row and column of a non-existing cell.
|
||||||
* It works, the commnet is visible.
|
* It works, the comment is visible.
|
||||||
*/
|
*/
|
||||||
comment2.setRow(6);
|
comment2.setRow(6);
|
||||||
comment2.setColumn((short)1);
|
comment2.setColumn((short)1);
|
||||||
@ -93,7 +94,5 @@ public class CellComments {
|
|||||||
FileOutputStream out = new FileOutputStream("poi_comment.xls");
|
FileOutputStream out = new FileOutputStream("poi_comment.xls");
|
||||||
wb.write(out);
|
wb.write(out);
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,7 +15,6 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel.examples;
|
package org.apache.poi.hssf.usermodel.examples;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||||
@ -28,19 +26,16 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class CellTypes
|
public class CellTypes {
|
||||||
{
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet("new sheet");
|
HSSFSheet sheet = wb.createSheet("new sheet");
|
||||||
HSSFRow row = sheet.createRow((short)2);
|
HSSFRow row = sheet.createRow(2);
|
||||||
row.createCell((short) 0).setCellValue(1.1);
|
row.createCell(0).setCellValue(1.1);
|
||||||
row.createCell((short) 1).setCellValue(new Date());
|
row.createCell(1).setCellValue(new Date());
|
||||||
row.createCell((short) 2).setCellValue("a string");
|
row.createCell(2).setCellValue("a string");
|
||||||
row.createCell((short) 3).setCellValue(true);
|
row.createCell(3).setCellValue(true);
|
||||||
row.createCell((short) 4).setCellType(HSSFCell.CELL_TYPE_ERROR);
|
row.createCell(4).setCellType(HSSFCell.CELL_TYPE_ERROR);
|
||||||
|
|
||||||
// Write the output to a file
|
// Write the output to a file
|
||||||
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,7 +15,6 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel.examples;
|
package org.apache.poi.hssf.usermodel.examples;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
@ -32,24 +30,21 @@ import java.io.IOException;
|
|||||||
*
|
*
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public class CreateCells
|
public class CreateCells {
|
||||||
{
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet("new sheet");
|
HSSFSheet sheet = wb.createSheet("new sheet");
|
||||||
|
|
||||||
// Create a row and put some cells in it. Rows are 0 based.
|
// Create a row and put some cells in it. Rows are 0 based.
|
||||||
HSSFRow row = sheet.createRow((short)0);
|
HSSFRow row = sheet.createRow(0);
|
||||||
// Create a cell and put a value in it.
|
// Create a cell and put a value in it.
|
||||||
HSSFCell cell = row.createCell((short)0);
|
HSSFCell cell = row.createCell(0);
|
||||||
cell.setCellValue(1);
|
cell.setCellValue(1);
|
||||||
|
|
||||||
// Or do it on one line.
|
// Or do it on one line.
|
||||||
row.createCell((short)1).setCellValue(1.2);
|
row.createCell(1).setCellValue(1.2);
|
||||||
row.createCell((short)2).setCellValue("This is a string");
|
row.createCell(2).setCellValue("This is a string");
|
||||||
row.createCell((short)3).setCellValue(true);
|
row.createCell(3).setCellValue(true);
|
||||||
|
|
||||||
// Write the output to a file
|
// Write the output to a file
|
||||||
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,7 +15,6 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel.examples;
|
package org.apache.poi.hssf.usermodel.examples;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.*;
|
import org.apache.poi.hssf.usermodel.*;
|
||||||
@ -32,26 +30,23 @@ import java.util.Date;
|
|||||||
*
|
*
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public class CreateDateCells
|
public class CreateDateCells {
|
||||||
{
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet("new sheet");
|
HSSFSheet sheet = wb.createSheet("new sheet");
|
||||||
|
|
||||||
// Create a row and put some cells in it. Rows are 0 based.
|
// Create a row and put some cells in it. Rows are 0 based.
|
||||||
HSSFRow row = sheet.createRow((short)0);
|
HSSFRow row = sheet.createRow(0);
|
||||||
|
|
||||||
// Create a cell and put a date value in it. The first cell is not styled as a date.
|
// Create a cell and put a date value in it. The first cell is not styled as a date.
|
||||||
HSSFCell cell = row.createCell((short)0);
|
HSSFCell cell = row.createCell(0);
|
||||||
cell.setCellValue(new Date());
|
cell.setCellValue(new Date());
|
||||||
|
|
||||||
// we style the second cell as a date (and time). It is important to create a new cell style from the workbook
|
// we style the second cell as a date (and time). It is important to create a new cell style from the workbook
|
||||||
// otherwise you can end up modifying the built in style and effecting not only this cell but other cells.
|
// otherwise you can end up modifying the built in style and effecting not only this cell but other cells.
|
||||||
HSSFCellStyle cellStyle = wb.createCellStyle();
|
HSSFCellStyle cellStyle = wb.createCellStyle();
|
||||||
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
|
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
|
||||||
cell = row.createCell((short)1);
|
cell = row.createCell(1);
|
||||||
cell.setCellValue(new Date());
|
cell.setCellValue(new Date());
|
||||||
cell.setCellStyle(cellStyle);
|
cell.setCellStyle(cellStyle);
|
||||||
|
|
||||||
@ -59,6 +54,5 @@ public class CreateDateCells
|
|||||||
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,7 +15,6 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel.examples;
|
package org.apache.poi.hssf.usermodel.examples;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.*;
|
import org.apache.poi.hssf.usermodel.*;
|
||||||
@ -30,22 +28,19 @@ import java.io.IOException;
|
|||||||
*
|
*
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public class FrillsAndFills
|
public class FrillsAndFills {
|
||||||
{
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet("new sheet");
|
HSSFSheet sheet = wb.createSheet("new sheet");
|
||||||
|
|
||||||
// Create a row and put some cells in it. Rows are 0 based.
|
// Create a row and put some cells in it. Rows are 0 based.
|
||||||
HSSFRow row = sheet.createRow((short) 1);
|
HSSFRow row = sheet.createRow(1);
|
||||||
|
|
||||||
// Aqua background
|
// Aqua background
|
||||||
HSSFCellStyle style = wb.createCellStyle();
|
HSSFCellStyle style = wb.createCellStyle();
|
||||||
style.setFillBackgroundColor(HSSFColor.AQUA.index);
|
style.setFillBackgroundColor(HSSFColor.AQUA.index);
|
||||||
style.setFillPattern(HSSFCellStyle.BIG_SPOTS);
|
style.setFillPattern(HSSFCellStyle.BIG_SPOTS);
|
||||||
HSSFCell cell = row.createCell((short) 1);
|
HSSFCell cell = row.createCell(1);
|
||||||
cell.setCellValue("X");
|
cell.setCellValue("X");
|
||||||
cell.setCellStyle(style);
|
cell.setCellStyle(style);
|
||||||
|
|
||||||
@ -53,7 +48,7 @@ public class FrillsAndFills
|
|||||||
style = wb.createCellStyle();
|
style = wb.createCellStyle();
|
||||||
style.setFillForegroundColor(HSSFColor.ORANGE.index);
|
style.setFillForegroundColor(HSSFColor.ORANGE.index);
|
||||||
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
|
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
|
||||||
cell = row.createCell((short) 2);
|
cell = row.createCell(2);
|
||||||
cell.setCellValue("X");
|
cell.setCellValue("X");
|
||||||
cell.setCellStyle(style);
|
cell.setCellStyle(style);
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,7 +15,6 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel.examples;
|
package org.apache.poi.hssf.usermodel.examples;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.*;
|
import org.apache.poi.hssf.usermodel.*;
|
||||||
@ -25,28 +23,22 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if hyperlink formula, with url that got more than 127 charaters, works
|
* Test if hyperlink formula, with url that got more than 127 characters, works
|
||||||
*
|
*
|
||||||
* @author Bernard Chesnoy
|
* @author Bernard Chesnoy
|
||||||
*/
|
*/
|
||||||
public class HyperlinkFormula
|
public class HyperlinkFormula {
|
||||||
{
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFCell cell;
|
|
||||||
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet("new sheet");
|
HSSFSheet sheet = wb.createSheet("new sheet");
|
||||||
HSSFRow row = sheet.createRow((short) 0);
|
HSSFRow row = sheet.createRow(0);
|
||||||
|
|
||||||
cell = row.createCell((short)0);
|
HSSFCell cell = row.createCell(0);
|
||||||
cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
|
cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
|
||||||
cell.setCellFormula("HYPERLINK(\"http://127.0.0.1:8080/toto/truc/index.html?test=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"test\")");
|
cell.setCellFormula("HYPERLINK(\"http://127.0.0.1:8080/toto/truc/index.html?test=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"test\")");
|
||||||
|
|
||||||
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -35,7 +34,7 @@ public class Hyperlinks {
|
|||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
|
|
||||||
//cell style for hyperlinks
|
//cell style for hyperlinks
|
||||||
//by default hypelrinks are blue and underlined
|
//by default hyperlinks are blue and underlined
|
||||||
HSSFCellStyle hlink_style = wb.createCellStyle();
|
HSSFCellStyle hlink_style = wb.createCellStyle();
|
||||||
HSSFFont hlink_font = wb.createFont();
|
HSSFFont hlink_font = wb.createFont();
|
||||||
hlink_font.setUnderline(HSSFFont.U_SINGLE);
|
hlink_font.setUnderline(HSSFFont.U_SINGLE);
|
||||||
@ -46,7 +45,7 @@ public class Hyperlinks {
|
|||||||
HSSFSheet sheet = wb.createSheet("Hyperlinks");
|
HSSFSheet sheet = wb.createSheet("Hyperlinks");
|
||||||
|
|
||||||
//URL
|
//URL
|
||||||
cell = sheet.createRow(0).createCell((short)0);
|
cell = sheet.createRow(0).createCell(0);
|
||||||
cell.setCellValue("URL Link");
|
cell.setCellValue("URL Link");
|
||||||
HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
|
HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
|
||||||
link.setAddress("http://poi.apache.org/");
|
link.setAddress("http://poi.apache.org/");
|
||||||
@ -54,7 +53,7 @@ public class Hyperlinks {
|
|||||||
cell.setCellStyle(hlink_style);
|
cell.setCellStyle(hlink_style);
|
||||||
|
|
||||||
//link to a file in the current directory
|
//link to a file in the current directory
|
||||||
cell = sheet.createRow(1).createCell((short)0);
|
cell = sheet.createRow(1).createCell(0);
|
||||||
cell.setCellValue("File Link");
|
cell.setCellValue("File Link");
|
||||||
link = new HSSFHyperlink(HSSFHyperlink.LINK_FILE);
|
link = new HSSFHyperlink(HSSFHyperlink.LINK_FILE);
|
||||||
link.setAddress("link1.xls");
|
link.setAddress("link1.xls");
|
||||||
@ -62,7 +61,7 @@ public class Hyperlinks {
|
|||||||
cell.setCellStyle(hlink_style);
|
cell.setCellStyle(hlink_style);
|
||||||
|
|
||||||
//e-mail link
|
//e-mail link
|
||||||
cell = sheet.createRow(2).createCell((short)0);
|
cell = sheet.createRow(2).createCell(0);
|
||||||
cell.setCellValue("Email Link");
|
cell.setCellValue("Email Link");
|
||||||
link = new HSSFHyperlink(HSSFHyperlink.LINK_EMAIL);
|
link = new HSSFHyperlink(HSSFHyperlink.LINK_EMAIL);
|
||||||
//note, if subject contains white spaces, make sure they are url-encoded
|
//note, if subject contains white spaces, make sure they are url-encoded
|
||||||
@ -74,9 +73,9 @@ public class Hyperlinks {
|
|||||||
|
|
||||||
//create a target sheet and cell
|
//create a target sheet and cell
|
||||||
HSSFSheet sheet2 = wb.createSheet("Target Sheet");
|
HSSFSheet sheet2 = wb.createSheet("Target Sheet");
|
||||||
sheet2.createRow(0).createCell((short)0).setCellValue("Target Cell");
|
sheet2.createRow(0).createCell(0).setCellValue("Target Cell");
|
||||||
|
|
||||||
cell = sheet.createRow(3).createCell((short)0);
|
cell = sheet.createRow(3).createCell(0);
|
||||||
cell.setCellValue("Worksheet Link");
|
cell.setCellValue("Worksheet Link");
|
||||||
link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
|
link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
|
||||||
link.setAddress("'Target Sheet'!A1");
|
link.setAddress("'Target Sheet'!A1");
|
||||||
@ -86,6 +85,5 @@ public class Hyperlinks {
|
|||||||
FileOutputStream out = new FileOutputStream("hssf-links.xls");
|
FileOutputStream out = new FileOutputStream("hssf-links.xls");
|
||||||
wb.write(out);
|
wb.write(out);
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,11 +15,10 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel.examples;
|
package org.apache.poi.hssf.usermodel.examples;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.*;
|
import org.apache.poi.hssf.usermodel.*;
|
||||||
import org.apache.poi.ss.util.Region;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -30,24 +28,20 @@ import java.io.FileOutputStream;
|
|||||||
*
|
*
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public class MergedCells
|
public class MergedCells {
|
||||||
{
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet("new sheet");
|
HSSFSheet sheet = wb.createSheet("new sheet");
|
||||||
|
|
||||||
HSSFRow row = sheet.createRow((short) 1);
|
HSSFRow row = sheet.createRow(1);
|
||||||
HSSFCell cell = row.createCell((short) 1);
|
HSSFCell cell = row.createCell(1);
|
||||||
cell.setCellValue("This is a test of merging");
|
cell.setCellValue("This is a test of merging");
|
||||||
|
|
||||||
sheet.addMergedRegion(new Region(1,(short)1,1,(short)2));
|
sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 2));
|
||||||
|
|
||||||
// Write the output to a file
|
// Write the output to a file
|
||||||
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,7 +15,6 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel.examples;
|
package org.apache.poi.hssf.usermodel.examples;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.*;
|
import org.apache.poi.hssf.usermodel.*;
|
||||||
@ -30,36 +28,32 @@ import java.io.IOException;
|
|||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
* @author Fauzia Lala <fauzia.lala at wcom.com>
|
* @author Fauzia Lala <fauzia.lala at wcom.com>
|
||||||
*/
|
*/
|
||||||
public class NewLinesInCells
|
public class NewLinesInCells {
|
||||||
{
|
public static void main( String[] args ) throws IOException {
|
||||||
public static void main( String[] args ) throws IOException
|
|
||||||
{
|
|
||||||
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet s = wb.createSheet();
|
HSSFSheet s = wb.createSheet();
|
||||||
HSSFRow r = null;
|
HSSFRow r = null;
|
||||||
HSSFCell c = null;
|
HSSFCell c = null;
|
||||||
HSSFCellStyle cs = wb.createCellStyle();
|
HSSFCellStyle cs = wb.createCellStyle();
|
||||||
HSSFFont f = wb.createFont();
|
|
||||||
HSSFFont f2 = wb.createFont();
|
HSSFFont f2 = wb.createFont();
|
||||||
|
|
||||||
cs = wb.createCellStyle();
|
cs = wb.createCellStyle();
|
||||||
|
|
||||||
cs.setFont( f2 );
|
cs.setFont(f2);
|
||||||
//Word Wrap MUST be turned on
|
// Word Wrap MUST be turned on
|
||||||
cs.setWrapText( true );
|
cs.setWrapText(true);
|
||||||
|
|
||||||
r = s.createRow( (short) 2 );
|
r = s.createRow(2);
|
||||||
r.setHeight( (short) 0x349 );
|
r.setHeight((short) 0x349);
|
||||||
c = r.createCell( (short) 2 );
|
c = r.createCell(2);
|
||||||
c.setCellType( HSSFCell.CELL_TYPE_STRING );
|
c.setCellType(HSSFCell.CELL_TYPE_STRING);
|
||||||
c.setCellValue( "Use \n with word wrap on to create a new line" );
|
c.setCellValue("Use \n with word wrap on to create a new line");
|
||||||
c.setCellStyle( cs );
|
c.setCellStyle(cs);
|
||||||
s.setColumnWidth( (short) 2, (short) ( ( 50 * 8 ) / ( (double) 1 / 20 ) ) );
|
s.setColumnWidth(2, (int) ((50 * 8) / ((double) 1 / 20)));
|
||||||
|
|
||||||
FileOutputStream fileOut = new FileOutputStream( "workbook.xls" );
|
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
||||||
wb.write( fileOut );
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,7 +15,6 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel.examples;
|
package org.apache.poi.hssf.usermodel.examples;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
@ -30,14 +28,12 @@ import java.io.FileOutputStream;
|
|||||||
*
|
*
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public class NewSheet
|
public class NewSheet {
|
||||||
{
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||||
HSSFSheet sheet2 = wb.createSheet("second sheet");
|
HSSFSheet sheet2 = wb.createSheet(); // create with default name
|
||||||
|
wb.setSheetName(1, "second sheet"); // setting sheet name later
|
||||||
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -27,11 +26,8 @@ import java.io.*;
|
|||||||
*
|
*
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public class OfficeDrawing
|
public class OfficeDrawing {
|
||||||
{
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
// Create the workbook and sheets.
|
// Create the workbook and sheets.
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||||
@ -58,8 +54,8 @@ public class OfficeDrawing
|
|||||||
// Create a row and size one of the cells reasonably large.
|
// Create a row and size one of the cells reasonably large.
|
||||||
HSSFRow row = sheet1.createRow(2);
|
HSSFRow row = sheet1.createRow(2);
|
||||||
row.setHeight((short) 2800);
|
row.setHeight((short) 2800);
|
||||||
row.createCell( (short)1 );
|
row.createCell(1);
|
||||||
sheet1.setColumnWidth((short) 2, (short) 9000);
|
sheet1.setColumnWidth(2, 9000);
|
||||||
|
|
||||||
// Create the drawing patriarch. This is the top level container for
|
// Create the drawing patriarch. This is the top level container for
|
||||||
// all shapes.
|
// all shapes.
|
||||||
@ -80,9 +76,9 @@ public class OfficeDrawing
|
|||||||
{
|
{
|
||||||
// Create a row and size one of the cells reasonably large.
|
// Create a row and size one of the cells reasonably large.
|
||||||
HSSFRow row = sheet2.createRow(2);
|
HSSFRow row = sheet2.createRow(2);
|
||||||
row.createCell( (short)1 );
|
row.createCell(1);
|
||||||
row.setHeightInPoints(240);
|
row.setHeightInPoints(240);
|
||||||
sheet2.setColumnWidth((short) 2, (short) 9000);
|
sheet2.setColumnWidth(2, 9000);
|
||||||
|
|
||||||
// Create the drawing patriarch. This is the top level container for
|
// Create the drawing patriarch. This is the top level container for
|
||||||
// all shapes. This will clear out any existing shapes for that sheet.
|
// all shapes. This will clear out any existing shapes for that sheet.
|
||||||
@ -97,8 +93,8 @@ public class OfficeDrawing
|
|||||||
// Create a row and size one of the cells reasonably large
|
// Create a row and size one of the cells reasonably large
|
||||||
HSSFRow row = sheet3.createRow(2);
|
HSSFRow row = sheet3.createRow(2);
|
||||||
row.setHeightInPoints(140);
|
row.setHeightInPoints(140);
|
||||||
row.createCell( (short)1 );
|
row.createCell(1);
|
||||||
sheet3.setColumnWidth((short) 2, (short) 9000);
|
sheet3.setColumnWidth(2, 9000);
|
||||||
|
|
||||||
// Create the drawing patriarch. This is the top level container for
|
// Create the drawing patriarch. This is the top level container for
|
||||||
// all shapes. This will clear out any existing shapes for that sheet.
|
// all shapes. This will clear out any existing shapes for that sheet.
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -29,15 +28,13 @@ import java.io.IOException;
|
|||||||
*
|
*
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public class OfficeDrawingWithGraphics
|
public class OfficeDrawingWithGraphics {
|
||||||
{
|
public static void main( String[] args ) throws IOException {
|
||||||
public static void main( String[] args ) throws IOException
|
|
||||||
{
|
|
||||||
// Create a workbook with one sheet and size the first three somewhat
|
// Create a workbook with one sheet and size the first three somewhat
|
||||||
// larger so we can fit the chemical structure diagram in.
|
// larger so we can fit the chemical structure diagram in.
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet( "my drawing" );
|
HSSFSheet sheet = wb.createSheet( "my drawing" );
|
||||||
sheet.setColumnWidth((short)1, (short)(256 * 27));
|
sheet.setColumnWidth(1, 256 * 27);
|
||||||
HSSFRow row1 = sheet.createRow(0);
|
HSSFRow row1 = sheet.createRow(0);
|
||||||
row1.setHeightInPoints(10 * 15);
|
row1.setHeightInPoints(10 * 15);
|
||||||
HSSFRow row2 = sheet.createRow(1);
|
HSSFRow row2 = sheet.createRow(1);
|
||||||
@ -47,9 +44,9 @@ public class OfficeDrawingWithGraphics
|
|||||||
|
|
||||||
// Add some cells so we can test that the anchoring works when we
|
// Add some cells so we can test that the anchoring works when we
|
||||||
// sort them.
|
// sort them.
|
||||||
row1.createCell((short)0).setCellValue("C");
|
row1.createCell(0).setCellValue("C");
|
||||||
row2.createCell((short)0).setCellValue("A");
|
row2.createCell(0).setCellValue("A");
|
||||||
row3.createCell((short)0).setCellValue("B");
|
row3.createCell(0).setCellValue("B");
|
||||||
|
|
||||||
// Create the top level drawing patriarch.
|
// Create the top level drawing patriarch.
|
||||||
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
|
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
|
||||||
@ -62,7 +59,7 @@ public class OfficeDrawingWithGraphics
|
|||||||
a = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 1, 0, (short) 1, 0 );
|
a = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 1, 0, (short) 1, 0 );
|
||||||
group = patriarch.createGroup( a );
|
group = patriarch.createGroup( a );
|
||||||
group.setCoordinates( 0, 0, 320, 276 );
|
group.setCoordinates( 0, 0, 320, 276 );
|
||||||
float verticalPointsPerPixel = a.getAnchorHeightInPoints(sheet) / (float)Math.abs(group.getY2() - group.getY1());
|
float verticalPointsPerPixel = a.getAnchorHeightInPoints(sheet) / Math.abs(group.getY2() - group.getY1());
|
||||||
g = new EscherGraphics( group, wb, Color.black, verticalPointsPerPixel );
|
g = new EscherGraphics( group, wb, Color.black, verticalPointsPerPixel );
|
||||||
g2d = new EscherGraphics2d( g );
|
g2d = new EscherGraphics2d( g );
|
||||||
drawStar( g2d );
|
drawStar( g2d );
|
||||||
@ -70,7 +67,7 @@ public class OfficeDrawingWithGraphics
|
|||||||
a = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 1, 1, (short) 1, 1 );
|
a = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 1, 1, (short) 1, 1 );
|
||||||
group = patriarch.createGroup( a );
|
group = patriarch.createGroup( a );
|
||||||
group.setCoordinates( 0, 0, 640, 276 );
|
group.setCoordinates( 0, 0, 640, 276 );
|
||||||
verticalPointsPerPixel = a.getAnchorHeightInPoints(sheet) / (float)Math.abs(group.getY2() - group.getY1());
|
verticalPointsPerPixel = a.getAnchorHeightInPoints(sheet) / Math.abs(group.getY2() - group.getY1());
|
||||||
// verticalPixelsPerPoint = (float)Math.abs(group.getY2() - group.getY1()) / a.getAnchorHeightInPoints(sheet);
|
// verticalPixelsPerPoint = (float)Math.abs(group.getY2() - group.getY1()) / a.getAnchorHeightInPoints(sheet);
|
||||||
g = new EscherGraphics( group, wb, Color.black, verticalPointsPerPixel );
|
g = new EscherGraphics( group, wb, Color.black, verticalPointsPerPixel );
|
||||||
g2d = new EscherGraphics2d( g );
|
g2d = new EscherGraphics2d( g );
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,7 +15,6 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel.examples;
|
package org.apache.poi.hssf.usermodel.examples;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||||
@ -32,13 +30,8 @@ import java.io.IOException;
|
|||||||
*
|
*
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public class Outlines
|
public class Outlines {
|
||||||
{
|
public static void main(String[] args) throws IOException {
|
||||||
private Outlines(){}
|
|
||||||
|
|
||||||
public static void main(String[] args)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
createCase1( "outline1.xls" );
|
createCase1( "outline1.xls" );
|
||||||
System.out.println( "outline1.xls written. Two expanded groups." );
|
System.out.println( "outline1.xls written. Two expanded groups." );
|
||||||
createCase2( "outline2.xls" );
|
createCase2( "outline2.xls" );
|
||||||
@ -67,19 +60,17 @@ public class Outlines
|
|||||||
System.out.println( "outline13.xls written. Mixed bag." );
|
System.out.println( "outline13.xls written. Mixed bag." );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createCase1( String filename ) throws IOException{
|
private static void createCase1(String filename) throws IOException {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||||
|
|
||||||
sheet1.groupColumn( (short)4, (short)7 );
|
sheet1.groupColumn(4, 7);
|
||||||
|
|
||||||
for (int row = 0; row < 200; row++)
|
for (int row = 0; row < 200; row++) {
|
||||||
{
|
HSSFRow r = sheet1.createRow(row);
|
||||||
HSSFRow r = sheet1.createRow( row );
|
for (int column = 0; column < 200; column++) {
|
||||||
for (int column = 0; column < 200; column++)
|
HSSFCell c = r.createCell(column);
|
||||||
{
|
c.setCellValue(column);
|
||||||
HSSFCell c = r.createCell( (short) column );
|
|
||||||
c.setCellValue( column );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,198 +79,181 @@ public class Outlines
|
|||||||
fileOut.close();
|
fileOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createCase2( String filename ) throws IOException{
|
private static void createCase2(String filename) throws IOException {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||||
|
|
||||||
sheet1.groupColumn( (short)2, (short)10 );
|
sheet1.groupColumn(2, 10);
|
||||||
sheet1.groupColumn( (short)4, (short)7 );
|
sheet1.groupColumn(4, 7);
|
||||||
sheet1.setColumnGroupCollapsed( (short)4, true );
|
sheet1.setColumnGroupCollapsed(4, true);
|
||||||
|
|
||||||
FileOutputStream fileOut = new FileOutputStream(filename);
|
FileOutputStream fileOut = new FileOutputStream(filename);
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createCase3( String filename ) throws IOException{
|
private static void createCase3(String filename) throws IOException {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||||
|
|
||||||
sheet1.groupColumn( (short)2, (short)10 );
|
sheet1.groupColumn(2, 10);
|
||||||
sheet1.groupColumn( (short)4, (short)7 );
|
sheet1.groupColumn(4, 7);
|
||||||
sheet1.setColumnGroupCollapsed( (short)4, true );
|
sheet1.setColumnGroupCollapsed(4, true);
|
||||||
sheet1.setColumnGroupCollapsed( (short)2, true );
|
sheet1.setColumnGroupCollapsed(2, true);
|
||||||
|
|
||||||
FileOutputStream fileOut = new FileOutputStream(filename);
|
FileOutputStream fileOut = new FileOutputStream(filename);
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createCase4( String filename ) throws IOException{
|
private static void createCase4(String filename) throws IOException {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||||
|
|
||||||
sheet1.groupColumn( (short)2, (short)10 );
|
sheet1.groupColumn(2, 10);
|
||||||
sheet1.groupColumn( (short)4, (short)7 );
|
sheet1.groupColumn(4, 7);
|
||||||
sheet1.setColumnGroupCollapsed( (short)4, true );
|
sheet1.setColumnGroupCollapsed(4, true);
|
||||||
sheet1.setColumnGroupCollapsed( (short)2, true );
|
sheet1.setColumnGroupCollapsed(2, true);
|
||||||
|
|
||||||
sheet1.setColumnGroupCollapsed( (short)4, false );
|
sheet1.setColumnGroupCollapsed(4, false);
|
||||||
|
|
||||||
FileOutputStream fileOut = new FileOutputStream(filename);
|
FileOutputStream fileOut = new FileOutputStream(filename);
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createCase5( String filename ) throws IOException{
|
private static void createCase5(String filename) throws IOException {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||||
|
|
||||||
sheet1.groupColumn( (short)2, (short)10 );
|
sheet1.groupColumn(2, 10);
|
||||||
sheet1.groupColumn( (short)4, (short)7 );
|
sheet1.groupColumn(4, 7);
|
||||||
sheet1.setColumnGroupCollapsed( (short)4, true );
|
sheet1.setColumnGroupCollapsed(4, true);
|
||||||
sheet1.setColumnGroupCollapsed( (short)2, true );
|
sheet1.setColumnGroupCollapsed(2, true);
|
||||||
|
|
||||||
sheet1.setColumnGroupCollapsed( (short)4, false );
|
sheet1.setColumnGroupCollapsed(4, false);
|
||||||
sheet1.setColumnGroupCollapsed( (short)3, false );
|
sheet1.setColumnGroupCollapsed(3, false);
|
||||||
|
|
||||||
FileOutputStream fileOut = new FileOutputStream(filename);
|
FileOutputStream fileOut = new FileOutputStream(filename);
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createCase6( String filename ) throws IOException{
|
private static void createCase6(String filename) throws IOException {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||||
|
|
||||||
sheet1.groupColumn( (short)2, (short)10 );
|
sheet1.groupColumn(2, 10);
|
||||||
sheet1.groupColumn( (short)4, (short)10 );
|
sheet1.groupColumn(4, 10);
|
||||||
sheet1.setColumnGroupCollapsed( (short)4, true );
|
sheet1.setColumnGroupCollapsed(4, true);
|
||||||
sheet1.setColumnGroupCollapsed( (short)2, true );
|
sheet1.setColumnGroupCollapsed(2, true);
|
||||||
|
|
||||||
sheet1.setColumnGroupCollapsed( (short)3, false );
|
sheet1.setColumnGroupCollapsed(3, false);
|
||||||
|
|
||||||
FileOutputStream fileOut = new FileOutputStream(filename);
|
FileOutputStream fileOut = new FileOutputStream(filename);
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createCase7( String filename )
|
private static void createCase7(String filename) throws IOException {
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||||
|
|
||||||
sheet1.groupRow( 5, 14 );
|
sheet1.groupRow(5, 14);
|
||||||
sheet1.groupRow( 7, 10 );
|
sheet1.groupRow(7, 10);
|
||||||
|
|
||||||
FileOutputStream fileOut = new FileOutputStream(filename);
|
FileOutputStream fileOut = new FileOutputStream(filename);
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createCase8( String filename )
|
private static void createCase8(String filename) throws IOException {
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||||
|
|
||||||
sheet1.groupRow( 5, 14 );
|
sheet1.groupRow(5, 14);
|
||||||
sheet1.groupRow( 7, 10 );
|
sheet1.groupRow(7, 10);
|
||||||
sheet1.setRowGroupCollapsed( 7, true );
|
sheet1.setRowGroupCollapsed(7, true);
|
||||||
|
|
||||||
FileOutputStream fileOut = new FileOutputStream(filename);
|
FileOutputStream fileOut = new FileOutputStream(filename);
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createCase9( String filename )
|
private static void createCase9(String filename) throws IOException {
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||||
|
|
||||||
sheet1.groupRow( 5, 14 );
|
sheet1.groupRow(5, 14);
|
||||||
sheet1.groupRow( 7, 10 );
|
sheet1.groupRow(7, 10);
|
||||||
sheet1.setRowGroupCollapsed( 7, true );
|
sheet1.setRowGroupCollapsed(7, true);
|
||||||
sheet1.setRowGroupCollapsed( 5, true );
|
sheet1.setRowGroupCollapsed(5, true);
|
||||||
|
|
||||||
FileOutputStream fileOut = new FileOutputStream(filename);
|
FileOutputStream fileOut = new FileOutputStream(filename);
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void createCase10(String filename) throws IOException {
|
||||||
private static void createCase10( String filename )
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||||
|
|
||||||
sheet1.groupRow( 5, 14 );
|
sheet1.groupRow(5, 14);
|
||||||
sheet1.groupRow( 7, 10 );
|
sheet1.groupRow(7, 10);
|
||||||
sheet1.setRowGroupCollapsed( 7, true );
|
sheet1.setRowGroupCollapsed(7, true);
|
||||||
sheet1.setRowGroupCollapsed( 5, true );
|
sheet1.setRowGroupCollapsed(5, true);
|
||||||
sheet1.setRowGroupCollapsed( 8, false );
|
sheet1.setRowGroupCollapsed(8, false);
|
||||||
|
|
||||||
FileOutputStream fileOut = new FileOutputStream(filename);
|
FileOutputStream fileOut = new FileOutputStream(filename);
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createCase11( String filename )
|
private static void createCase11(String filename) throws IOException {
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||||
|
|
||||||
sheet1.groupRow( 5, 14 );
|
sheet1.groupRow(5, 14);
|
||||||
sheet1.groupRow( 7, 10 );
|
sheet1.groupRow(7, 10);
|
||||||
sheet1.setRowGroupCollapsed( 7, true );
|
sheet1.setRowGroupCollapsed(7, true);
|
||||||
sheet1.setRowGroupCollapsed( 5, true );
|
sheet1.setRowGroupCollapsed(5, true);
|
||||||
sheet1.setRowGroupCollapsed( 8, false );
|
sheet1.setRowGroupCollapsed(8, false);
|
||||||
sheet1.setRowGroupCollapsed( 14, false );
|
sheet1.setRowGroupCollapsed(14, false);
|
||||||
|
|
||||||
FileOutputStream fileOut = new FileOutputStream(filename);
|
FileOutputStream fileOut = new FileOutputStream(filename);
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createCase12( String filename )
|
private static void createCase12(String filename) throws IOException {
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||||
|
|
||||||
sheet1.groupRow( 5, 14 );
|
sheet1.groupRow(5, 14);
|
||||||
sheet1.groupRow( 7, 14 );
|
sheet1.groupRow(7, 14);
|
||||||
sheet1.setRowGroupCollapsed( 7, true );
|
sheet1.setRowGroupCollapsed(7, true);
|
||||||
sheet1.setRowGroupCollapsed( 5, true );
|
sheet1.setRowGroupCollapsed(5, true);
|
||||||
sheet1.setRowGroupCollapsed( 6, false );
|
sheet1.setRowGroupCollapsed(6, false);
|
||||||
|
|
||||||
FileOutputStream fileOut = new FileOutputStream(filename);
|
FileOutputStream fileOut = new FileOutputStream(filename);
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createCase13( String filename )
|
private static void createCase13(String filename) throws IOException {
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||||
|
|
||||||
sheet1.groupRow( 5, 14 );
|
sheet1.groupRow(5, 14);
|
||||||
sheet1.groupRow( 7, 14 );
|
sheet1.groupRow(7, 14);
|
||||||
sheet1.groupRow( 16, 19 );
|
sheet1.groupRow(16, 19);
|
||||||
|
|
||||||
sheet1.groupColumn( (short)4, (short)7 );
|
sheet1.groupColumn(4, 7);
|
||||||
sheet1.groupColumn( (short)9, (short)12 );
|
sheet1.groupColumn(9, 12);
|
||||||
sheet1.groupColumn( (short)10, (short)11 );
|
sheet1.groupColumn(10, 11);
|
||||||
|
|
||||||
FileOutputStream fileOut = new FileOutputStream(filename);
|
FileOutputStream fileOut = new FileOutputStream(filename);
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,7 +15,6 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel.examples;
|
package org.apache.poi.hssf.usermodel.examples;
|
||||||
|
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
@ -35,11 +33,8 @@ import java.io.IOException;
|
|||||||
*
|
*
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public class ReadWriteWorkbook
|
public class ReadWriteWorkbook {
|
||||||
{
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
FileInputStream fileIn = null;
|
FileInputStream fileIn = null;
|
||||||
FileOutputStream fileOut = null;
|
FileOutputStream fileOut = null;
|
||||||
|
|
||||||
@ -52,18 +47,16 @@ public class ReadWriteWorkbook
|
|||||||
HSSFRow row = sheet.getRow(2);
|
HSSFRow row = sheet.getRow(2);
|
||||||
if (row == null)
|
if (row == null)
|
||||||
row = sheet.createRow(2);
|
row = sheet.createRow(2);
|
||||||
HSSFCell cell = row.getCell((short)3);
|
HSSFCell cell = row.getCell(3);
|
||||||
if (cell == null)
|
if (cell == null)
|
||||||
cell = row.createCell((short)3);
|
cell = row.createCell(3);
|
||||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
||||||
cell.setCellValue("a test");
|
cell.setCellValue("a test");
|
||||||
|
|
||||||
// Write the output to a file
|
// Write the output to a file
|
||||||
fileOut = new FileOutputStream("workbookout.xls");
|
fileOut = new FileOutputStream("workbookout.xls");
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
}
|
} finally {
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (fileOut != null)
|
if (fileOut != null)
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
if (fileIn != null)
|
if (fileIn != null)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,33 +15,22 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel.examples;
|
package org.apache.poi.hssf.usermodel.examples;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.*;
|
import org.apache.poi.hssf.usermodel.*;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public class RepeatingRowsAndColumns
|
public class RepeatingRowsAndColumns {
|
||||||
{
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet("first sheet");
|
HSSFSheet sheet1 = wb.createSheet("first sheet");
|
||||||
HSSFSheet sheet2 = wb.createSheet("second sheet");
|
wb.createSheet("second sheet");
|
||||||
HSSFSheet sheet3 = wb.createSheet("third sheet");
|
wb.createSheet("third sheet");
|
||||||
|
|
||||||
// POIFSFileSystem fs =
|
|
||||||
// new POIFSFileSystem(new FileInputStream("workbook.xls"));
|
|
||||||
// HSSFWorkbook wb = new HSSFWorkbook(fs);
|
|
||||||
// HSSFSheet sheet1 = wb.getSheetAt(0);
|
|
||||||
|
|
||||||
HSSFFont boldFont = wb.createFont();
|
HSSFFont boldFont = wb.createFont();
|
||||||
boldFont.setFontHeightInPoints((short)22);
|
boldFont.setFontHeightInPoints((short)22);
|
||||||
@ -51,8 +39,8 @@ public class RepeatingRowsAndColumns
|
|||||||
HSSFCellStyle boldStyle = wb.createCellStyle();
|
HSSFCellStyle boldStyle = wb.createCellStyle();
|
||||||
boldStyle.setFont(boldFont);
|
boldStyle.setFont(boldFont);
|
||||||
|
|
||||||
HSSFRow row = sheet1.createRow((short)1);
|
HSSFRow row = sheet1.createRow(1);
|
||||||
HSSFCell cell = row.createCell((short)0);
|
HSSFCell cell = row.createCell(0);
|
||||||
cell.setCellValue("This quick brown fox");
|
cell.setCellValue("This quick brown fox");
|
||||||
cell.setCellStyle(boldStyle);
|
cell.setCellStyle(boldStyle);
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,7 +15,6 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel.examples;
|
package org.apache.poi.hssf.usermodel.examples;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.*;
|
import org.apache.poi.hssf.usermodel.*;
|
||||||
@ -29,16 +27,13 @@ import java.io.IOException;
|
|||||||
*
|
*
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public class WorkingWithFonts
|
public class WorkingWithFonts {
|
||||||
{
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = wb.createSheet("new sheet");
|
HSSFSheet sheet = wb.createSheet("new sheet");
|
||||||
|
|
||||||
// Create a row and put some cells in it. Rows are 0 based.
|
// Create a row and put some cells in it. Rows are 0 based.
|
||||||
HSSFRow row = sheet.createRow((short) 1);
|
HSSFRow row = sheet.createRow(1);
|
||||||
|
|
||||||
// Create a new font and alter it.
|
// Create a new font and alter it.
|
||||||
HSSFFont font = wb.createFont();
|
HSSFFont font = wb.createFont();
|
||||||
@ -52,7 +47,7 @@ public class WorkingWithFonts
|
|||||||
style.setFont(font);
|
style.setFont(font);
|
||||||
|
|
||||||
// Create a cell and put a value in it.
|
// Create a cell and put a value in it.
|
||||||
HSSFCell cell = row.createCell((short) 1);
|
HSSFCell cell = row.createCell(1);
|
||||||
cell.setCellValue("This is a test of fonts");
|
cell.setCellValue("This is a test of fonts");
|
||||||
cell.setCellStyle(style);
|
cell.setCellStyle(style);
|
||||||
|
|
||||||
@ -60,6 +55,5 @@ public class WorkingWithFonts
|
|||||||
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,9 +45,9 @@ import org.apache.poi.ss.util.Region;
|
|||||||
|
|
||||||
public class HSSF
|
public class HSSF
|
||||||
{
|
{
|
||||||
private String filename = null;
|
private String _filename = null;
|
||||||
|
|
||||||
protected HSSFWorkbook hssfworkbook = null;
|
protected HSSFWorkbook _hssfworkbook = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor HSSF - creates an HSSFStream from an InputStream. The HSSFStream
|
* Constructor HSSF - creates an HSSFStream from an InputStream. The HSSFStream
|
||||||
@ -60,16 +60,9 @@ public class HSSF
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public HSSF(String filename)
|
public HSSF(String filename) throws IOException {
|
||||||
throws IOException
|
_filename = filename;
|
||||||
{
|
_hssfworkbook = new HSSFWorkbook(new FileInputStream(filename));
|
||||||
this.filename = filename;
|
|
||||||
POIFSFileSystem fs =
|
|
||||||
new POIFSFileSystem(new FileInputStream(filename));
|
|
||||||
|
|
||||||
hssfworkbook = new HSSFWorkbook(fs);
|
|
||||||
|
|
||||||
// records = RecordFactory.createRecords(stream);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,7 +80,7 @@ public class HSSF
|
|||||||
public HSSF(String filename, boolean write)
|
public HSSF(String filename, boolean write)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
short rownum = 0;
|
int rownum = 0;
|
||||||
FileOutputStream out = new FileOutputStream(filename);
|
FileOutputStream out = new FileOutputStream(filename);
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet s = wb.createSheet();
|
HSSFSheet s = wb.createSheet();
|
||||||
@ -112,7 +105,7 @@ public class HSSF
|
|||||||
cs2.setFillForegroundColor(( short ) 0xA);
|
cs2.setFillForegroundColor(( short ) 0xA);
|
||||||
cs2.setFont(f2);
|
cs2.setFont(f2);
|
||||||
wb.setSheetName(0, "HSSF Test");
|
wb.setSheetName(0, "HSSF Test");
|
||||||
for (rownum = ( short ) 0; rownum < 300; rownum++)
|
for (rownum = 0; rownum < 300; rownum++)
|
||||||
{
|
{
|
||||||
r = s.createRow(rownum);
|
r = s.createRow(rownum);
|
||||||
if ((rownum % 2) == 0)
|
if ((rownum % 2) == 0)
|
||||||
@ -121,7 +114,7 @@ public class HSSF
|
|||||||
}
|
}
|
||||||
|
|
||||||
// r.setRowNum(( short ) rownum);
|
// r.setRowNum(( short ) rownum);
|
||||||
for (short cellnum = ( short ) 0; cellnum < 50; cellnum += 2)
|
for (int cellnum = 0; cellnum < 50; cellnum += 2)
|
||||||
{
|
{
|
||||||
c = r.createCell(cellnum, HSSFCell.CELL_TYPE_NUMERIC);
|
c = r.createCell(cellnum, HSSFCell.CELL_TYPE_NUMERIC);
|
||||||
c.setCellValue(rownum * 10000 + cellnum
|
c.setCellValue(rownum * 10000 + cellnum
|
||||||
@ -147,7 +140,7 @@ public class HSSF
|
|||||||
rownum++;
|
rownum++;
|
||||||
r = s.createRow(rownum);
|
r = s.createRow(rownum);
|
||||||
cs3.setBorderBottom(HSSFCellStyle.BORDER_THICK);
|
cs3.setBorderBottom(HSSFCellStyle.BORDER_THICK);
|
||||||
for (short cellnum = ( short ) 0; cellnum < 50; cellnum++)
|
for (int cellnum = 0; cellnum < 50; cellnum++)
|
||||||
{
|
{
|
||||||
c = r.createCell(cellnum, HSSFCell.CELL_TYPE_BLANK);
|
c = r.createCell(cellnum, HSSFCell.CELL_TYPE_BLANK);
|
||||||
|
|
||||||
@ -183,11 +176,11 @@ public class HSSF
|
|||||||
public HSSF(String infile, String outfile, boolean write)
|
public HSSF(String infile, String outfile, boolean write)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
this.filename = infile;
|
_filename = infile;
|
||||||
POIFSFileSystem fs =
|
POIFSFileSystem fs =
|
||||||
new POIFSFileSystem(new FileInputStream(filename));
|
new POIFSFileSystem(new FileInputStream(_filename));
|
||||||
|
|
||||||
hssfworkbook = new HSSFWorkbook(fs);
|
_hssfworkbook = new HSSFWorkbook(fs);
|
||||||
|
|
||||||
// HSSFWorkbook book = hssfstream.getWorkbook();
|
// HSSFWorkbook book = hssfstream.getWorkbook();
|
||||||
}
|
}
|
||||||
@ -226,7 +219,7 @@ public class HSSF
|
|||||||
HSSF hssf = new HSSF(args[ 0 ]);
|
HSSF hssf = new HSSF(args[ 0 ]);
|
||||||
|
|
||||||
System.out.println("Data dump:\n");
|
System.out.println("Data dump:\n");
|
||||||
HSSFWorkbook wb = hssf.hssfworkbook;
|
HSSFWorkbook wb = hssf._hssfworkbook;
|
||||||
|
|
||||||
for (int k = 0; k < wb.getNumberOfSheets(); k++)
|
for (int k = 0; k < wb.getNumberOfSheets(); k++)
|
||||||
{
|
{
|
||||||
@ -238,11 +231,12 @@ public class HSSF
|
|||||||
for (int r = 0; r < rows; r++)
|
for (int r = 0; r < rows; r++)
|
||||||
{
|
{
|
||||||
HSSFRow row = sheet.getRow(r);
|
HSSFRow row = sheet.getRow(r);
|
||||||
int cells = (row != null) ? row.getPhysicalNumberOfCells() : 0;
|
if (row == null) {
|
||||||
if (row != null) {
|
continue;
|
||||||
|
}
|
||||||
|
int cells = row.getPhysicalNumberOfCells();
|
||||||
System.out.println("\nROW " + row.getRowNum()
|
System.out.println("\nROW " + row.getRowNum()
|
||||||
+ " has " + cells + " cell(s).");
|
+ " has " + cells + " cell(s).");
|
||||||
}
|
|
||||||
for (int c = 0; c < cells; c++)
|
for (int c = 0; c < cells; c++)
|
||||||
{
|
{
|
||||||
HSSFCell cell = row.getCell(c);
|
HSSFCell cell = row.getCell(c);
|
||||||
@ -269,7 +263,7 @@ public class HSSF
|
|||||||
default :
|
default :
|
||||||
}
|
}
|
||||||
System.out.println("CELL col="
|
System.out.println("CELL col="
|
||||||
+ cell.getCellNum()
|
+ cell.getColumnIndex()
|
||||||
+ " VALUE=" + value);
|
+ " VALUE=" + value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,7 +301,7 @@ public class HSSF
|
|||||||
HSSF hssf = new HSSF(args[ 0 ]);
|
HSSF hssf = new HSSF(args[ 0 ]);
|
||||||
|
|
||||||
// HSSFStream hssfstream = hssf.hssfstream;
|
// HSSFStream hssfstream = hssf.hssfstream;
|
||||||
HSSFWorkbook wb = hssf.hssfworkbook;
|
HSSFWorkbook wb = hssf._hssfworkbook;
|
||||||
FileOutputStream stream = new FileOutputStream(args[ 1 ]);
|
FileOutputStream stream = new FileOutputStream(args[ 1 ]);
|
||||||
|
|
||||||
// HSSFCell cell = new HSSFCell();
|
// HSSFCell cell = new HSSFCell();
|
||||||
@ -332,7 +326,7 @@ public class HSSF
|
|||||||
HSSF hssf = new HSSF(args[ 0 ]);
|
HSSF hssf = new HSSF(args[ 0 ]);
|
||||||
|
|
||||||
// HSSFStream hssfstream = hssf.hssfstream;
|
// HSSFStream hssfstream = hssf.hssfstream;
|
||||||
HSSFWorkbook wb = hssf.hssfworkbook;
|
HSSFWorkbook wb = hssf._hssfworkbook;
|
||||||
FileOutputStream stream = new FileOutputStream(args[ 1 ]);
|
FileOutputStream stream = new FileOutputStream(args[ 1 ]);
|
||||||
HSSFSheet sheet = wb.getSheetAt(0);
|
HSSFSheet sheet = wb.getSheetAt(0);
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,19 +15,15 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* TestCellStyle.java
|
|
||||||
*
|
|
||||||
* Created on December 11, 2001, 5:51 PM
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import java.util.*;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import junit.framework.*;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.util.TempFile;
|
import org.apache.poi.util.TempFile;
|
||||||
@ -39,20 +34,12 @@ import org.apache.poi.util.TempFile;
|
|||||||
* @author Andrew C. Oliver
|
* @author Andrew C. Oliver
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class TestCellStyle
|
public final class TestCellStyle extends TestCase {
|
||||||
extends TestCase
|
|
||||||
{
|
|
||||||
|
|
||||||
private static HSSFWorkbook openSample(String sampleFileName) {
|
private static HSSFWorkbook openSample(String sampleFileName) {
|
||||||
return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
|
return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates a new instance of TestCellStyle */
|
|
||||||
|
|
||||||
public TestCellStyle(String name)
|
|
||||||
{
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TEST NAME: Test Write Sheet Font <P>
|
* TEST NAME: Test Write Sheet Font <P>
|
||||||
@ -63,10 +50,7 @@ public class TestCellStyle
|
|||||||
* HSSFSheet last row or first row is incorrect. <P>
|
* HSSFSheet last row or first row is incorrect. <P>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
public void testWriteSheetFont() throws IOException{
|
||||||
public void testWriteSheetFont()
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
File file = TempFile.createTempFile("testWriteSheetFont",
|
File file = TempFile.createTempFile("testWriteSheetFont",
|
||||||
".xls");
|
".xls");
|
||||||
FileOutputStream out = new FileOutputStream(file);
|
FileOutputStream out = new FileOutputStream(file);
|
||||||
@ -80,13 +64,10 @@ public class TestCellStyle
|
|||||||
fnt.setColor(HSSFFont.COLOR_RED);
|
fnt.setColor(HSSFFont.COLOR_RED);
|
||||||
fnt.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
|
fnt.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
|
||||||
cs.setFont(fnt);
|
cs.setFont(fnt);
|
||||||
for (short rownum = ( short ) 0; rownum < 100; rownum++)
|
for (int rownum = 0; rownum < 100; rownum++) {
|
||||||
{
|
|
||||||
r = s.createRow(rownum);
|
r = s.createRow(rownum);
|
||||||
|
|
||||||
// r.setRowNum(( short ) rownum);
|
for (int cellnum = 0; cellnum < 50; cellnum += 2) {
|
||||||
for (short cellnum = ( short ) 0; cellnum < 50; cellnum += 2)
|
|
||||||
{
|
|
||||||
c = r.createCell(cellnum);
|
c = r.createCell(cellnum);
|
||||||
c.setCellValue(rownum * 10000 + cellnum
|
c.setCellValue(rownum * 10000 + cellnum
|
||||||
+ ((( double ) rownum / 1000)
|
+ ((( double ) rownum / 1000)
|
||||||
@ -109,9 +90,7 @@ public class TestCellStyle
|
|||||||
/**
|
/**
|
||||||
* Tests that is creating a file with a date or an calendar works correctly.
|
* Tests that is creating a file with a date or an calendar works correctly.
|
||||||
*/
|
*/
|
||||||
public void testDataStyle()
|
public void testDataStyle() throws IOException {
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
File file = TempFile.createTempFile("testWriteSheetStyleDate",
|
File file = TempFile.createTempFile("testWriteSheetStyleDate",
|
||||||
".xls");
|
".xls");
|
||||||
FileOutputStream out = new FileOutputStream(file);
|
FileOutputStream out = new FileOutputStream(file);
|
||||||
@ -141,7 +120,6 @@ public class TestCellStyle
|
|||||||
|
|
||||||
assertEquals("LAST ROW ", 0, s.getLastRowNum());
|
assertEquals("LAST ROW ", 0, s.getLastRowNum());
|
||||||
assertEquals("FIRST ROW ", 0, s.getFirstRowNum());
|
assertEquals("FIRST ROW ", 0, s.getFirstRowNum());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHashEquals() {
|
public void testHashEquals() {
|
||||||
@ -183,10 +161,7 @@ public class TestCellStyle
|
|||||||
* HSSFSheet last row or first row is incorrect. <P>
|
* HSSFSheet last row or first row is incorrect. <P>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
public void testWriteSheetStyle() throws IOException {
|
||||||
public void testWriteSheetStyle()
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
File file = TempFile.createTempFile("testWriteSheetStyle",
|
File file = TempFile.createTempFile("testWriteSheetStyle",
|
||||||
".xls");
|
".xls");
|
||||||
FileOutputStream out = new FileOutputStream(file);
|
FileOutputStream out = new FileOutputStream(file);
|
||||||
@ -209,13 +184,10 @@ public class TestCellStyle
|
|||||||
cs2.setFillForegroundColor(( short ) 0x0);
|
cs2.setFillForegroundColor(( short ) 0x0);
|
||||||
cs2.setFillPattern(( short ) 1);
|
cs2.setFillPattern(( short ) 1);
|
||||||
cs2.setFont(fnt);
|
cs2.setFont(fnt);
|
||||||
for (short rownum = ( short ) 0; rownum < 100; rownum++)
|
for (int rownum = 0; rownum < 100; rownum++) {
|
||||||
{
|
|
||||||
r = s.createRow(rownum);
|
r = s.createRow(rownum);
|
||||||
|
|
||||||
// r.setRowNum(( short ) rownum);
|
for (int cellnum = 0; cellnum < 50; cellnum += 2) {
|
||||||
for (short cellnum = ( short ) 0; cellnum < 50; cellnum += 2)
|
|
||||||
{
|
|
||||||
c = r.createCell(cellnum);
|
c = r.createCell(cellnum);
|
||||||
c.setCellValue(rownum * 10000 + cellnum
|
c.setCellValue(rownum * 10000 + cellnum
|
||||||
+ ((( double ) rownum / 1000)
|
+ ((( double ) rownum / 1000)
|
||||||
@ -232,15 +204,13 @@ public class TestCellStyle
|
|||||||
sanityChecker.checkHSSFWorkbook(wb);
|
sanityChecker.checkHSSFWorkbook(wb);
|
||||||
assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
|
assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
|
||||||
assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
|
assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
|
||||||
|
|
||||||
// assert((s.getLastRowNum() == 99));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cloning one HSSFCellStyle onto Another, same
|
* Cloning one HSSFCellStyle onto Another, same
|
||||||
* HSSFWorkbook
|
* HSSFWorkbook
|
||||||
*/
|
*/
|
||||||
public void testCloneStyleSameWB() throws Exception {
|
public void testCloneStyleSameWB() {
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFFont fnt = wb.createFont();
|
HSSFFont fnt = wb.createFont();
|
||||||
fnt.setFontName("TestingFont");
|
fnt.setFontName("TestingFont");
|
||||||
@ -271,7 +241,7 @@ public class TestCellStyle
|
|||||||
* Cloning one HSSFCellStyle onto Another, across
|
* Cloning one HSSFCellStyle onto Another, across
|
||||||
* two different HSSFWorkbooks
|
* two different HSSFWorkbooks
|
||||||
*/
|
*/
|
||||||
public void testCloneStyleDiffWB() throws Exception {
|
public void testCloneStyleDiffWB() {
|
||||||
HSSFWorkbook wbOrig = new HSSFWorkbook();
|
HSSFWorkbook wbOrig = new HSSFWorkbook();
|
||||||
|
|
||||||
HSSFFont fnt = wbOrig.createFont();
|
HSSFFont fnt = wbOrig.createFont();
|
||||||
@ -310,7 +280,7 @@ public class TestCellStyle
|
|||||||
assertEquals(5, wbClone.getNumberOfFonts());
|
assertEquals(5, wbClone.getNumberOfFonts());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStyleNames() throws Exception {
|
public void testStyleNames() {
|
||||||
HSSFWorkbook wb = openSample("WithExtendedStyles.xls");
|
HSSFWorkbook wb = openSample("WithExtendedStyles.xls");
|
||||||
HSSFSheet s = wb.getSheetAt(0);
|
HSSFSheet s = wb.getSheetAt(0);
|
||||||
HSSFCell c1 = s.getRow(0).getCell(0);
|
HSSFCell c1 = s.getRow(0).getCell(0);
|
||||||
@ -357,11 +327,4 @@ public class TestCellStyle
|
|||||||
assertEquals("style1", cs2.getParentStyle().getUserStyleName());
|
assertEquals("style1", cs2.getParentStyle().getUserStyleName());
|
||||||
assertEquals("style2", cs3.getParentStyle().getUserStyleName());
|
assertEquals("style2", cs3.getParentStyle().getUserStyleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String [] ignored_args)
|
|
||||||
{
|
|
||||||
System.out
|
|
||||||
.println("Testing org.apache.poi.hssf.usermodel.HSSFCellStyle");
|
|
||||||
junit.textui.TestRunner.run(TestCellStyle.class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -14,37 +14,18 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* TestRowStyle.java
|
|
||||||
*
|
|
||||||
* Created on May 20, 2005
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.util.TempFile;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to test row styling functionality
|
* Class to test row styling functionality
|
||||||
*
|
*
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
||||||
*/
|
*/
|
||||||
|
public final class TestRowStyle extends TestCase {
|
||||||
public class TestRowStyle
|
|
||||||
extends TestCase
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Creates a new instance of TestCellStyle */
|
|
||||||
|
|
||||||
public TestRowStyle(String name)
|
|
||||||
{
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TEST NAME: Test Write Sheet Font <P>
|
* TEST NAME: Test Write Sheet Font <P>
|
||||||
@ -55,21 +36,17 @@ public class TestRowStyle
|
|||||||
* HSSFSheet last row or first row is incorrect. <P>
|
* HSSFSheet last row or first row is incorrect. <P>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
public void testWriteSheetFont() {
|
||||||
public void testWriteSheetFont()
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet s = wb.createSheet();
|
HSSFSheet s = wb.createSheet();
|
||||||
HSSFRow r = null;
|
HSSFRow r = null;
|
||||||
HSSFCell c = null;
|
|
||||||
HSSFFont fnt = wb.createFont();
|
HSSFFont fnt = wb.createFont();
|
||||||
HSSFCellStyle cs = wb.createCellStyle();
|
HSSFCellStyle cs = wb.createCellStyle();
|
||||||
|
|
||||||
fnt.setColor(HSSFFont.COLOR_RED);
|
fnt.setColor(HSSFFont.COLOR_RED);
|
||||||
fnt.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
|
fnt.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
|
||||||
cs.setFont(fnt);
|
cs.setFont(fnt);
|
||||||
for (short rownum = ( short ) 0; rownum < 100; rownum++)
|
for (int rownum = 0; rownum < 100; rownum++)
|
||||||
{
|
{
|
||||||
r = s.createRow(rownum);
|
r = s.createRow(rownum);
|
||||||
r.setRowStyle(cs);
|
r.setRowStyle(cs);
|
||||||
@ -86,13 +63,11 @@ public class TestRowStyle
|
|||||||
/**
|
/**
|
||||||
* Tests that is creating a file with a date or an calendar works correctly.
|
* Tests that is creating a file with a date or an calendar works correctly.
|
||||||
*/
|
*/
|
||||||
public void testDataStyle()
|
public void testDataStyle() {
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet s = wb.createSheet();
|
HSSFSheet s = wb.createSheet();
|
||||||
HSSFCellStyle cs = wb.createCellStyle();
|
HSSFCellStyle cs = wb.createCellStyle();
|
||||||
HSSFRow row = s.createRow((short)0);
|
HSSFRow row = s.createRow(0);
|
||||||
|
|
||||||
// with Date:
|
// with Date:
|
||||||
cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
|
cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
|
||||||
@ -101,7 +76,7 @@ public class TestRowStyle
|
|||||||
|
|
||||||
|
|
||||||
// with Calendar:
|
// with Calendar:
|
||||||
row = s.createRow((short)1);
|
row = s.createRow(1);
|
||||||
cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
|
cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
|
||||||
row.setRowStyle(cs);
|
row.setRowStyle(cs);
|
||||||
row.createCell(0);
|
row.createCell(0);
|
||||||
@ -126,10 +101,7 @@ public class TestRowStyle
|
|||||||
* HSSFSheet last row or first row is incorrect. <P>
|
* HSSFSheet last row or first row is incorrect. <P>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
public void testWriteSheetStyle() {
|
||||||
public void testWriteSheetStyle()
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet s = wb.createSheet();
|
HSSFSheet s = wb.createSheet();
|
||||||
HSSFRow r = null;
|
HSSFRow r = null;
|
||||||
@ -148,7 +120,7 @@ public class TestRowStyle
|
|||||||
cs2.setFillForegroundColor(( short ) 0x0);
|
cs2.setFillForegroundColor(( short ) 0x0);
|
||||||
cs2.setFillPattern(( short ) 1);
|
cs2.setFillPattern(( short ) 1);
|
||||||
cs2.setFont(fnt);
|
cs2.setFont(fnt);
|
||||||
for (short rownum = ( short ) 0; rownum < 100; rownum++)
|
for (int rownum = 0; rownum < 100; rownum++)
|
||||||
{
|
{
|
||||||
r = s.createRow(rownum);
|
r = s.createRow(rownum);
|
||||||
r.setRowStyle(cs);
|
r.setRowStyle(cs);
|
||||||
@ -171,7 +143,7 @@ public class TestRowStyle
|
|||||||
s = wb.getSheetAt(0);
|
s = wb.getSheetAt(0);
|
||||||
assertNotNull("Sheet is not null", s);
|
assertNotNull("Sheet is not null", s);
|
||||||
|
|
||||||
for (short rownum = ( short ) 0; rownum < 100; rownum++)
|
for (int rownum = 0; rownum < 100; rownum++)
|
||||||
{
|
{
|
||||||
r = s.getRow(rownum);
|
r = s.getRow(rownum);
|
||||||
assertNotNull("Row is not null", r);
|
assertNotNull("Row is not null", r);
|
||||||
@ -194,11 +166,4 @@ public class TestRowStyle
|
|||||||
assertEquals("FillPattern for row: ", cs2.getFillPattern(), (short) 0x1);
|
assertEquals("FillPattern for row: ", cs2.getFillPattern(), (short) 0x1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String [] ignored_args)
|
|
||||||
{
|
|
||||||
System.out
|
|
||||||
.println("Testing org.apache.poi.hssf.usermodel.HSSFCellStyle");
|
|
||||||
junit.textui.TestRunner.run(TestCellStyle.class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user