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:
Josh Micich 2009-02-03 01:19:13 +00:00
parent 2b78c4ccd5
commit 6fd3790d79
22 changed files with 360 additions and 560 deletions

View File

@ -29,27 +29,23 @@ import java.io.IOException;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class Alignment
{
public static void main(String[] args)
throws IOException
{
public class Alignment {
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow((short) 2);
createCell(wb, row, (short) 0, HSSFCellStyle.ALIGN_CENTER);
createCell(wb, row, (short) 1, HSSFCellStyle.ALIGN_CENTER_SELECTION);
createCell(wb, row, (short) 2, HSSFCellStyle.ALIGN_FILL);
createCell(wb, row, (short) 3, HSSFCellStyle.ALIGN_GENERAL);
createCell(wb, row, (short) 4, HSSFCellStyle.ALIGN_JUSTIFY);
createCell(wb, row, (short) 5, HSSFCellStyle.ALIGN_LEFT);
createCell(wb, row, (short) 6, HSSFCellStyle.ALIGN_RIGHT);
HSSFRow row = sheet.createRow(2);
createCell(wb, row, 0, HSSFCellStyle.ALIGN_CENTER);
createCell(wb, row, 1, HSSFCellStyle.ALIGN_CENTER_SELECTION);
createCell(wb, row, 2, HSSFCellStyle.ALIGN_FILL);
createCell(wb, row, 3, HSSFCellStyle.ALIGN_GENERAL);
createCell(wb, row, 4, HSSFCellStyle.ALIGN_JUSTIFY);
createCell(wb, row, 5, HSSFCellStyle.ALIGN_LEFT);
createCell(wb, row, 6, HSSFCellStyle.ALIGN_RIGHT);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
/**
@ -60,12 +56,11 @@ public class Alignment
* @param column the column number to create the cell in
* @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);
cell.setCellValue("Align It");
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setAlignment(align);
cellStyle.setAlignment((short)align);
cell.setCellStyle(cellStyle);
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
@ -31,12 +29,9 @@ import java.io.IOException;
* @author Glen Stampoultzis (glens at apache.org)
* @author Andrew Oliver (acoliver at apache.org)
*/
public class BigExample
{
public static void main(String[] args)
throws IOException
{
short rownum;
public class BigExample {
public static void main(String[] args) throws IOException {
int rownum;
// create a new file
FileOutputStream out = new FileOutputStream("workbook.xls");
@ -59,7 +54,7 @@ public class BigExample
//set font 1 to 12 point type
f.setFontHeightInPoints((short) 12);
//make it red
f.setColor((short) HSSFColor.RED.index);
f.setColor(HSSFColor.RED.index);
// make it bold
//arial is the default font
f.setBoldweight(f.BOLDWEIGHT_BOLD);
@ -67,7 +62,7 @@ public class BigExample
//set font 2 to 10 point type
f2.setFontHeightInPoints((short) 10);
//make it the color at palette index 0xf (white)
f2.setColor((short) HSSFColor.WHITE.index);
f2.setColor(HSSFColor.WHITE.index);
//make it bold
f2.setBoldweight(f2.BOLDWEIGHT_BOLD);
@ -79,9 +74,9 @@ public class BigExample
//set a thin border
cs2.setBorderBottom(cs2.BORDER_THIN);
//fill w fg fill color
cs2.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
cs2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
// set foreground fill to red
cs2.setFillForegroundColor((short) HSSFColor.RED.index);
cs2.setFillForegroundColor(HSSFColor.RED.index);
// set the font
cs2.setFont(f2);
@ -89,7 +84,7 @@ public class BigExample
// set the sheet name to HSSF Test
wb.setSheetName(0, "HSSF Test");
// create a sheet with 300 rows (0-299)
for (rownum = (short) 0; rownum < 300; rownum++)
for (rownum = 0; rownum < 300; rownum++)
{
// create a row
r = s.createRow(rownum);
@ -102,7 +97,7 @@ public class BigExample
//r.setRowNum(( short ) rownum);
// 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
c = r.createCell(cellnum);
@ -119,12 +114,12 @@ public class BigExample
}
// 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"
c.setCellValue("TEST");
// 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
if ((rownum % 2) == 0)
@ -149,8 +144,7 @@ public class BigExample
cs3.setBorderBottom(cs3.BORDER_THICK);
//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)
c = r.createCell(cellnum);
// set it to the thick black border style

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
@ -30,19 +28,16 @@ import java.io.IOException;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class Borders
{
public static void main(String[] args)
throws IOException
{
public class Borders {
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
// 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.
HSSFCell cell = row.createCell((short) 1);
HSSFCell cell = row.createCell(1);
cell.setCellValue(4);
// Style the cell with borders all around.

View File

@ -14,6 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
import org.apache.poi.hssf.usermodel.*;
@ -42,7 +43,7 @@ public class CellComments {
HSSFPatriarch patr = sheet.createDrawingPatriarch();
//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"));
//anchor defines size and position of the comment in worksheet
@ -59,7 +60,7 @@ public class CellComments {
cell1.setCellComment(comment1);
//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);
@ -85,7 +86,7 @@ public class CellComments {
/**
* 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.
* It works, the commnet is visible.
* It works, the comment is visible.
*/
comment2.setRow(6);
comment2.setColumn((short)1);
@ -93,7 +94,5 @@ public class CellComments {
FileOutputStream out = new FileOutputStream("poi_comment.xls");
wb.write(out);
out.close();
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
@ -28,19 +26,16 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
public class CellTypes
{
public static void main(String[] args)
throws IOException
{
public class CellTypes {
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow((short)2);
row.createCell((short) 0).setCellValue(1.1);
row.createCell((short) 1).setCellValue(new Date());
row.createCell((short) 2).setCellValue("a string");
row.createCell((short) 3).setCellValue(true);
row.createCell((short) 4).setCellType(HSSFCell.CELL_TYPE_ERROR);
HSSFRow row = sheet.createRow(2);
row.createCell(0).setCellValue(1.1);
row.createCell(1).setCellValue(new Date());
row.createCell(2).setCellValue("a string");
row.createCell(3).setCellValue(true);
row.createCell(4).setCellType(HSSFCell.CELL_TYPE_ERROR);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
@ -32,24 +30,21 @@ import java.io.IOException;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class CreateCells
{
public static void main(String[] args)
throws IOException
{
public class CreateCells {
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
// 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.
HSSFCell cell = row.createCell((short)0);
HSSFCell cell = row.createCell(0);
cell.setCellValue(1);
// Or do it on one line.
row.createCell((short)1).setCellValue(1.2);
row.createCell((short)2).setCellValue("This is a string");
row.createCell((short)3).setCellValue(true);
row.createCell(1).setCellValue(1.2);
row.createCell(2).setCellValue("This is a string");
row.createCell(3).setCellValue(true);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
@ -32,26 +30,23 @@ import java.util.Date;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class CreateDateCells
{
public static void main(String[] args)
throws IOException
{
public class CreateDateCells {
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
// 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.
HSSFCell cell = row.createCell((short)0);
HSSFCell cell = row.createCell(0);
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
// otherwise you can end up modifying the built in style and effecting not only this cell but other cells.
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
cell = row.createCell((short)1);
cell = row.createCell(1);
cell.setCellValue(new Date());
cell.setCellStyle(cellStyle);
@ -59,6 +54,5 @@ public class CreateDateCells
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
@ -30,22 +28,19 @@ import java.io.IOException;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class FrillsAndFills
{
public static void main(String[] args)
throws IOException
{
public class FrillsAndFills {
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
// 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
HSSFCellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(HSSFColor.AQUA.index);
style.setFillPattern(HSSFCellStyle.BIG_SPOTS);
HSSFCell cell = row.createCell((short) 1);
HSSFCell cell = row.createCell(1);
cell.setCellValue("X");
cell.setCellStyle(style);
@ -53,7 +48,7 @@ public class FrillsAndFills
style = wb.createCellStyle();
style.setFillForegroundColor(HSSFColor.ORANGE.index);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
cell = row.createCell((short) 2);
cell = row.createCell(2);
cell.setCellValue("X");
cell.setCellStyle(style);

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
@ -25,28 +23,22 @@ import java.io.FileOutputStream;
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
*/
public class HyperlinkFormula
{
public static void main(String[] args)
throws IOException
{
HSSFCell cell;
HSSFWorkbook wb = new HSSFWorkbook();
public class HyperlinkFormula {
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
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.setCellFormula("HYPERLINK(\"http://127.0.0.1:8080/toto/truc/index.html?test=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"test\")");
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -35,7 +34,7 @@ public class Hyperlinks {
HSSFWorkbook wb = new HSSFWorkbook();
//cell style for hyperlinks
//by default hypelrinks are blue and underlined
//by default hyperlinks are blue and underlined
HSSFCellStyle hlink_style = wb.createCellStyle();
HSSFFont hlink_font = wb.createFont();
hlink_font.setUnderline(HSSFFont.U_SINGLE);
@ -46,7 +45,7 @@ public class Hyperlinks {
HSSFSheet sheet = wb.createSheet("Hyperlinks");
//URL
cell = sheet.createRow(0).createCell((short)0);
cell = sheet.createRow(0).createCell(0);
cell.setCellValue("URL Link");
HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
link.setAddress("http://poi.apache.org/");
@ -54,7 +53,7 @@ public class Hyperlinks {
cell.setCellStyle(hlink_style);
//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");
link = new HSSFHyperlink(HSSFHyperlink.LINK_FILE);
link.setAddress("link1.xls");
@ -62,7 +61,7 @@ public class Hyperlinks {
cell.setCellStyle(hlink_style);
//e-mail link
cell = sheet.createRow(2).createCell((short)0);
cell = sheet.createRow(2).createCell(0);
cell.setCellValue("Email Link");
link = new HSSFHyperlink(HSSFHyperlink.LINK_EMAIL);
//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
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");
link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
link.setAddress("'Target Sheet'!A1");
@ -86,6 +85,5 @@ public class Hyperlinks {
FileOutputStream out = new FileOutputStream("hssf-links.xls");
wb.write(out);
out.close();
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,12 +14,11 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
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.FileOutputStream;
@ -30,24 +28,20 @@ import java.io.FileOutputStream;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class MergedCells
{
public static void main(String[] args)
throws IOException
{
public class MergedCells {
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow((short) 1);
HSSFCell cell = row.createCell((short) 1);
HSSFRow row = sheet.createRow(1);
HSSFCell cell = row.createCell(1);
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
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
@ -30,36 +28,32 @@ import java.io.IOException;
* @author Glen Stampoultzis (glens at apache.org)
* @author Fauzia Lala <fauzia.lala at wcom.com>
*/
public class NewLinesInCells
{
public static void main( String[] args ) throws IOException
{
public class NewLinesInCells {
public static void main( String[] args ) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
HSSFRow r = null;
HSSFCell c = null;
HSSFCellStyle cs = wb.createCellStyle();
HSSFFont f = wb.createFont();
HSSFFont f2 = wb.createFont();
HSSFSheet s = wb.createSheet();
HSSFRow r = null;
HSSFCell c = null;
HSSFCellStyle cs = wb.createCellStyle();
HSSFFont f2 = wb.createFont();
cs = wb.createCellStyle();
cs = wb.createCellStyle();
cs.setFont( f2 );
//Word Wrap MUST be turned on
cs.setWrapText( true );
cs.setFont(f2);
// Word Wrap MUST be turned on
cs.setWrapText(true);
r = s.createRow( (short) 2 );
r.setHeight( (short) 0x349 );
c = r.createCell( (short) 2 );
c.setCellType( HSSFCell.CELL_TYPE_STRING );
c.setCellValue( "Use \n with word wrap on to create a new line" );
c.setCellStyle( cs );
s.setColumnWidth( (short) 2, (short) ( ( 50 * 8 ) / ( (double) 1 / 20 ) ) );
FileOutputStream fileOut = new FileOutputStream( "workbook.xls" );
wb.write( fileOut );
fileOut.close();
r = s.createRow(2);
r.setHeight((short) 0x349);
c = r.createCell(2);
c.setCellType(HSSFCell.CELL_TYPE_STRING);
c.setCellValue("Use \n with word wrap on to create a new line");
c.setCellStyle(cs);
s.setColumnWidth(2, (int) ((50 * 8) / ((double) 1 / 20)));
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
@ -30,14 +28,12 @@ import java.io.FileOutputStream;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class NewSheet
{
public static void main(String[] args)
throws IOException
{
public class NewSheet {
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
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");
wb.write(fileOut);
fileOut.close();

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
import org.apache.poi.hssf.usermodel.*;
@ -27,11 +26,8 @@ import java.io.*;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class OfficeDrawing
{
public static void main(String[] args)
throws IOException
{
public class OfficeDrawing {
public static void main(String[] args) throws IOException {
// Create the workbook and sheets.
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
@ -58,8 +54,8 @@ public class OfficeDrawing
// Create a row and size one of the cells reasonably large.
HSSFRow row = sheet1.createRow(2);
row.setHeight((short) 2800);
row.createCell( (short)1 );
sheet1.setColumnWidth((short) 2, (short) 9000);
row.createCell(1);
sheet1.setColumnWidth(2, 9000);
// Create the drawing patriarch. This is the top level container for
// all shapes.
@ -80,9 +76,9 @@ public class OfficeDrawing
{
// Create a row and size one of the cells reasonably large.
HSSFRow row = sheet2.createRow(2);
row.createCell( (short)1 );
row.createCell(1);
row.setHeightInPoints(240);
sheet2.setColumnWidth((short) 2, (short) 9000);
sheet2.setColumnWidth(2, 9000);
// Create the drawing patriarch. This is the top level container for
// 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
HSSFRow row = sheet3.createRow(2);
row.setHeightInPoints(140);
row.createCell( (short)1 );
sheet3.setColumnWidth((short) 2, (short) 9000);
row.createCell(1);
sheet3.setColumnWidth(2, 9000);
// Create the drawing patriarch. This is the top level container for
// all shapes. This will clear out any existing shapes for that sheet.

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
import org.apache.poi.hssf.usermodel.*;
@ -29,15 +28,13 @@ import java.io.IOException;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class OfficeDrawingWithGraphics
{
public static void main( String[] args ) throws IOException
{
public class OfficeDrawingWithGraphics {
public static void main( String[] args ) throws IOException {
// Create a workbook with one sheet and size the first three somewhat
// larger so we can fit the chemical structure diagram in.
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet( "my drawing" );
sheet.setColumnWidth((short)1, (short)(256 * 27));
sheet.setColumnWidth(1, 256 * 27);
HSSFRow row1 = sheet.createRow(0);
row1.setHeightInPoints(10 * 15);
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
// sort them.
row1.createCell((short)0).setCellValue("C");
row2.createCell((short)0).setCellValue("A");
row3.createCell((short)0).setCellValue("B");
row1.createCell(0).setCellValue("C");
row2.createCell(0).setCellValue("A");
row3.createCell(0).setCellValue("B");
// Create the top level drawing patriarch.
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
@ -62,7 +59,7 @@ public class OfficeDrawingWithGraphics
a = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 1, 0, (short) 1, 0 );
group = patriarch.createGroup( a );
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 );
g2d = new EscherGraphics2d( g );
drawStar( g2d );
@ -70,7 +67,7 @@ public class OfficeDrawingWithGraphics
a = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 1, 1, (short) 1, 1 );
group = patriarch.createGroup( a );
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);
g = new EscherGraphics( group, wb, Color.black, verticalPointsPerPixel );
g2d = new EscherGraphics2d( g );

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
@ -29,16 +27,11 @@ import java.io.IOException;
/**
* Creates outlines.
*
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class Outlines
{
private Outlines(){}
public static void main(String[] args)
throws IOException
{
public class Outlines {
public static void main(String[] args) throws IOException {
createCase1( "outline1.xls" );
System.out.println( "outline1.xls written. Two expanded groups." );
createCase2( "outline2.xls" );
@ -67,19 +60,17 @@ public class Outlines
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();
HSSFSheet sheet1 = wb.createSheet("new sheet");
sheet1.groupColumn( (short)4, (short)7 );
sheet1.groupColumn(4, 7);
for (int row = 0; row < 200; row++)
{
HSSFRow r = sheet1.createRow( row );
for (int column = 0; column < 200; column++)
{
HSSFCell c = r.createCell( (short) column );
c.setCellValue( column );
for (int row = 0; row < 200; row++) {
HSSFRow r = sheet1.createRow(row);
for (int column = 0; column < 200; column++) {
HSSFCell c = r.createCell(column);
c.setCellValue(column);
}
}
@ -88,198 +79,181 @@ public class Outlines
fileOut.close();
}
private static void createCase2( String filename ) throws IOException{
private static void createCase2(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
sheet1.groupColumn( (short)2, (short)10 );
sheet1.groupColumn( (short)4, (short)7 );
sheet1.setColumnGroupCollapsed( (short)4, true );
sheet1.groupColumn(2, 10);
sheet1.groupColumn(4, 7);
sheet1.setColumnGroupCollapsed(4, true);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
private static void createCase3( String filename ) throws IOException{
private static void createCase3(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
sheet1.groupColumn( (short)2, (short)10 );
sheet1.groupColumn( (short)4, (short)7 );
sheet1.setColumnGroupCollapsed( (short)4, true );
sheet1.setColumnGroupCollapsed( (short)2, true );
sheet1.groupColumn(2, 10);
sheet1.groupColumn(4, 7);
sheet1.setColumnGroupCollapsed(4, true);
sheet1.setColumnGroupCollapsed(2, true);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
private static void createCase4( String filename ) throws IOException{
private static void createCase4(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
sheet1.groupColumn( (short)2, (short)10 );
sheet1.groupColumn( (short)4, (short)7 );
sheet1.setColumnGroupCollapsed( (short)4, true );
sheet1.setColumnGroupCollapsed( (short)2, true );
sheet1.groupColumn(2, 10);
sheet1.groupColumn(4, 7);
sheet1.setColumnGroupCollapsed(4, true);
sheet1.setColumnGroupCollapsed(2, true);
sheet1.setColumnGroupCollapsed( (short)4, false );
sheet1.setColumnGroupCollapsed(4, false);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
private static void createCase5( String filename ) throws IOException{
private static void createCase5(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
sheet1.groupColumn( (short)2, (short)10 );
sheet1.groupColumn( (short)4, (short)7 );
sheet1.setColumnGroupCollapsed( (short)4, true );
sheet1.setColumnGroupCollapsed( (short)2, true );
sheet1.groupColumn(2, 10);
sheet1.groupColumn(4, 7);
sheet1.setColumnGroupCollapsed(4, true);
sheet1.setColumnGroupCollapsed(2, true);
sheet1.setColumnGroupCollapsed( (short)4, false );
sheet1.setColumnGroupCollapsed( (short)3, false );
sheet1.setColumnGroupCollapsed(4, false);
sheet1.setColumnGroupCollapsed(3, false);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
private static void createCase6( String filename ) throws IOException{
private static void createCase6(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
sheet1.groupColumn( (short)2, (short)10 );
sheet1.groupColumn( (short)4, (short)10 );
sheet1.setColumnGroupCollapsed( (short)4, true );
sheet1.setColumnGroupCollapsed( (short)2, true );
sheet1.groupColumn(2, 10);
sheet1.groupColumn(4, 10);
sheet1.setColumnGroupCollapsed(4, true);
sheet1.setColumnGroupCollapsed(2, true);
sheet1.setColumnGroupCollapsed( (short)3, false );
sheet1.setColumnGroupCollapsed(3, false);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
private static void createCase7( String filename )
throws IOException
{
private static void createCase7(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
sheet1.groupRow( 5, 14 );
sheet1.groupRow( 7, 10 );
sheet1.groupRow(5, 14);
sheet1.groupRow(7, 10);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
private static void createCase8( String filename )
throws IOException
{
private static void createCase8(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
sheet1.groupRow( 5, 14 );
sheet1.groupRow( 7, 10 );
sheet1.setRowGroupCollapsed( 7, true );
sheet1.groupRow(5, 14);
sheet1.groupRow(7, 10);
sheet1.setRowGroupCollapsed(7, true);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
private static void createCase9( String filename )
throws IOException
{
private static void createCase9(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
sheet1.groupRow( 5, 14 );
sheet1.groupRow( 7, 10 );
sheet1.setRowGroupCollapsed( 7, true );
sheet1.setRowGroupCollapsed( 5, true );
sheet1.groupRow(5, 14);
sheet1.groupRow(7, 10);
sheet1.setRowGroupCollapsed(7, true);
sheet1.setRowGroupCollapsed(5, true);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
private static void createCase10( String filename )
throws IOException
{
private static void createCase10(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
sheet1.groupRow( 5, 14 );
sheet1.groupRow( 7, 10 );
sheet1.setRowGroupCollapsed( 7, true );
sheet1.setRowGroupCollapsed( 5, true );
sheet1.setRowGroupCollapsed( 8, false );
sheet1.groupRow(5, 14);
sheet1.groupRow(7, 10);
sheet1.setRowGroupCollapsed(7, true);
sheet1.setRowGroupCollapsed(5, true);
sheet1.setRowGroupCollapsed(8, false);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
private static void createCase11( String filename )
throws IOException
{
private static void createCase11(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
sheet1.groupRow( 5, 14 );
sheet1.groupRow( 7, 10 );
sheet1.setRowGroupCollapsed( 7, true );
sheet1.setRowGroupCollapsed( 5, true );
sheet1.setRowGroupCollapsed( 8, false );
sheet1.setRowGroupCollapsed( 14, false );
sheet1.groupRow(5, 14);
sheet1.groupRow(7, 10);
sheet1.setRowGroupCollapsed(7, true);
sheet1.setRowGroupCollapsed(5, true);
sheet1.setRowGroupCollapsed(8, false);
sheet1.setRowGroupCollapsed(14, false);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
private static void createCase12( String filename )
throws IOException
{
private static void createCase12(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
sheet1.groupRow( 5, 14 );
sheet1.groupRow( 7, 14 );
sheet1.setRowGroupCollapsed( 7, true );
sheet1.setRowGroupCollapsed( 5, true );
sheet1.setRowGroupCollapsed( 6, false );
sheet1.groupRow(5, 14);
sheet1.groupRow(7, 14);
sheet1.setRowGroupCollapsed(7, true);
sheet1.setRowGroupCollapsed(5, true);
sheet1.setRowGroupCollapsed(6, false);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
private static void createCase13( String filename )
throws IOException
{
private static void createCase13(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
sheet1.groupRow( 5, 14 );
sheet1.groupRow( 7, 14 );
sheet1.groupRow( 16, 19 );
sheet1.groupRow(5, 14);
sheet1.groupRow(7, 14);
sheet1.groupRow(16, 19);
sheet1.groupColumn( (short)4, (short)7 );
sheet1.groupColumn( (short)9, (short)12 );
sheet1.groupColumn( (short)10, (short)11 );
sheet1.groupColumn(4, 7);
sheet1.groupColumn(9, 12);
sheet1.groupColumn(10, 11);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
@ -35,11 +33,8 @@ import java.io.IOException;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class ReadWriteWorkbook
{
public static void main(String[] args)
throws IOException
{
public class ReadWriteWorkbook {
public static void main(String[] args) throws IOException {
FileInputStream fileIn = null;
FileOutputStream fileOut = null;
@ -52,18 +47,16 @@ public class ReadWriteWorkbook
HSSFRow row = sheet.getRow(2);
if (row == null)
row = sheet.createRow(2);
HSSFCell cell = row.getCell((short)3);
HSSFCell cell = row.getCell(3);
if (cell == null)
cell = row.createCell((short)3);
cell = row.createCell(3);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue("a test");
// Write the output to a file
fileOut = new FileOutputStream("workbookout.xls");
wb.write(fileOut);
}
finally
{
} finally {
if (fileOut != null)
fileOut.close();
if (fileIn != null)

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,34 +14,23 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.FileInputStream;
/**
* @author Glen Stampoultzis (glens at apache.org)
*/
public class RepeatingRowsAndColumns
{
public static void main(String[] args)
throws IOException
{
public class RepeatingRowsAndColumns {
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("first sheet");
HSSFSheet sheet2 = wb.createSheet("second sheet");
HSSFSheet sheet3 = wb.createSheet("third sheet");
// POIFSFileSystem fs =
// new POIFSFileSystem(new FileInputStream("workbook.xls"));
// HSSFWorkbook wb = new HSSFWorkbook(fs);
// HSSFSheet sheet1 = wb.getSheetAt(0);
wb.createSheet("second sheet");
wb.createSheet("third sheet");
HSSFFont boldFont = wb.createFont();
boldFont.setFontHeightInPoints((short)22);
@ -51,8 +39,8 @@ public class RepeatingRowsAndColumns
HSSFCellStyle boldStyle = wb.createCellStyle();
boldStyle.setFont(boldFont);
HSSFRow row = sheet1.createRow((short)1);
HSSFCell cell = row.createCell((short)0);
HSSFRow row = sheet1.createRow(1);
HSSFCell cell = row.createCell(0);
cell.setCellValue("This quick brown fox");
cell.setCellStyle(boldStyle);

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.usermodel.examples;
@ -29,16 +27,13 @@ import java.io.IOException;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class WorkingWithFonts
{
public static void main(String[] args)
throws IOException
{
public class WorkingWithFonts {
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
// 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.
HSSFFont font = wb.createFont();
@ -52,7 +47,7 @@ public class WorkingWithFonts
style.setFont(font);
// 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.setCellStyle(style);
@ -60,6 +55,5 @@ public class WorkingWithFonts
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
}

View File

@ -45,9 +45,9 @@ import org.apache.poi.ss.util.Region;
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
@ -60,16 +60,9 @@ public class HSSF
*
*/
public HSSF(String filename)
throws IOException
{
this.filename = filename;
POIFSFileSystem fs =
new POIFSFileSystem(new FileInputStream(filename));
hssfworkbook = new HSSFWorkbook(fs);
// records = RecordFactory.createRecords(stream);
public HSSF(String filename) throws IOException {
_filename = filename;
_hssfworkbook = new HSSFWorkbook(new FileInputStream(filename));
}
/**
@ -87,7 +80,7 @@ public class HSSF
public HSSF(String filename, boolean write)
throws IOException
{
short rownum = 0;
int rownum = 0;
FileOutputStream out = new FileOutputStream(filename);
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
@ -112,7 +105,7 @@ public class HSSF
cs2.setFillForegroundColor(( short ) 0xA);
cs2.setFont(f2);
wb.setSheetName(0, "HSSF Test");
for (rownum = ( short ) 0; rownum < 300; rownum++)
for (rownum = 0; rownum < 300; rownum++)
{
r = s.createRow(rownum);
if ((rownum % 2) == 0)
@ -121,7 +114,7 @@ public class HSSF
}
// 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.setCellValue(rownum * 10000 + cellnum
@ -147,7 +140,7 @@ public class HSSF
rownum++;
r = s.createRow(rownum);
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);
@ -183,11 +176,11 @@ public class HSSF
public HSSF(String infile, String outfile, boolean write)
throws IOException
{
this.filename = infile;
_filename = infile;
POIFSFileSystem fs =
new POIFSFileSystem(new FileInputStream(filename));
new POIFSFileSystem(new FileInputStream(_filename));
hssfworkbook = new HSSFWorkbook(fs);
_hssfworkbook = new HSSFWorkbook(fs);
// HSSFWorkbook book = hssfstream.getWorkbook();
}
@ -226,7 +219,7 @@ public class HSSF
HSSF hssf = new HSSF(args[ 0 ]);
System.out.println("Data dump:\n");
HSSFWorkbook wb = hssf.hssfworkbook;
HSSFWorkbook wb = hssf._hssfworkbook;
for (int k = 0; k < wb.getNumberOfSheets(); k++)
{
@ -238,11 +231,12 @@ public class HSSF
for (int r = 0; r < rows; r++)
{
HSSFRow row = sheet.getRow(r);
int cells = (row != null) ? row.getPhysicalNumberOfCells() : 0;
if (row != null) {
System.out.println("\nROW " + row.getRowNum()
+ " has " + cells + " cell(s).");
if (row == null) {
continue;
}
int cells = row.getPhysicalNumberOfCells();
System.out.println("\nROW " + row.getRowNum()
+ " has " + cells + " cell(s).");
for (int c = 0; c < cells; c++)
{
HSSFCell cell = row.getCell(c);
@ -269,7 +263,7 @@ public class HSSF
default :
}
System.out.println("CELL col="
+ cell.getCellNum()
+ cell.getColumnIndex()
+ " VALUE=" + value);
}
}
@ -307,7 +301,7 @@ public class HSSF
HSSF hssf = new HSSF(args[ 0 ]);
// HSSFStream hssfstream = hssf.hssfstream;
HSSFWorkbook wb = hssf.hssfworkbook;
HSSFWorkbook wb = hssf._hssfworkbook;
FileOutputStream stream = new FileOutputStream(args[ 1 ]);
// HSSFCell cell = new HSSFCell();
@ -332,7 +326,7 @@ public class HSSF
HSSF hssf = new HSSF(args[ 0 ]);
// HSSFStream hssfstream = hssf.hssfstream;
HSSFWorkbook wb = hssf.hssfworkbook;
HSSFWorkbook wb = hssf._hssfworkbook;
FileOutputStream stream = new FileOutputStream(args[ 1 ]);
HSSFSheet sheet = wb.getSheetAt(0);

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -15,20 +14,16 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
/*
* TestCellStyle.java
*
* Created on December 11, 2001, 5:51 PM
*/
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.*;
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.util.TempFile;
@ -39,20 +34,12 @@ import org.apache.poi.util.TempFile;
* @author Andrew C. Oliver
*/
public class TestCellStyle
extends TestCase
{
public final class TestCellStyle extends TestCase {
private static HSSFWorkbook openSample(String sampleFileName) {
return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
}
/** Creates a new instance of TestCellStyle */
public TestCellStyle(String name)
{
super(name);
}
/**
* TEST NAME: Test Write Sheet Font <P>
@ -63,10 +50,7 @@ public class TestCellStyle
* HSSFSheet last row or first row is incorrect. <P>
*
*/
public void testWriteSheetFont()
throws IOException
{
public void testWriteSheetFont() throws IOException{
File file = TempFile.createTempFile("testWriteSheetFont",
".xls");
FileOutputStream out = new FileOutputStream(file);
@ -80,13 +64,10 @@ public class TestCellStyle
fnt.setColor(HSSFFont.COLOR_RED);
fnt.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
cs.setFont(fnt);
for (short rownum = ( short ) 0; rownum < 100; rownum++)
{
for (int rownum = 0; rownum < 100; rownum++) {
r = s.createRow(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);
c.setCellValue(rownum * 10000 + cellnum
+ ((( double ) rownum / 1000)
@ -109,9 +90,7 @@ public class TestCellStyle
/**
* Tests that is creating a file with a date or an calendar works correctly.
*/
public void testDataStyle()
throws Exception
{
public void testDataStyle() throws IOException {
File file = TempFile.createTempFile("testWriteSheetStyleDate",
".xls");
FileOutputStream out = new FileOutputStream(file);
@ -141,7 +120,6 @@ public class TestCellStyle
assertEquals("LAST ROW ", 0, s.getLastRowNum());
assertEquals("FIRST ROW ", 0, s.getFirstRowNum());
}
public void testHashEquals() {
@ -183,10 +161,7 @@ public class TestCellStyle
* HSSFSheet last row or first row is incorrect. <P>
*
*/
public void testWriteSheetStyle()
throws IOException
{
public void testWriteSheetStyle() throws IOException {
File file = TempFile.createTempFile("testWriteSheetStyle",
".xls");
FileOutputStream out = new FileOutputStream(file);
@ -209,13 +184,10 @@ public class TestCellStyle
cs2.setFillForegroundColor(( short ) 0x0);
cs2.setFillPattern(( short ) 1);
cs2.setFont(fnt);
for (short rownum = ( short ) 0; rownum < 100; rownum++)
{
for (int rownum = 0; rownum < 100; rownum++) {
r = s.createRow(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);
c.setCellValue(rownum * 10000 + cellnum
+ ((( double ) rownum / 1000)
@ -232,136 +204,127 @@ public class TestCellStyle
sanityChecker.checkHSSFWorkbook(wb);
assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
// assert((s.getLastRowNum() == 99));
}
/**
* Cloning one HSSFCellStyle onto Another, same
* HSSFWorkbook
*/
public void testCloneStyleSameWB() throws Exception {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFFont fnt = wb.createFont();
fnt.setFontName("TestingFont");
assertEquals(5, wb.getNumberOfFonts());
HSSFCellStyle orig = wb.createCellStyle();
orig.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
orig.setFont(fnt);
orig.setDataFormat((short)18);
assertTrue(HSSFCellStyle.ALIGN_RIGHT == orig.getAlignment());
assertTrue(fnt == orig.getFont(wb));
assertTrue(18 == orig.getDataFormat());
HSSFCellStyle clone = wb.createCellStyle();
assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
assertFalse(fnt == clone.getFont(wb));
assertFalse(18 == clone.getDataFormat());
clone.cloneStyleFrom(orig);
assertTrue(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
assertTrue(fnt == clone.getFont(wb));
assertTrue(18 == clone.getDataFormat());
assertEquals(5, wb.getNumberOfFonts());
public void testCloneStyleSameWB() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFFont fnt = wb.createFont();
fnt.setFontName("TestingFont");
assertEquals(5, wb.getNumberOfFonts());
HSSFCellStyle orig = wb.createCellStyle();
orig.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
orig.setFont(fnt);
orig.setDataFormat((short)18);
assertTrue(HSSFCellStyle.ALIGN_RIGHT == orig.getAlignment());
assertTrue(fnt == orig.getFont(wb));
assertTrue(18 == orig.getDataFormat());
HSSFCellStyle clone = wb.createCellStyle();
assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
assertFalse(fnt == clone.getFont(wb));
assertFalse(18 == clone.getDataFormat());
clone.cloneStyleFrom(orig);
assertTrue(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
assertTrue(fnt == clone.getFont(wb));
assertTrue(18 == clone.getDataFormat());
assertEquals(5, wb.getNumberOfFonts());
}
/**
* Cloning one HSSFCellStyle onto Another, across
* two different HSSFWorkbooks
*/
public void testCloneStyleDiffWB() throws Exception {
HSSFWorkbook wbOrig = new HSSFWorkbook();
HSSFFont fnt = wbOrig.createFont();
fnt.setFontName("TestingFont");
assertEquals(5, wbOrig.getNumberOfFonts());
HSSFDataFormat fmt = wbOrig.createDataFormat();
fmt.getFormat("MadeUpOne");
fmt.getFormat("MadeUpTwo");
HSSFCellStyle orig = wbOrig.createCellStyle();
orig.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
orig.setFont(fnt);
orig.setDataFormat(fmt.getFormat("Test##"));
assertTrue(HSSFCellStyle.ALIGN_RIGHT == orig.getAlignment());
assertTrue(fnt == orig.getFont(wbOrig));
assertTrue(fmt.getFormat("Test##") == orig.getDataFormat());
// Now a style on another workbook
HSSFWorkbook wbClone = new HSSFWorkbook();
assertEquals(4, wbClone.getNumberOfFonts());
HSSFDataFormat fmtClone = wbClone.createDataFormat();
HSSFCellStyle clone = wbClone.createCellStyle();
assertEquals(4, wbClone.getNumberOfFonts());
assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
assertFalse("TestingFont" == clone.getFont(wbClone).getFontName());
clone.cloneStyleFrom(orig);
assertTrue(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
assertTrue("TestingFont" == clone.getFont(wbClone).getFontName());
assertTrue(fmtClone.getFormat("Test##") == clone.getDataFormat());
assertFalse(fmtClone.getFormat("Test##") == fmt.getFormat("Test##"));
assertEquals(5, wbClone.getNumberOfFonts());
public void testCloneStyleDiffWB() {
HSSFWorkbook wbOrig = new HSSFWorkbook();
HSSFFont fnt = wbOrig.createFont();
fnt.setFontName("TestingFont");
assertEquals(5, wbOrig.getNumberOfFonts());
HSSFDataFormat fmt = wbOrig.createDataFormat();
fmt.getFormat("MadeUpOne");
fmt.getFormat("MadeUpTwo");
HSSFCellStyle orig = wbOrig.createCellStyle();
orig.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
orig.setFont(fnt);
orig.setDataFormat(fmt.getFormat("Test##"));
assertTrue(HSSFCellStyle.ALIGN_RIGHT == orig.getAlignment());
assertTrue(fnt == orig.getFont(wbOrig));
assertTrue(fmt.getFormat("Test##") == orig.getDataFormat());
// Now a style on another workbook
HSSFWorkbook wbClone = new HSSFWorkbook();
assertEquals(4, wbClone.getNumberOfFonts());
HSSFDataFormat fmtClone = wbClone.createDataFormat();
HSSFCellStyle clone = wbClone.createCellStyle();
assertEquals(4, wbClone.getNumberOfFonts());
assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
assertFalse("TestingFont" == clone.getFont(wbClone).getFontName());
clone.cloneStyleFrom(orig);
assertTrue(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
assertTrue("TestingFont" == clone.getFont(wbClone).getFontName());
assertTrue(fmtClone.getFormat("Test##") == clone.getDataFormat());
assertFalse(fmtClone.getFormat("Test##") == fmt.getFormat("Test##"));
assertEquals(5, wbClone.getNumberOfFonts());
}
public void testStyleNames() throws Exception {
public void testStyleNames() {
HSSFWorkbook wb = openSample("WithExtendedStyles.xls");
HSSFSheet s = wb.getSheetAt(0);
HSSFCell c1 = s.getRow(0).getCell(0);
HSSFCell c2 = s.getRow(1).getCell(0);
HSSFCell c3 = s.getRow(2).getCell(0);
HSSFCellStyle cs1 = c1.getCellStyle();
HSSFCellStyle cs2 = c2.getCellStyle();
HSSFCellStyle cs3 = c3.getCellStyle();
assertNotNull(cs1);
assertNotNull(cs2);
assertNotNull(cs3);
// Check we got the styles we'd expect
assertEquals(10, cs1.getFont(wb).getFontHeightInPoints());
assertEquals(9, cs2.getFont(wb).getFontHeightInPoints());
assertEquals(12, cs3.getFont(wb).getFontHeightInPoints());
assertEquals(15, cs1.getIndex());
assertEquals(23, cs2.getIndex());
assertEquals(24, cs3.getIndex());
assertNull(cs1.getParentStyle());
assertNotNull(cs2.getParentStyle());
assertNotNull(cs3.getParentStyle());
assertEquals(21, cs2.getParentStyle().getIndex());
assertEquals(22, cs3.getParentStyle().getIndex());
// Now check we can get style records for
// the parent ones
assertNull(wb.getWorkbook().getStyleRecord(15));
assertNull(wb.getWorkbook().getStyleRecord(23));
assertNull(wb.getWorkbook().getStyleRecord(24));
assertNotNull(wb.getWorkbook().getStyleRecord(21));
assertNotNull(wb.getWorkbook().getStyleRecord(22));
// Now check the style names
assertEquals(null, cs1.getUserStyleName());
assertEquals(null, cs2.getUserStyleName());
assertEquals(null, cs3.getUserStyleName());
assertEquals("style1", cs2.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);
HSSFSheet s = wb.getSheetAt(0);
HSSFCell c1 = s.getRow(0).getCell(0);
HSSFCell c2 = s.getRow(1).getCell(0);
HSSFCell c3 = s.getRow(2).getCell(0);
HSSFCellStyle cs1 = c1.getCellStyle();
HSSFCellStyle cs2 = c2.getCellStyle();
HSSFCellStyle cs3 = c3.getCellStyle();
assertNotNull(cs1);
assertNotNull(cs2);
assertNotNull(cs3);
// Check we got the styles we'd expect
assertEquals(10, cs1.getFont(wb).getFontHeightInPoints());
assertEquals(9, cs2.getFont(wb).getFontHeightInPoints());
assertEquals(12, cs3.getFont(wb).getFontHeightInPoints());
assertEquals(15, cs1.getIndex());
assertEquals(23, cs2.getIndex());
assertEquals(24, cs3.getIndex());
assertNull(cs1.getParentStyle());
assertNotNull(cs2.getParentStyle());
assertNotNull(cs3.getParentStyle());
assertEquals(21, cs2.getParentStyle().getIndex());
assertEquals(22, cs3.getParentStyle().getIndex());
// Now check we can get style records for
// the parent ones
assertNull(wb.getWorkbook().getStyleRecord(15));
assertNull(wb.getWorkbook().getStyleRecord(23));
assertNull(wb.getWorkbook().getStyleRecord(24));
assertNotNull(wb.getWorkbook().getStyleRecord(21));
assertNotNull(wb.getWorkbook().getStyleRecord(22));
// Now check the style names
assertEquals(null, cs1.getUserStyleName());
assertEquals(null, cs2.getUserStyleName());
assertEquals(null, cs3.getUserStyleName());
assertEquals("style1", cs2.getParentStyle().getUserStyleName());
assertEquals("style2", cs3.getParentStyle().getUserStyleName());
}
}

View File

@ -14,37 +14,18 @@
limitations under the License.
==================================================================== */
/*
* TestRowStyle.java
*
* Created on May 20, 2005
*/
package org.apache.poi.hssf.usermodel;
import java.io.IOException;
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.util.TempFile;
/**
* Class to test row styling functionality
*
* @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
*/
public class TestRowStyle
extends TestCase
{
/** Creates a new instance of TestCellStyle */
public TestRowStyle(String name)
{
super(name);
}
public final class TestRowStyle extends TestCase {
/**
* TEST NAME: Test Write Sheet Font <P>
@ -55,21 +36,17 @@ public class TestRowStyle
* HSSFSheet last row or first row is incorrect. <P>
*
*/
public void testWriteSheetFont()
throws IOException
{
public void testWriteSheetFont() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
HSSFRow r = null;
HSSFCell c = null;
HSSFFont fnt = wb.createFont();
HSSFCellStyle cs = wb.createCellStyle();
fnt.setColor(HSSFFont.COLOR_RED);
fnt.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
cs.setFont(fnt);
for (short rownum = ( short ) 0; rownum < 100; rownum++)
for (int rownum = 0; rownum < 100; rownum++)
{
r = s.createRow(rownum);
r.setRowStyle(cs);
@ -86,13 +63,11 @@ public class TestRowStyle
/**
* Tests that is creating a file with a date or an calendar works correctly.
*/
public void testDataStyle()
throws Exception
{
public void testDataStyle() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
HSSFCellStyle cs = wb.createCellStyle();
HSSFRow row = s.createRow((short)0);
HSSFRow row = s.createRow(0);
// with Date:
cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
@ -101,7 +76,7 @@ public class TestRowStyle
// with Calendar:
row = s.createRow((short)1);
row = s.createRow(1);
cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
row.setRowStyle(cs);
row.createCell(0);
@ -126,10 +101,7 @@ public class TestRowStyle
* HSSFSheet last row or first row is incorrect. <P>
*
*/
public void testWriteSheetStyle()
throws IOException
{
public void testWriteSheetStyle() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
HSSFRow r = null;
@ -148,7 +120,7 @@ public class TestRowStyle
cs2.setFillForegroundColor(( short ) 0x0);
cs2.setFillPattern(( short ) 1);
cs2.setFont(fnt);
for (short rownum = ( short ) 0; rownum < 100; rownum++)
for (int rownum = 0; rownum < 100; rownum++)
{
r = s.createRow(rownum);
r.setRowStyle(cs);
@ -171,7 +143,7 @@ public class TestRowStyle
s = wb.getSheetAt(0);
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);
assertNotNull("Row is not null", r);
@ -194,11 +166,4 @@ public class TestRowStyle
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);
}
}