]> source.dussan.org Git - poi.git/commitdiff
Fixed deprecated references to HSSFSheet.getRow(short) etc. Removed all deprecated...
authorJosh Micich <josh@apache.org>
Tue, 3 Feb 2009 01:19:13 +0000 (01:19 +0000)
committerJosh Micich <josh@apache.org>
Tue, 3 Feb 2009 01:19:13 +0000 (01:19 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@740179 13f79535-47bb-0310-9956-ffa450edef68

22 files changed:
src/examples/src/org/apache/poi/hssf/usermodel/examples/Alignment.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/BigExample.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/Borders.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/CellComments.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/CellTypes.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/CreateCells.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/CreateDateCells.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/FrillsAndFills.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/HyperlinkFormula.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/Hyperlinks.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/MergedCells.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/NewLinesInCells.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/NewSheet.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/OfficeDrawing.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/OfficeDrawingWithGraphics.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/Outlines.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/ReadWriteWorkbook.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/RepeatingRowsAndColumns.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/WorkingWithFonts.java
src/java/org/apache/poi/hssf/dev/HSSF.java
src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java
src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java

index bad05466b4ab17d369a539cb2d21f24f89f884d5..b54640ee737be65b12ede1ad576eae2f97b9bc99 100644 (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);
     }
 }
index 85894c64742c435d768bba28bda7fd507bc59ba3..3981a145daa07ee40fcef2c61a22a477d6bbda94 100644 (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
index d632cf18b217cfabd96590d80075db1b6ca490bf..d29635004adc336206fee6c0049dde4771ea7042 100644 (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.
index 7ec606fea3128bb8aaa27394b91aab2b64cb77c3..84efa9cd2d5a88a4a782dc87d1d4e5c73e3e39ae 100644 (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();
-
-
     }
 }
index dd6674762213ef99d194fe59f3291f9b43b8e9e4..07b9b0165a2e308d72e4d8657660b7ea96a970be 100644 (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");
index fb7a773320211426c728a13aecd17e2915ed5e45..ff8a0b73ca79748dc8bf15746610356618e131f3 100644 (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");
index fb7908ab8f32186202defb9196d55e578ff1f580..746fd536b8f87dd505830f7a50c1f6a80d6e4eeb 100644 (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();
-
     }
 }
index c4833715630909f5b5bc27de633406f19b2616d9..02b7cb3e3915501bd60652b7484d2af2ea3af00c 100644 (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);
 
index 81c505a0679813692a506267714bee1a514d4ce3..8ed9213bfaf47565cb7a58aefca30d49c0b73669 100644 (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();
-
     }
 }
index 24b3f186fc4d4f61376aca378d6f42ae65bab8bc..456df814865c0e56fd313d3cd5e8895ccd4f0c6f 100755 (executable)
@@ -1,4 +1,3 @@
-\r
 /* ====================================================================\r
    Licensed to the Apache Software Foundation (ASF) under one or more\r
    contributor license agreements.  See the NOTICE file distributed with\r
@@ -35,7 +34,7 @@ public class Hyperlinks {
         HSSFWorkbook wb = new HSSFWorkbook();\r
 \r
         //cell style for hyperlinks\r
-        //by default hypelrinks are blue and underlined\r
+        //by default hyperlinks are blue and underlined\r
         HSSFCellStyle hlink_style = wb.createCellStyle();\r
         HSSFFont hlink_font = wb.createFont();\r
         hlink_font.setUnderline(HSSFFont.U_SINGLE);\r
@@ -46,7 +45,7 @@ public class Hyperlinks {
         HSSFSheet sheet = wb.createSheet("Hyperlinks");\r
 \r
         //URL\r
-        cell = sheet.createRow(0).createCell((short)0);\r
+        cell = sheet.createRow(0).createCell(0);\r
         cell.setCellValue("URL Link");\r
         HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL);\r
         link.setAddress("http://poi.apache.org/");\r
@@ -54,7 +53,7 @@ public class Hyperlinks {
         cell.setCellStyle(hlink_style);\r
 \r
         //link to a file in the current directory\r
-        cell = sheet.createRow(1).createCell((short)0);\r
+        cell = sheet.createRow(1).createCell(0);\r
         cell.setCellValue("File Link");\r
         link = new HSSFHyperlink(HSSFHyperlink.LINK_FILE);\r
         link.setAddress("link1.xls");\r
@@ -62,7 +61,7 @@ public class Hyperlinks {
         cell.setCellStyle(hlink_style);\r
 \r
         //e-mail link\r
-        cell = sheet.createRow(2).createCell((short)0);\r
+        cell = sheet.createRow(2).createCell(0);\r
         cell.setCellValue("Email Link");\r
         link = new HSSFHyperlink(HSSFHyperlink.LINK_EMAIL);\r
         //note, if subject contains white spaces, make sure they are url-encoded\r
@@ -74,9 +73,9 @@ public class Hyperlinks {
 \r
         //create a target sheet and cell\r
         HSSFSheet sheet2 = wb.createSheet("Target Sheet");\r
-        sheet2.createRow(0).createCell((short)0).setCellValue("Target Cell");\r
+        sheet2.createRow(0).createCell(0).setCellValue("Target Cell");\r
 \r
-        cell = sheet.createRow(3).createCell((short)0);\r
+        cell = sheet.createRow(3).createCell(0);\r
         cell.setCellValue("Worksheet Link");\r
         link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);\r
         link.setAddress("'Target Sheet'!A1");\r
@@ -86,6 +85,5 @@ public class Hyperlinks {
         FileOutputStream out = new FileOutputStream("hssf-links.xls");\r
         wb.write(out);\r
         out.close();\r
-\r
     }\r
 }\r
index fa66d76f0a013fa14be0e96bc01ce5d6969680e1..31e5215b8e432489672f170b49e15e9da838b1bb 100644 (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
    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();
-
     }
 }
index e96dc23cab72bac288de0f60c26a2907b9e5cf95..7653a0b527b57f4749bff75dd336b1e702ba4cfd 100644 (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();
-
-        cs = wb.createCellStyle();
-
-        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();
-
+               HSSFSheet s = wb.createSheet();
+               HSSFRow r = null;
+               HSSFCell c = null;
+               HSSFCellStyle cs = wb.createCellStyle();
+               HSSFFont f2 = wb.createFont();
+
+               cs = wb.createCellStyle();
+
+               cs.setFont(f2);
+               // Word Wrap MUST be turned on
+               cs.setWrapText(true);
+
+               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();
     }
 }
index 960c0d9e5db42ed9e9b8c21141acc6cf22487300..5fdf2dd30d3c2129b6ef2dafd95644d86cae733e 100644 (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();
index 21319f873057056444998372b869a82a9f47e34d..1b580d35f013345d89499ebf233d4b9a0c8d54c6 100644 (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.
index 0fb72c65822a484dc965e691196df547a4f8816f..4de1207f429c7b60dce61dffe2155d038524bfa0 100644 (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 );
index 4d68f8071cf6c9c3bebdf8b8a1b3c53a25f91ec0..c04d608ed0642836267a7aaaf6b045432b09032c 100644 (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();
     }
-
-
 }
index 821950fac0faa81aaac67bb1fb410be4bf406c37..26bba44674d30310bd8ca82b564f49160d29d30d 100644 (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)
index e6fd1eb29bb06a4d155f09cdbc5b9e5d1191d492..df4e3bb64c60502f7b31e978ee509b37eace7f57 100644 (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
    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);
 
index 727674646799592c2098f9e376f05466c87d566b..6cb15941f218989f1cc0699f4620f3bd86bb8d58 100644 (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();
-
     }
 }
index c1af8a11e47eb2a878ee349e38c80853becff23d..fc1cd3880e3b8bf40db3470ab43888108ffc9420 100644 (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);
 
index a4cf005a0c2dbbe055392724e5fddb17693f8f83..17ad850d7f479188b8658a004b1806f41e5ef85c 100644 (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
    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.util.*;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.Date;
 
-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());
     }
 }
index 8cca078496b1e88c8740e8a658b5b87976e33620..36821e6a2485571d5d24e6b1b752b2f51702805e 100644 (file)
    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);
-    }
 }