]> source.dussan.org Git - poi.git/commitdiff
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-63924...
authorNick Burch <nick@apache.org>
Wed, 27 Aug 2008 10:34:33 +0000 (10:34 +0000)
committerNick Burch <nick@apache.org>
Wed, 27 Aug 2008 10:34:33 +0000 (10:34 +0000)
https://svn.apache.org/repos/asf/poi/trunk

........
  r687403 | nick | 2008-08-20 19:14:11 +0100 (Wed, 20 Aug 2008) | 1 line

  Make an initial start on hpbf code
........
  r687423 | nick | 2008-08-20 19:50:15 +0100 (Wed, 20 Aug 2008) | 1 line

  More HPBF stuff, and some tests
........
  r687429 | nick | 2008-08-20 20:40:05 +0100 (Wed, 20 Aug 2008) | 1 line

  Quill CONTENTS bits, and tests
........
  r687443 | nick | 2008-08-20 21:13:08 +0100 (Wed, 20 Aug 2008) | 1 line

  HPBF text extractor and unit tests
........
  r688426 | josh | 2008-08-23 23:47:51 +0100 (Sat, 23 Aug 2008) | 1 line

  Fix for bug 45672 - prevent MissingRecordAwareHSSFListener generating multiple LastCellOfRowDummyRecords when shared formulas are present
........
  r688642 | josh | 2008-08-25 08:56:37 +0100 (Mon, 25 Aug 2008) | 1 line

  JDK 1.4 fixes for new hpbf stuff. Some clean-up
........
  r688650 | josh | 2008-08-25 09:09:02 +0100 (Mon, 25 Aug 2008) | 1 line

  Initial support for evaluating external add-in functions like YEARFRAC
........
  r688655 | josh | 2008-08-25 09:30:54 +0100 (Mon, 25 Aug 2008) | 1 line

  Fix for bug 45682 - allow cloning of sheets with conditional formatting
........
  r688825 | josh | 2008-08-25 19:57:14 +0100 (Mon, 25 Aug 2008) | 1 line

  Fix for small bug introduced in c688655 - keep header field in sync with number of rules
........
  r688910 | josh | 2008-08-25 23:41:08 +0100 (Mon, 25 Aug 2008) | 1 line

  Replaced calls to deprecated versions of createCell(), getCell(), createRow(), and getRow(). (Changing short to int)
........

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@689435 13f79535-47bb-0310-9956-ffa450edef68

74 files changed:
src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFCellUtil.java
src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/dev/HSSF.java
src/java/org/apache/poi/hssf/eventusermodel/MissingRecordAwareHSSFListener.java
src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java
src/java/org/apache/poi/hssf/record/CFHeaderRecord.java
src/java/org/apache/poi/hssf/record/SupBookRecord.java
src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java
src/java/org/apache/poi/hssf/record/formula/NameXPtg.java
src/java/org/apache/poi/hssf/record/formula/atp/AnalysisToolPak.java [new file with mode: 0644]
src/java/org/apache/poi/hssf/record/formula/atp/YearFrac.java [new file with mode: 0644]
src/java/org/apache/poi/hssf/record/formula/atp/YearFracCalculator.java [new file with mode: 0644]
src/java/org/apache/poi/hssf/record/formula/eval/ExternalFunction.java
src/java/org/apache/poi/hssf/record/formula/eval/NameXEval.java [new file with mode: 0644]
src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
src/java/org/apache/poi/ss/usermodel/DateUtil.java
src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java
src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hpbf/extractor/PublisherTextExtractor.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hpbf/model/EscherStm.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hpbf/model/MainContents.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hpbf/model/qcbits/QCBit.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hpbf/model/qcbits/QCTextBit.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hpbf/model/qcbits/UnknownQCBit.java [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hpbf/TestHPBFDocument.java [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hpbf/data/Simple.pub [new file with mode: 0755]
src/scratchpad/testcases/org/apache/poi/hpbf/extractor/TextPublisherTextExtractor.java [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hpbf/model/TestEscherParts.java [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hpbf/model/TestQuillContents.java [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/data/ex45672.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/data/yearfracExamples.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java
src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java
src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java
src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java
src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java
src/testcases/org/apache/poi/hssf/record/formula/TestAreaErrPtg.java
src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java
src/testcases/org/apache/poi/hssf/record/formula/TestErrPtg.java
src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java
src/testcases/org/apache/poi/hssf/record/formula/TestIntersectionPtg.java
src/testcases/org/apache/poi/hssf/record/formula/TestPercentPtg.java
src/testcases/org/apache/poi/hssf/record/formula/TestRangePtg.java
src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java
src/testcases/org/apache/poi/hssf/record/formula/TestUnionPtg.java
src/testcases/org/apache/poi/hssf/record/formula/atp/TestYearFracCalculator.java [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/record/formula/atp/TestYearFracCalculatorFromSpreadsheet.java [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java
src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java
src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java
src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java
src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java
src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java
src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java
src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java

index 67f4b38cb531e594897a865a10a9045ee7838fe2..8f40ab391e0e33e8062fcda23c42697ee54f1932 100644 (file)
@@ -113,7 +113,7 @@ public final class HSSFCellUtil
 
         if ( cell == null )
         {
-            cell = row.createCell( (short)column );
+            cell = row.createCell(column );
         }
         return cell;
     }
index 62fee5b1c2e7e21fe809dad234e19d1c5f934a65..bfc44a828f2045f12c328a84409e6f88b4fa1237 100644 (file)
@@ -64,6 +64,9 @@
            <action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
         </release>
         <release version="3.1.1-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">45682 - Fix for cloning of CFRecordsAggregate</action>
+           <action dev="POI-DEVELOPERS" type="add">Initial support for evaluating external add-in functions like YEARFRAC</action>
+           <action dev="POI-DEVELOPERS" type="fix">45672 - Fix for MissingRecordAwareHSSFListener to prevent multiple LastCellOfRowDummyRecords when shared formulas are present</action>
            <action dev="POI-DEVELOPERS" type="fix">45645 - Fix for HSSFSheet.autoSizeColumn() for widths exceeding Short.MAX_VALUE</action>
            <action dev="POI-DEVELOPERS" type="add">45623 - Support for additional HSSF header and footer fields, including bold and full file path</action>
            <action dev="POI-DEVELOPERS" type="add">45623 - Support stripping HSSF header and footer fields (eg page number) out of header and footer text if required</action>
index 96272b165cc4c9e06080e1846a328eb6f83b2d7e..5ed54a515b910ef0b4b823b9bbdb5fcd6f2c4d90 100644 (file)
@@ -61,6 +61,9 @@
            <action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
         </release>
         <release version="3.1.1-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">45682 - Fix for cloning of CFRecordsAggregate</action>
+           <action dev="POI-DEVELOPERS" type="add">Initial support for evaluating external add-in functions like YEARFRAC</action>
+           <action dev="POI-DEVELOPERS" type="fix">45672 - Fix for MissingRecordAwareHSSFListener to prevent multiple LastCellOfRowDummyRecords when shared formulas are present</action>
            <action dev="POI-DEVELOPERS" type="fix">45645 - Fix for HSSFSheet.autoSizeColumn() for widths exceeding Short.MAX_VALUE</action>
            <action dev="POI-DEVELOPERS" type="add">45623 - Support for additional HSSF header and footer fields, including bold and full file path</action>
            <action dev="POI-DEVELOPERS" type="add">45623 - Support stripping HSSF header and footer fields (eg page number) out of header and footer text if required</action>
index 5297f0781f2374fe469e123dbeabfe9831804a66..6583b94c62c4f3b3688f8b2535090167744eff99 100644 (file)
@@ -132,7 +132,7 @@ public class HSSF
                 {
                     c.setCellStyle(cs);
                 }
-                c = r.createCell(( short ) (cellnum + 1),
+                c = r.createCell(cellnum + 1,
                                  HSSFCell.CELL_TYPE_STRING);
                 c.setCellValue(new HSSFRichTextString("TEST"));
                 s.setColumnWidth(( short ) (cellnum + 1),
@@ -347,7 +347,7 @@ public class HSSF
                     sheet.removeRow(row);
                 }
                 HSSFRow  row  = sheet.getRow(39);
-                HSSFCell cell = row.getCell(( short ) 3);
+                HSSFCell cell = row.getCell(3);
 
                 cell.setCellType(HSSFCell.CELL_TYPE_STRING);
                 cell.setCellValue("MODIFIED CELL!!!!!");
index 0bdcb1d3d9ddf0e26bd2dfe6eedb9ffed1774cd8..e41b0b92aea08917802ef8a48e43a3dcc03b58e9 100644 (file)
 
 package org.apache.poi.hssf.eventusermodel;
 
-import org.apache.poi.hssf.eventusermodel.HSSFListener;
 import org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord;
 import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord;
 import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingRowDummyRecord;
 import org.apache.poi.hssf.record.BOFRecord;
-import org.apache.poi.hssf.record.BlankRecord;
-import org.apache.poi.hssf.record.BoolErrRecord;
-import org.apache.poi.hssf.record.BoundSheetRecord;
-import org.apache.poi.hssf.record.FormulaRecord;
-import org.apache.poi.hssf.record.LabelRecord;
-import org.apache.poi.hssf.record.LabelSSTRecord;
+import org.apache.poi.hssf.record.CellValueRecordInterface;
 import org.apache.poi.hssf.record.NoteRecord;
-import org.apache.poi.hssf.record.NumberRecord;
-import org.apache.poi.hssf.record.RKRecord;
 import org.apache.poi.hssf.record.Record;
 import org.apache.poi.hssf.record.RowRecord;
+import org.apache.poi.hssf.record.SharedFormulaRecord;
 
 /**
  * <p>A HSSFListener which tracks rows and columns, and will
@@ -44,16 +37,16 @@ import org.apache.poi.hssf.record.RowRecord;
  *  file, or was skipped from being written as it was
  *  blank.
  */
-public class MissingRecordAwareHSSFListener implements HSSFListener {
+public final class MissingRecordAwareHSSFListener implements HSSFListener {
        private HSSFListener childListener;
        
        // Need to have different counters for cell rows and
        //  row rows, as you sometimes get a RowRecord in the
        //  middle of some cells, and that'd break everything
-       private int lastRowRow = -1;
+       private int lastRowRow;
        
-       private int lastCellRow = -1;
-       private int lastCellColumn = -1;
+       private int lastCellRow;
+       private int lastCellColumn;
        
        /**
         * Constructs a new MissingRecordAwareHSSFListener, which
@@ -62,128 +55,80 @@ public class MissingRecordAwareHSSFListener implements HSSFListener {
         * @param listener The HSSFListener to pass records on to
         */
        public MissingRecordAwareHSSFListener(HSSFListener listener) {
+               resetCounts();
                childListener = listener;
        }
 
        public void processRecord(Record record) {
-               int thisRow = -1;
-               int thisColumn = -1;
-               
-               switch (record.getSid())
-        {
-            // the BOFRecord can represent either the beginning of a sheet or the workbook
-            case BOFRecord.sid:
-                BOFRecord bof = (BOFRecord) record;
-                if (bof.getType() == bof.TYPE_WORKBOOK)
-                {
-                       // Reset the row and column counts - new workbook
-                       lastRowRow = -1;
-                       lastCellRow = -1;
-                       lastCellColumn = -1;
-                    //System.out.println("Encountered workbook");
-                } else if (bof.getType() == bof.TYPE_WORKSHEET)
-                {
-                       // Reset the row and column counts - new sheet
-                       lastRowRow = -1;
-                       lastCellRow = -1;
-                       lastCellColumn = -1;
-                    //System.out.println("Encountered sheet reference");
-                }
-                break;
-            case BoundSheetRecord.sid:
-                BoundSheetRecord bsr = (BoundSheetRecord) record;
-                //System.out.println("New sheet named: " + bsr.getSheetname());
-                break;
-            case RowRecord.sid:
-                RowRecord rowrec = (RowRecord) record;
-                //System.out.println("Row " + rowrec.getRowNumber() + " found, first column at "
-                //        + rowrec.getFirstCol() + " last column at " + rowrec.getLastCol());
-                
-                // If there's a jump in rows, fire off missing row records
-                if(lastRowRow+1 < rowrec.getRowNumber()) {
-                       for(int i=(lastRowRow+1); i<rowrec.getRowNumber(); i++) {
-                               MissingRowDummyRecord dr = new MissingRowDummyRecord(i);
-                               childListener.processRecord(dr);
-                       }
-                }
-                
-                // Record this as the last row we saw
-                lastRowRow = rowrec.getRowNumber();
-                break;
-                
-                
-            // These are all the "cell" records
-                
-            case BlankRecord.sid:
-               BlankRecord brec = (BlankRecord) record;
-                thisRow = brec.getRow();
-                thisColumn = brec.getColumn();
-                break;
-            case BoolErrRecord.sid:
-               BoolErrRecord berec = (BoolErrRecord) record;
-                thisRow = berec.getRow();
-                thisColumn = berec.getColumn();
-                break;
-            case FormulaRecord.sid:
-               FormulaRecord frec = (FormulaRecord) record;
-               thisRow = frec.getRow();
-               thisColumn = frec.getColumn();
-                break;
-            case LabelRecord.sid:
-               LabelRecord lrec = (LabelRecord) record;
-                thisRow = lrec.getRow();
-                thisColumn = lrec.getColumn();
-                //System.out.println("Cell found containing String "
-                //        + " at row " + lrec.getRow() + " and column " + lrec.getColumn());
-                break;
-            case LabelSSTRecord.sid:
-               LabelSSTRecord lsrec = (LabelSSTRecord) record;
-                thisRow = lsrec.getRow();
-                thisColumn = lsrec.getColumn();
-                //System.out.println("Cell found containing String "
-                //        + " at row " + lsrec.getRow() + " and column " + lsrec.getColumn());
-                break;
-            case NoteRecord.sid:
-               NoteRecord nrec = (NoteRecord) record;
-               thisRow = nrec.getRow();
-               thisColumn = nrec.getColumn();
-                break;
-            case NumberRecord.sid:
-                NumberRecord numrec = (NumberRecord) record;
-                thisRow = numrec.getRow();
-                thisColumn = numrec.getColumn();
-                //System.out.println("Cell found with value " + numrec.getValue()
-                //        + " at row " + numrec.getRow() + " and column " + numrec.getColumn());
-                break;
-            case RKRecord.sid:
-               RKRecord rkrec = (RKRecord) record;
-               thisRow = rkrec.getRow();
-               thisColumn = rkrec.getColumn();
-                break;
-            default:
-               //System.out.println(record.getClass());
-               break;
-        }
-               
+               int thisRow;
+               int thisColumn;
+
+
+               if (record instanceof CellValueRecordInterface) {
+                       CellValueRecordInterface valueRec = (CellValueRecordInterface) record;
+                       thisRow = valueRec.getRow();
+                       thisColumn = valueRec.getColumn();
+               } else {
+                       thisRow = -1;
+                       thisColumn = -1;
+
+                       switch (record.getSid()) {
+                               // the BOFRecord can represent either the beginning of a sheet or
+                               // the workbook
+                               case BOFRecord.sid:
+                                       BOFRecord bof = (BOFRecord) record;
+                                       if (bof.getType() == bof.TYPE_WORKBOOK || bof.getType() == bof.TYPE_WORKSHEET) {
+                                               // Reset the row and column counts - new workbook / worksheet
+                                               resetCounts();
+                                       }
+                                       break;
+                               case RowRecord.sid:
+                                       RowRecord rowrec = (RowRecord) record;
+                                       //System.out.println("Row " + rowrec.getRowNumber() + " found, first column at "
+                                       //        + rowrec.getFirstCol() + " last column at " + rowrec.getLastCol());
+
+                                       // If there's a jump in rows, fire off missing row records
+                                       if (lastRowRow + 1 < rowrec.getRowNumber()) {
+                                               for (int i = (lastRowRow + 1); i < rowrec.getRowNumber(); i++) {
+                                                       MissingRowDummyRecord dr = new MissingRowDummyRecord(i);
+                                                       childListener.processRecord(dr);
+                                               }
+                                       }
+
+                                       // Record this as the last row we saw
+                                       lastRowRow = rowrec.getRowNumber();
+                                       break;
+
+                               case SharedFormulaRecord.sid:
+                                       // SharedFormulaRecord occurs after the first FormulaRecord of the cell range.
+                                       // There are probably (but not always) more cell records after this
+                                       // - so don't fire off the LastCellOfRowDummyRecord yet
+                                       childListener.processRecord(record);
+                                       return;
+                               case NoteRecord.sid:
+                                       NoteRecord nrec = (NoteRecord) record;
+                                       thisRow = nrec.getRow();
+                                       thisColumn = nrec.getColumn();
+                                       break;
+                       }
+               }
                // If we're on cells, and this cell isn't in the same
                //  row as the last one, then fire the 
-               //  dummy end-of-row records?
+               //  dummy end-of-row records
                if(thisRow != lastCellRow && lastCellRow > -1) {
                        for(int i=lastCellRow; i<thisRow; i++) {
                                int cols = -1;
                                if(i == lastCellRow) {
                                        cols = lastCellColumn;
                                }
-                               LastCellOfRowDummyRecord r = new LastCellOfRowDummyRecord(i, cols);
-                               childListener.processRecord(r);
+                               childListener.processRecord(new LastCellOfRowDummyRecord(i, cols));
                        }
                }
                
                // If we've just finished with the cells, then fire the
-               //  final dummy end-of-row record
+               // final dummy end-of-row record
                if(lastCellRow != -1 && lastCellColumn != -1 && thisRow == -1) {
-                       LastCellOfRowDummyRecord r = new LastCellOfRowDummyRecord(lastCellRow, lastCellColumn);
-                       childListener.processRecord(r);
+                       childListener.processRecord(new LastCellOfRowDummyRecord(lastCellRow, lastCellColumn));
                        
                        lastCellRow = -1;
                        lastCellColumn = -1;
@@ -196,11 +141,10 @@ public class MissingRecordAwareHSSFListener implements HSSFListener {
                }
                
                // If there's a gap in the cells, then fire
-               //  the dummy cell records?
-               if(lastCellColumn != (thisColumn-1)) {
+               //  the dummy cell records
+               if(lastCellColumn != thisColumn-1) {
                        for(int i=lastCellColumn+1; i<thisColumn; i++) {
-                               MissingCellDummyRecord r = new MissingCellDummyRecord(thisRow, i);
-                               childListener.processRecord(r);
+                               childListener.processRecord(new MissingCellDummyRecord(thisRow, i));
                        }
                }
                
@@ -209,7 +153,13 @@ public class MissingRecordAwareHSSFListener implements HSSFListener {
                        lastCellColumn = thisColumn;
                        lastCellRow = thisRow;
                }
-               
+
                childListener.processRecord(record);
        }
+
+       private void resetCounts() {
+               lastRowRow = -1;
+               lastCellRow = -1;
+               lastCellColumn = -1;
+       }
 }
index f3089b70b7c70aefd957132cc1cc2aab6d64f4fb..0381a0457341b544a8006ea21d58e9b73befdbb2 100644 (file)
@@ -107,7 +107,7 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p
                                int firstCell = row.getFirstCellNum();
                                int lastCell = row.getLastCellNum();
                                for(int k=firstCell;k<lastCell;k++) {
-                                       HSSFCell cell = row.getCell((short)k);
+                                       HSSFCell cell = row.getCell(k);
                                        boolean outputContents = false;
                                        if(cell == null) { continue; }
                                        
index 862adc9c5936df7200e22d6d35b31813347a1c89..7ecc7f6f8fe87f3bfd3933bbd5c18b186863cd0c 100644 (file)
@@ -40,11 +40,11 @@ public final class CFHeaderRecord extends Record {
        {
                field_4_cell_ranges = new CellRangeAddressList();
        }
-       public CFHeaderRecord(CellRangeAddress[] regions)
-       {
+       public CFHeaderRecord(CellRangeAddress[] regions, int nRules) {
                CellRangeAddress[] unmergedRanges = regions;
                CellRangeAddress[] mergeCellRanges = CellRangeUtil.mergeCellRanges(unmergedRanges);
                setCellRanges(mergeCellRanges);
+               field_1_numcf = nRules;
        }
 
        public CFHeaderRecord(RecordInputStream in)
index cb4eff84068fe709ae9a98ab9f7262135323e0aa..c75e2db8944fef9f3231c29b5ecf1cf1ae3d1129 100644 (file)
@@ -150,6 +150,7 @@ public final class SupBookRecord extends Record {
             sb.append("Internal References ");
             sb.append(" nSheets= ").append(field_1_number_of_sheets);
         }
+        sb.append("]");
         return sb.toString();
     }
     private int getDataSize() {
index 9fd2412a98de225d7560e1a409bdbff068dc57c0..d3a3a673e05e45c4f79000610fbb67aac27170c0 100644 (file)
 package org.apache.poi.hssf.record.aggregates;
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.poi.hssf.model.RecordStream;
 import org.apache.poi.hssf.record.CFHeaderRecord;
 import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.Record;
-import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.ss.util.Region;
 import org.apache.poi.ss.util.CellRangeAddress;
 
@@ -37,12 +35,10 @@ import org.apache.poi.ss.util.CellRangeAddress;
  * @author Dmitriy Kumshayev
  *
  */
-public final class CFRecordsAggregate extends Record {
+public final class CFRecordsAggregate extends RecordAggregate {
        /** Excel allows up to 3 conditional formating rules */
        private static final int MAX_CONDTIONAL_FORMAT_RULES = 3;
 
-       public final static short sid = -2008; // not a real BIFF record
-
        private final CFHeaderRecord header;
 
        /** List of CFRuleRecord objects */
@@ -59,6 +55,9 @@ public final class CFRecordsAggregate extends Record {
                        throw new IllegalArgumentException("No more than " 
                                        + MAX_CONDTIONAL_FORMAT_RULES + " rules may be specified");
                }
+               if (pRules.length != pHeader.getNumberOfConditionalFormats()) {
+                       throw new RuntimeException("Mismatch number of rules");
+               }
                header = pHeader;
                rules = new ArrayList(3);
                for (int i = 0; i < pRules.length; i++) {
@@ -67,7 +66,7 @@ public final class CFRecordsAggregate extends Record {
        }
 
        public CFRecordsAggregate(CellRangeAddress[] regions, CFRuleRecord[] rules) {
-               this(new CFHeaderRecord(regions), rules);
+               this(new CFHeaderRecord(regions, rules.length), rules);
        }
 
        /**
@@ -108,45 +107,6 @@ public final class CFRecordsAggregate extends Record {
                return new CFRecordsAggregate((CFHeaderRecord) header.clone(), newRecs);
        }
 
-       protected void fillFields(RecordInputStream in)
-       {
-            // You never fill an aggregate record
-       }
-
-       public short getSid()
-       {
-               return sid;
-       }
-
-       /**
-        * called by the class that is responsible for writing this sucker.
-        * Subclasses should implement this so that their data is passed back in a
-        * byte array.
-        *
-        * @param offset to begin writing at
-        * @param data byte array containing instance data
-        * @return number of bytes written
-        */
-
-       public int serialize(int offset, byte[] data)
-       {
-               int nRules = rules.size();
-               header.setNumberOfConditionalFormats(nRules);
-
-               int pos = offset;
-
-               pos += header.serialize(pos, data);
-               for(int i=0; i< nRules; i++) {
-                       pos += getRule(i).serialize(pos, data);
-               }
-               return pos - offset;
-       }
-
-       protected void validateSid(short id)
-       {
-               // do nothing here
-       }
-
        /**
         * @return the header. Never <code>null</code>.
         */
@@ -166,10 +126,16 @@ public final class CFRecordsAggregate extends Record {
                return (CFRuleRecord) rules.get(idx);
        }
        public void setRule(int idx, CFRuleRecord r) {
+               if (r == null) {
+                       throw new IllegalArgumentException("r must not be null");
+               }
                checkRuleIndex(idx);
                rules.set(idx, r);
        }
        public void addRule(CFRuleRecord r) {
+               if (r == null) {
+                       throw new IllegalArgumentException("r must not be null");
+               }
                if(rules.size() >= MAX_CONDTIONAL_FORMAT_RULES) {
                        throw new IllegalStateException("Cannot have more than " 
                                        + MAX_CONDTIONAL_FORMAT_RULES + " conditional format rules");
@@ -181,26 +147,6 @@ public final class CFRecordsAggregate extends Record {
                return rules.size();
        }
 
-       /**
-        *  @return sum of sizes of all aggregated records
-        */
-       public int getRecordSize() 
-       {
-               int size = 0;
-               if( header != null)
-               {
-                       size += header.getRecordSize();
-               }
-               if( rules != null)
-               {
-                       for(Iterator irecs = rules.iterator(); irecs.hasNext(); )
-                       {
-                               size += (( Record ) irecs.next()).getRecordSize();
-                       }
-               }
-               return size;
-       }
-
        /**
         * String representation of CFRecordsAggregate
         */
@@ -216,12 +162,17 @@ public final class CFRecordsAggregate extends Record {
                for(int i=0; i<rules.size(); i++)
                {
                        CFRuleRecord cfRule = (CFRuleRecord)rules.get(i);
-                       if(cfRule!=null)
-                       {
-                               buffer.append(cfRule.toString());
-                       }
+                       buffer.append(cfRule.toString());
                }
                buffer.append("[/CF]\n");
                return buffer.toString();
        }
+
+       public void visitContainedRecords(RecordVisitor rv) {
+               rv.visitRecord(header);
+               for(int i=0; i<rules.size(); i++) {
+                       CFRuleRecord rule = (CFRuleRecord)rules.get(i);
+                       rv.visitRecord(rule);
+               }
+       }
 }
index 34e9ca837f0d0e81149d09a03bda8f3dec6adc66..d748c412023da40fda00f749e06e80a61dd2edf8 100644 (file)
@@ -22,7 +22,6 @@ import java.util.List;
 
 import org.apache.poi.hssf.model.RecordStream;
 import org.apache.poi.hssf.record.CFHeaderRecord;
-import org.apache.poi.hssf.record.Record;
 
 /**
  * Holds all the conditional formatting for a workbook sheet.<p/>
@@ -53,7 +52,8 @@ public final class ConditionalFormattingTable extends RecordAggregate {
 
        public void visitContainedRecords(RecordVisitor rv) {
                for (int i = 0; i < _cfHeaders.size(); i++) {
-                       rv.visitRecord((Record) _cfHeaders.get(i));
+                       CFRecordsAggregate subAgg = (CFRecordsAggregate) _cfHeaders.get(i);
+                       subAgg.visitContainedRecords(rv);
                }
        }
 
index b6076e1ea8adf75880955f2e4716ad202f5ef970..393a8cd69053c6600e978e007a45bf1f5ff3c999 100644 (file)
@@ -30,11 +30,11 @@ public final class NameXPtg extends OperandPtg {
        private final static int SIZE = 7;
 
        /** index to REF entry in externsheet record */
-       private int _sheetRefIndex;
+       private final int _sheetRefIndex;
        /** index to defined name or externname table(1 based) */
-       private int _nameNumber;
+       private final int _nameNumber;
        /** reserved must be 0 */
-       private int _reserved;
+       private final int _reserved;
 
        private NameXPtg(int sheetRefIndex, int nameNumber, int reserved) {
                _sheetRefIndex = sheetRefIndex;
@@ -73,4 +73,11 @@ public final class NameXPtg extends OperandPtg {
        public byte getDefaultOperandClass() {
                return Ptg.CLASS_VALUE;
        }
+
+       public int getSheetRefIndex() {
+               return _sheetRefIndex;
+       }
+       public int getNameIndex() {
+               return _nameNumber - 1;
+       }
 }
diff --git a/src/java/org/apache/poi/hssf/record/formula/atp/AnalysisToolPak.java b/src/java/org/apache/poi/hssf/record/formula/atp/AnalysisToolPak.java
new file mode 100644 (file)
index 0000000..e5ec7fa
--- /dev/null
@@ -0,0 +1,154 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.formula.atp;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.functions.FreeRefFunction;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+
+public final class AnalysisToolPak {
+
+       private static final FreeRefFunction NotImplemented = new FreeRefFunction() {
+
+               public ValueEval evaluate(Eval[] args, int srcCellRow, short srcCellCol,
+                               Workbook workbook, Sheet sheet) {
+                       return ErrorEval.FUNCTION_NOT_IMPLEMENTED;
+               }
+       };
+       
+       private static Map _functionsByName = createFunctionsMap();
+
+       private AnalysisToolPak() {
+               // no instances of this class
+       }
+
+       public static FreeRefFunction findFunction(String name) {
+               return (FreeRefFunction)_functionsByName.get(name);
+       }
+       
+       private static Map createFunctionsMap() {
+               Map m = new HashMap(100);
+
+               r(m, "ACCRINT", null);
+               r(m, "ACCRINTM", null);
+               r(m, "AMORDEGRC", null);
+               r(m, "AMORLINC", null);
+               r(m, "BESSELI", null);
+               r(m, "BESSELJ", null);
+               r(m, "BESSELK", null);
+               r(m, "BESSELY", null);
+               r(m, "BIN2DEC", null);
+               r(m, "BIN2HEX", null);
+               r(m, "BIN2OCT", null);
+               r(m, "CO MPLEX", null);
+               r(m, "CONVERT", null);
+               r(m, "COUPDAYBS", null);
+               r(m, "COUPDAYS", null);
+               r(m, "COUPDAYSNC", null);
+               r(m, "COUPNCD", null);
+               r(m, "COUPNUM", null);
+               r(m, "COUPPCD", null);
+               r(m, "CUMIPMT", null);
+               r(m, "CUMPRINC", null);
+               r(m, "DEC2BIN", null);
+               r(m, "DEC2HEX", null);
+               r(m, "DEC2OCT", null);
+               r(m, "DELTA", null);
+               r(m, "DISC", null);
+               r(m, "DOLLARDE", null);
+               r(m, "DOLLARFR", null);
+               r(m, "DURATION", null);
+               r(m, "EDATE", null);
+               r(m, "EFFECT", null);
+               r(m, "EOMONTH", null);
+               r(m, "ERF", null);
+               r(m, "ERFC", null);
+               r(m, "FACTDOUBLE", null);
+               r(m, "FVSCHEDULE", null);
+               r(m, "GCD", null);
+               r(m, "GESTEP", null);
+               r(m, "HEX2BIN", null);
+               r(m, "HEX2DEC", null);
+               r(m, "HEX2OCT", null);
+               r(m, "IMABS", null);
+               r(m, "IMAGINARY", null);
+               r(m, "IMARGUMENT", null);
+               r(m, "IMCONJUGATE", null);
+               r(m, "IMCOS", null);
+               r(m, "IMDIV", null);
+               r(m, "IMEXP", null);
+               r(m, "IMLN", null);
+               r(m, "IMLOG10", null);
+               r(m, "IMLOG2", null);
+               r(m, "IMPOWER", null);
+               r(m, "IMPRODUCT", null);
+               r(m, "IMREAL", null);
+               r(m, "IMSIN", null);
+               r(m, "IMSQRT", null);
+               r(m, "IMSUB", null);
+               r(m, "IMSUM", null);
+               r(m, "INTRATE", null);
+               r(m, "ISEVEN", null);
+               r(m, "ISODD", null);
+               r(m, "LCM", null);
+               r(m, "MDURATION", null);
+               r(m, "MROUND", null);
+               r(m, "MULTINOMIAL", null);
+               r(m, "NETWORKDAYS", null);
+               r(m, "NOMINAL", null);
+               r(m, "OCT2BIN", null);
+               r(m, "OCT2DEC", null);
+               r(m, "OCT2HEX", null);
+               r(m, "ODDFPRICE", null);
+               r(m, "ODDFYIELD", null);
+               r(m, "ODDLPRICE", null);
+               r(m, "ODDLYIELD", null);
+               r(m, "PRICE", null);
+               r(m, "PRICEDISC", null);
+               r(m, "PRICEMAT", null);
+               r(m, "QUOTIENT", null);
+               r(m, "RAND BETWEEN", null);
+               r(m, "RECEIVED", null);
+               r(m, "SERIESSUM", null);
+               r(m, "SQRTPI", null);
+               r(m, "TBILLEQ", null);
+               r(m, "TBILLPRICE", null);
+               r(m, "TBILLYIELD", null);
+               r(m, "WEEKNUM", null);
+               r(m, "WORKDAY", null);
+               r(m, "XIRR", null);
+               r(m, "XNPV", null);
+               r(m, "YEARFRAC", YearFrac.instance);
+               r(m, "YIELD", null);
+               r(m, "YIELDDISC", null);
+               r(m, "YIELDMAT", null);
+               
+               return m;
+       }
+
+       private static void r(Map m, String functionName, FreeRefFunction pFunc) {
+               FreeRefFunction func = pFunc == null ? NotImplemented : pFunc;
+               m.put(functionName, func);
+       }
+}
diff --git a/src/java/org/apache/poi/hssf/record/formula/atp/YearFrac.java b/src/java/org/apache/poi/hssf/record/formula/atp/YearFrac.java
new file mode 100644 (file)
index 0000000..517189d
--- /dev/null
@@ -0,0 +1,160 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.formula.atp;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.regex.Pattern;
+
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.EvaluationException;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.OperandResolver;
+import org.apache.poi.hssf.record.formula.eval.StringEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.functions.FreeRefFunction;
+import org.apache.poi.ss.usermodel.DateUtil;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+/**
+ * Implementation of Excel 'Analysis ToolPak' function YEARFRAC()<br/>
+ * 
+ * Returns the fraction of the year spanned by two dates.<p/>
+ * 
+ * <b>Syntax</b><br/>
+ * <b>YEARFRAC</b>(<b>startDate</b>, <b>endDate</b>, basis)<p/>
+ * 
+ * The <b>basis</b> optionally specifies the behaviour of YEARFRAC as follows:
+ * 
+ * <table border="0" cellpadding="1" cellspacing="0" summary="basis parameter description">
+ *   <tr><th>Value</th><th>Days per Month</th><th>Days per Year</th></tr>
+ *   <tr align='center'><td>0 (default)</td><td>30</td><td>360</td></tr>
+ *   <tr align='center'><td>1</td><td>actual</td><td>actual</td></tr>
+ *   <tr align='center'><td>2</td><td>actual</td><td>360</td></tr>
+ *   <tr align='center'><td>3</td><td>actual</td><td>365</td></tr>
+ *   <tr align='center'><td>4</td><td>30</td><td>360</td></tr>
+ * </table>
+ * 
+ */
+final class YearFrac implements FreeRefFunction {
+
+       public static final FreeRefFunction instance = new YearFrac();
+       
+       private YearFrac() {
+               // enforce singleton
+       }
+
+       public ValueEval evaluate(Eval[] args, int srcCellRow, short srcCellCol, Workbook workbook,
+                       Sheet sheet) {
+
+               double result;
+               try {
+                       int basis = 0; // default
+                       switch(args.length) {
+                               case 3:
+                                       basis = evaluateIntArg(args[2], srcCellRow, srcCellCol);
+                               case 2:
+                                       break;
+                               default:
+                                       return ErrorEval.VALUE_INVALID;  
+                       }
+                       double startDateVal = evaluateDateArg(args[0], srcCellRow, srcCellCol);
+                       double endDateVal = evaluateDateArg(args[1], srcCellRow, srcCellCol);
+                       result = YearFracCalculator.calculate(startDateVal, endDateVal, basis);
+               } catch (EvaluationException e) {
+                       return e.getErrorEval();
+               }
+               
+               return new NumberEval(result);
+       }
+
+       private static double evaluateDateArg(Eval arg, int srcCellRow, short srcCellCol) throws EvaluationException {
+               ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
+
+               if (ve instanceof StringEval) {
+                       String strVal = ((StringEval) ve).getStringValue();
+                       Double dVal = OperandResolver.parseDouble(strVal);
+                       if (dVal != null) {
+                               return dVal.doubleValue();
+                       }
+                       Calendar date = parseDate(strVal);
+                       return DateUtil.getExcelDate(date, false);
+               }
+               return OperandResolver.coerceValueToDouble(ve);
+       }
+
+       private static Calendar parseDate(String strVal) throws EvaluationException {
+               String[] parts = Pattern.compile("/").split(strVal);
+               if (parts.length != 3) {
+                       throw new EvaluationException(ErrorEval.VALUE_INVALID);
+               }
+               String part2 = parts[2];
+               int spacePos = part2.indexOf(' ');
+               if (spacePos > 0) {
+                       // drop time portion if present
+                       part2 = part2.substring(0, spacePos);
+               }
+               int f0;
+               int f1;
+               int f2;
+               try {
+                       f0 = Integer.parseInt(parts[0]);
+                       f1 = Integer.parseInt(parts[1]);
+                       f2 = Integer.parseInt(part2);
+               } catch (NumberFormatException e) {
+                       throw new EvaluationException(ErrorEval.VALUE_INVALID);
+               }
+               if (f0<0 || f1<0 || f2<0 || f0>12 || f1>12 || f2>12) {
+                       // easy to see this cannot be a valid date
+                       throw new EvaluationException(ErrorEval.VALUE_INVALID);
+               }
+               
+               if (f0 >= 1900 && f0 < 9999) {
+                       // when 4 digit value appears first, the format is YYYY/MM/DD, regardless of OS settings
+                       return makeDate(f0, f1, f2);
+               }
+               // otherwise the format seems to depend on OS settings (default date format)
+               if (false) {
+                       // MM/DD/YYYY is probably a good guess, if the in the US
+                       return makeDate(f2, f0, f1);
+               }
+               // TODO - find a way to choose the correct date format
+               throw new RuntimeException("Unable to determine date format for text '" + strVal + "'");
+       }
+
+       /**
+        * @param month 1-based
+        */
+       private static Calendar makeDate(int year, int month, int day) throws EvaluationException {
+               if (month < 1 || month > 12) {
+                       throw new EvaluationException(ErrorEval.VALUE_INVALID);
+               }
+               Calendar cal = new GregorianCalendar(year, month-1, 1, 0, 0, 0);
+               cal.set(Calendar.MILLISECOND, 0);
+               if (day <1 || day>cal.getActualMaximum(Calendar.DAY_OF_MONTH)) {
+                       throw new EvaluationException(ErrorEval.VALUE_INVALID);
+               }
+               return cal;
+       }
+
+       private static int evaluateIntArg(Eval arg, int srcCellRow, short srcCellCol) throws EvaluationException {
+               ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
+               return OperandResolver.coerceValueToInt(ve);
+       }
+}
diff --git a/src/java/org/apache/poi/hssf/record/formula/atp/YearFracCalculator.java b/src/java/org/apache/poi/hssf/record/formula/atp/YearFracCalculator.java
new file mode 100644 (file)
index 0000000..40a5eb8
--- /dev/null
@@ -0,0 +1,344 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.formula.atp;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.TimeZone;
+
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.EvaluationException;
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
+
+
+/**
+ * Internal calculation methods for Excel 'Analysis ToolPak' function YEARFRAC()<br/>
+ *  
+ * Algorithm inspired by www.dwheeler.com/yearfrac
+ * 
+ * @author Josh Micich
+ */
+final class YearFracCalculator {
+       /** use UTC time-zone to avoid daylight savings issues */
+       private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone("UTC");
+       private static final int MS_PER_HOUR = 60 * 60 * 1000;
+       private static final int MS_PER_DAY = 24 * MS_PER_HOUR;
+       private static final int DAYS_PER_NORMAL_YEAR = 365;
+       private static final int DAYS_PER_LEAP_YEAR = DAYS_PER_NORMAL_YEAR + 1;
+
+       /** the length of normal long months i.e. 31 */
+       private static final int LONG_MONTH_LEN = 31;
+       /** the length of normal short months i.e. 30 */
+       private static final int SHORT_MONTH_LEN = 30;
+       private static final int SHORT_FEB_LEN = 28;
+       private static final int LONG_FEB_LEN = SHORT_FEB_LEN + 1;
+
+       private YearFracCalculator() {
+               // no instances of this class
+       }
+
+
+       public static double calculate(double pStartDateVal, double pEndDateVal, int basis) throws EvaluationException {
+
+               if (basis < 0 || basis >= 5) {
+                       // if basis is invalid the result is #NUM!
+                       throw new EvaluationException(ErrorEval.NUM_ERROR);
+               }
+
+               // common logic for all bases
+
+               // truncate day values
+               int startDateVal = (int) Math.floor(pStartDateVal);
+               int endDateVal = (int) Math.floor(pEndDateVal);
+               if (startDateVal == endDateVal) {
+                       // when dates are equal, result is zero 
+                       return 0;
+               }
+               // swap start and end if out of order
+               if (startDateVal > endDateVal) {
+                       int temp = startDateVal;
+                       startDateVal = endDateVal;
+                       endDateVal = temp;
+               }
+
+               switch (basis) {
+                       case 0: return basis0(startDateVal, endDateVal);
+                       case 1: return basis1(startDateVal, endDateVal);
+                       case 2: return basis2(startDateVal, endDateVal);
+                       case 3: return basis3(startDateVal, endDateVal);
+                       case 4: return basis4(startDateVal, endDateVal);
+               }
+               throw new IllegalStateException("cannot happen");
+       }
+
+
+       /**
+        * @param startDateVal assumed to be less than or equal to endDateVal
+        * @param endDateVal assumed to be greater than or equal to startDateVal
+        */
+       public static double basis0(int startDateVal, int endDateVal) {
+               SimpleDate startDate = createDate(startDateVal);
+               SimpleDate endDate = createDate(endDateVal);
+               int date1day = startDate.day;
+               int date2day = endDate.day;
+
+               // basis zero has funny adjustments to the day-of-month fields when at end-of-month 
+               if (date1day == LONG_MONTH_LEN && date2day == LONG_MONTH_LEN) {
+                       date1day = SHORT_MONTH_LEN;
+                       date2day = SHORT_MONTH_LEN;
+               } else if (date1day == LONG_MONTH_LEN) {
+                       date1day = SHORT_MONTH_LEN;
+               } else if (date1day == SHORT_MONTH_LEN && date2day == LONG_MONTH_LEN) {
+                       date2day = SHORT_MONTH_LEN;
+                       // Note: If date2day==31, it STAYS 31 if date1day < 30.
+                       // Special fixes for February:
+               } else if (startDate.month == 2 && isLastDayOfMonth(startDate)) {
+                       // Note - these assignments deliberately set Feb 30 date.
+                       date1day = SHORT_MONTH_LEN;
+                       if (endDate.month == 2 && isLastDayOfMonth(endDate)) {
+                               // only adjusted when first date is last day in Feb
+                               date2day = SHORT_MONTH_LEN;
+                       }
+               }
+               return calculateAdjusted(startDate, endDate, date1day, date2day);
+       }
+       /**
+        * @param startDateVal assumed to be less than or equal to endDateVal
+        * @param endDateVal assumed to be greater than or equal to startDateVal
+        */
+       public static double basis1(int startDateVal, int endDateVal) {
+               SimpleDate startDate = createDate(startDateVal);
+               SimpleDate endDate = createDate(endDateVal);
+               double yearLength;
+               if (isGreaterThanOneYear(startDate, endDate)) {
+                       yearLength = averageYearLength(startDate.year, endDate.year);
+               } else if (shouldCountFeb29(startDate, endDate)) {
+                       yearLength = DAYS_PER_LEAP_YEAR;
+               } else {
+                       yearLength = DAYS_PER_NORMAL_YEAR;
+               }
+               return dateDiff(startDate.tsMilliseconds, endDate.tsMilliseconds) / yearLength;
+       }
+
+       /**
+        * @param startDateVal assumed to be less than or equal to endDateVal
+        * @param endDateVal assumed to be greater than or equal to startDateVal
+        */
+       public static double basis2(int startDateVal, int endDateVal) {
+               return (endDateVal - startDateVal) / 360.0;
+       }
+       /**
+        * @param startDateVal assumed to be less than or equal to endDateVal
+        * @param endDateVal assumed to be greater than or equal to startDateVal
+        */
+       public static double basis3(double startDateVal, double endDateVal) {
+               return (endDateVal - startDateVal) / 365.0;
+       }
+       /**
+        * @param startDateVal assumed to be less than or equal to endDateVal
+        * @param endDateVal assumed to be greater than or equal to startDateVal
+        */
+       public static double basis4(int startDateVal, int endDateVal) {
+               SimpleDate startDate = createDate(startDateVal);
+               SimpleDate endDate = createDate(endDateVal);
+               int date1day = startDate.day;
+               int date2day = endDate.day;
+
+
+               // basis four has funny adjustments to the day-of-month fields when at end-of-month 
+               if (date1day == LONG_MONTH_LEN) {
+                       date1day = SHORT_MONTH_LEN;
+               }
+               if (date2day == LONG_MONTH_LEN) {
+                       date2day = SHORT_MONTH_LEN;
+               }
+               // Note - no adjustments for end of Feb
+               return calculateAdjusted(startDate, endDate, date1day, date2day);
+       }
+
+
+       private static double calculateAdjusted(SimpleDate startDate, SimpleDate endDate, int date1day,
+                       int date2day) {
+               double dayCount 
+                       = (endDate.year - startDate.year) * 360
+                       + (endDate.month - startDate.month) * SHORT_MONTH_LEN
+                       + (date2day - date1day) * 1;
+               return dayCount / 360;
+       }
+
+       private static boolean isLastDayOfMonth(SimpleDate date) {
+               if (date.day < SHORT_FEB_LEN) {
+                       return false;
+               }
+               return date.day == getLastDayOfMonth(date);
+       }
+
+       private static int getLastDayOfMonth(SimpleDate date) {
+               switch (date.month) {
+                       case 1:
+                       case 3:
+                       case 5:
+                       case 7:
+                       case 8:
+                       case 10:
+                       case 12:
+                               return LONG_MONTH_LEN;
+                       case 4:
+                       case 6:
+                       case 9:
+                       case 11:
+                               return SHORT_MONTH_LEN;
+               }
+               if (isLeapYear(date.year)) {
+                       return LONG_FEB_LEN;
+               }
+               return SHORT_FEB_LEN;
+       }
+
+       /**
+        * Assumes dates are no more than 1 year apart.
+        * @return <code>true</code> if dates both within a leap year, or span a period including Feb 29
+        */
+       private static boolean shouldCountFeb29(SimpleDate start, SimpleDate end) {
+               boolean startIsLeapYear = isLeapYear(start.year);
+               if (startIsLeapYear && start.year == end.year) {
+                       // note - dates may not actually span Feb-29, but it gets counted anyway in this case
+                       return true;
+               }
+
+               boolean endIsLeapYear = isLeapYear(end.year);
+               if (!startIsLeapYear && !endIsLeapYear) {
+                       return false;
+               }
+               if (startIsLeapYear) {
+                       switch (start.month) {
+                               case SimpleDate.JANUARY:
+                               case SimpleDate.FEBRUARY:
+                                       return true;
+                       }
+                       return false;
+               }
+               if (endIsLeapYear) {
+                       switch (end.month) {
+                               case SimpleDate.JANUARY:
+                                       return false;
+                               case SimpleDate.FEBRUARY:
+                                       break;
+                               default:
+                                       return true;
+                       }
+                       return end.day == LONG_FEB_LEN;
+               }
+               return false;
+       }
+
+       /**
+        * @return the whole number of days between the two time-stamps.  Both time-stamps are
+        * assumed to represent 12:00 midnight on the respective day.
+        */
+       private static int dateDiff(long startDateMS, long endDateMS) {
+               long msDiff = endDateMS - startDateMS;
+
+               // some extra checks to make sure we don't hide some other bug with the rounding 
+               int remainderHours = (int) ((msDiff % MS_PER_DAY) / MS_PER_HOUR);
+               switch (remainderHours) {
+                       case 0:  // normal case
+                               break;
+                       case 1:  // transition from normal time to daylight savings adjusted
+                       case 23: // transition from daylight savings adjusted to normal time
+                               // Unexpected since we are using UTC_TIME_ZONE 
+                       default:
+                               throw new RuntimeException("Unexpected date diff between " + startDateMS + " and " + endDateMS);
+
+               }
+               return (int) (0.5 + ((double)msDiff / MS_PER_DAY));
+       }
+
+       private static double averageYearLength(int startYear, int endYear) {
+               int dayCount = 0;
+               for (int i=startYear; i<=endYear; i++) {
+                       dayCount += DAYS_PER_NORMAL_YEAR;
+                       if (isLeapYear(i)) {
+                               dayCount++;
+                       }
+               }
+               double numberOfYears = endYear-startYear+1;
+               return dayCount / numberOfYears;
+       }
+
+       private static boolean isLeapYear(int i) {
+               // leap years are always divisible by 4
+               if (i % 4 != 0) {
+                       return false;
+               }
+               // each 4th century is a leap year
+               if (i % 400 == 0) {
+                       return true;
+               }
+               // all other centuries are *not* leap years
+               if (i % 100 == 0) {
+                       return false;
+               }
+               return true;
+       }
+
+       private static boolean isGreaterThanOneYear(SimpleDate start, SimpleDate end) {
+               if (start.year == end.year) {
+                       return false;
+               }
+               if (start.year + 1 != end.year) {
+                       return true;
+               }
+
+               if (start.month > end.month) {
+                       return false;
+               }
+               if (start.month < end.month) {
+                       return true;
+               }
+
+               return start.day < end.day;
+       }
+
+       private static SimpleDate createDate(int dayCount) {
+               GregorianCalendar calendar = new GregorianCalendar(UTC_TIME_ZONE);
+               HSSFDateUtil.setCalendar(calendar, dayCount, 0, false);
+               return new SimpleDate(calendar);
+       }
+
+       private static final class SimpleDate {
+
+               public static final int JANUARY = 1;
+               public static final int FEBRUARY = 2;
+
+               public final int year;
+               /** 1-based month */
+               public final int month;
+               /** day of month */
+               public final int day;
+               /** milliseconds since 1970 */
+               public long tsMilliseconds;
+
+               public SimpleDate(Calendar cal) {
+                       year = cal.get(Calendar.YEAR);
+                       month = cal.get(Calendar.MONTH) + 1;
+                       day = cal.get(Calendar.DAY_OF_MONTH);
+                       tsMilliseconds = cal.getTimeInMillis();
+               }
+       }
+}
index f40c83202e1ba57f6774c870baa6a44907e65559..ffaf780ab65092b95a484a20145a3c7bf7217bc1 100755 (executable)
 
 package org.apache.poi.hssf.record.formula.eval;
 
+import org.apache.poi.hssf.record.formula.atp.AnalysisToolPak;
 import org.apache.poi.hssf.record.formula.functions.FreeRefFunction;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 /**
  * 
- * Common entry point for all external functions (where 
+ * Common entry point for all user-defined (non-built-in) functions (where 
  * <tt>AbstractFunctionPtg.field_2_fnc_index</tt> == 255)
  * 
+ * TODO rename to UserDefinedFunction
  * @author Josh Micich
  */
 final class ExternalFunction implements FreeRefFunction {
@@ -36,27 +38,43 @@ final class ExternalFunction implements FreeRefFunction {
                        throw new RuntimeException("function name argument missing");
                }
                
-               if (!(args[0] instanceof NameEval)) {
-                       throw new RuntimeException("First argument should be a NameEval, but got ("
-                                       + args[0].getClass().getName() + ")");
-               }
-               NameEval functionNameEval = (NameEval) args[0];
-               
-               int nOutGoingArgs = nIncomingArgs -1;
-               Eval[] outGoingArgs = new Eval[nOutGoingArgs];
-               System.arraycopy(args, 1, outGoingArgs, 0, nOutGoingArgs);
-               
+               Eval nameArg = args[0];
                FreeRefFunction targetFunc;
                try {
-                       targetFunc = findTargetFunction(workbook, functionNameEval);
+                       if (nameArg instanceof NameEval) {
+                               targetFunc = findInternalUserDefinedFunction(workbook, (NameEval) nameArg);
+                       } else if (nameArg instanceof NameXEval) {
+                               targetFunc = findExternalUserDefinedFunction(workbook, (NameXEval) nameArg);
+                       } else {
+                               throw new RuntimeException("First argument should be a NameEval, but got ("
+                                               + nameArg.getClass().getName() + ")");
+                       }
                } catch (EvaluationException e) {
                        return e.getErrorEval();
                }
-               
+               int nOutGoingArgs = nIncomingArgs -1;
+               Eval[] outGoingArgs = new Eval[nOutGoingArgs];
+               System.arraycopy(args, 1, outGoingArgs, 0, nOutGoingArgs);
                return targetFunc.evaluate(outGoingArgs, srcCellRow, srcCellCol, workbook, sheet);
        }
 
-       private FreeRefFunction findTargetFunction(Workbook workbook, NameEval functionNameEval) throws EvaluationException {
+       private FreeRefFunction findExternalUserDefinedFunction(Workbook workbook,
+                       NameXEval n) throws EvaluationException {
+               String functionName = workbook.resolveNameXText(n.getSheetRefIndex(), n.getNameNumber());
+
+               if(false) {
+                       System.out.println("received call to external user defined function (" + functionName + ")");
+               }
+               // currently only looking for functions from the 'Analysis TookPak'
+               // not sure how much this logic would need to change to support other or multiple add-ins.
+               FreeRefFunction result = AnalysisToolPak.findFunction(functionName);
+               if (result != null) {
+                       return result;
+               }
+               throw new EvaluationException(ErrorEval.FUNCTION_NOT_IMPLEMENTED);
+       }
+
+       private FreeRefFunction findInternalUserDefinedFunction(Workbook workbook, NameEval functionNameEval) throws EvaluationException {
 
                int numberOfNames = workbook.getNumberOfNames();
                
@@ -68,7 +86,7 @@ final class ExternalFunction implements FreeRefFunction {
                
                String functionName = workbook.getNameName(nameIndex);
                if(false) {
-                       System.out.println("received call to external function index (" + functionName + ")");
+                       System.out.println("received call to internal user defined function  (" + functionName + ")");
                }
                // TODO - detect if the NameRecord corresponds to a named range, function, or something undefined
                // throw the right errors in these cases
@@ -77,5 +95,5 @@ final class ExternalFunction implements FreeRefFunction {
                
                throw new EvaluationException(ErrorEval.FUNCTION_NOT_IMPLEMENTED);
        }
-
 }
+
diff --git a/src/java/org/apache/poi/hssf/record/formula/eval/NameXEval.java b/src/java/org/apache/poi/hssf/record/formula/eval/NameXEval.java
new file mode 100644 (file)
index 0000000..12b6be3
--- /dev/null
@@ -0,0 +1,49 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.formula.eval;
+
+/**
+ * @author Josh Micich
+ */
+public final class NameXEval implements Eval {
+
+       /** index to REF entry in externsheet record */
+       private final int _sheetRefIndex;
+       /** index to defined name or externname table(1 based) */
+       private final int _nameNumber;
+
+       public NameXEval(int sheetRefIndex, int nameNumber) {
+               _sheetRefIndex = sheetRefIndex;
+               _nameNumber = nameNumber;
+       }
+
+       public int getSheetRefIndex() {
+               return _sheetRefIndex;
+       }
+       public int getNameNumber() {
+               return _nameNumber;
+       }
+
+       public String toString() {
+               StringBuffer sb = new StringBuffer(64);
+               sb.append(getClass().getName()).append(" [");
+               sb.append(_sheetRefIndex).append(", ").append(_nameNumber);
+               sb.append("]");
+               return sb.toString();
+       }
+}
index 10d86015aa6f8dc4d2ebbf7040abf14de043f4e4..fc34b9da9c693ab7c8560f4511c022ac98c70868 100644 (file)
@@ -41,6 +41,12 @@ public final class HSSFConditionalFormattingRule
        private final HSSFWorkbook workbook;
 
        HSSFConditionalFormattingRule(HSSFWorkbook pWorkbook, CFRuleRecord pRuleRecord) {
+               if (pWorkbook == null) {
+                       throw new IllegalArgumentException("pWorkbook must not be null");
+               }
+               if (pRuleRecord == null) {
+                       throw new IllegalArgumentException("pRuleRecord must not be null");
+               }
                workbook = pWorkbook;
                cfRuleRecord = pRuleRecord;
        }
index dff82a732efc4ccbda1ff891691ef1b087b4a2a2..4e351e6ade282073ec3ae953ab7a4d66b469e4ab 100644 (file)
@@ -349,7 +349,7 @@ public final class HSSFRow implements Comparable, Row {
         }
         if(policy == CREATE_NULL_AS_BLANK) {
             if(cell == null) {
-                return createCell((short)cellnum, HSSFCell.CELL_TYPE_BLANK);
+                return createCell(cellnum, HSSFCell.CELL_TYPE_BLANK);
             }
             return cell;
         }
index 3e51fe831753266c850803e04aeb526a1b964dd5..280284439b267b6b70762cd985be2a3e47824386 100644 (file)
@@ -1836,7 +1836,7 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet
         //  new HSSFComment instances, which is bad
         HSSFRow r = getRow(row);
         if(r != null) {
-            HSSFCell c = r.getCell((short)column);
+            HSSFCell c = r.getCell(column);
             if(c != null) {
                 return c.getCellComment();
             } else {
index 002b4aedc1fd647e45df9126d8acec0d67f27eea..d457489096a02b136506d511a0a506e25fd3bd22 100644 (file)
@@ -158,9 +158,16 @@ public class DateUtil {
         if (!isValidExcelDate(date)) {
             return null;
         }
+        int wholeDays = (int)Math.floor(date);
+        int millisecondsInDay = (int)((date - wholeDays) * DAY_MILLISECONDS + 0.5);
+        Calendar calendar = new GregorianCalendar(); // using default time-zone
+        setCalendar(calendar, wholeDays, millisecondsInDay, use1904windowing);
+        return calendar.getTime();
+    }        
+    public static void setCalendar(Calendar calendar, int wholeDays, 
+            int millisecondsInDay, boolean use1904windowing) {
         int startYear = 1900;
         int dayAdjust = -1; // Excel thinks 2/29/1900 is a valid date, which it isn't
-        int wholeDays = (int)Math.floor(date);
         if (use1904windowing) {
             startYear = 1904;
             dayAdjust = 1; // 1904 date windowing uses 1/2/1904 as the first day
@@ -170,12 +177,8 @@ public class DateUtil {
             // If Excel date == 2/29/1900, will become 3/1/1900 in Java representation
             dayAdjust = 0;
         }
-        GregorianCalendar calendar = new GregorianCalendar(startYear,0,
-                                                 wholeDays + dayAdjust);
-        int millisecondsInDay = (int)((date - Math.floor(date)) *
-                                      DAY_MILLISECONDS + 0.5);
+        calendar.set(startYear,0, wholeDays + dayAdjust, 0, 0, 0);
         calendar.set(GregorianCalendar.MILLISECOND, millisecondsInDay);
-        return calendar.getTime();
     }
 
     /**
index 22321ff9e102a039486cce417b3d11d51b5eb872..9cd7f918e4ed69138286d734516804ec5a2766c9 100644 (file)
@@ -50,6 +50,7 @@ import org.apache.poi.hssf.record.formula.eval.ErrorEval;
 import org.apache.poi.hssf.record.formula.eval.Eval;
 import org.apache.poi.hssf.record.formula.eval.FunctionEval;
 import org.apache.poi.hssf.record.formula.eval.NameEval;
+import org.apache.poi.hssf.record.formula.eval.NameXEval;
 import org.apache.poi.hssf.record.formula.eval.NumberEval;
 import org.apache.poi.hssf.record.formula.eval.OperationEval;
 import org.apache.poi.hssf.record.formula.eval.Ref2DEval;
@@ -348,7 +349,8 @@ public class FormulaEvaluator {
                 continue; 
             }
             if (ptg instanceof NameXPtg) {
-                // TODO - external functions
+                NameXPtg nameXPtg = (NameXPtg) ptg;
+                stack.push(new NameXEval(nameXPtg.getSheetRefIndex(), nameXPtg.getNameIndex()));
                 continue;
             }
             if (ptg instanceof UnknownPtg) { continue; }
diff --git a/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java b/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java
new file mode 100644 (file)
index 0000000..49de0d0
--- /dev/null
@@ -0,0 +1,86 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hpbf;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.poi.POIDocument;
+import org.apache.poi.hpbf.model.EscherDelayStm;
+import org.apache.poi.hpbf.model.EscherStm;
+import org.apache.poi.hpbf.model.MainContents;
+import org.apache.poi.hpbf.model.QuillContents;
+import org.apache.poi.poifs.filesystem.DirectoryNode;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+
+/**
+ * This class provides the basic functionality 
+ *  for HPBF, our implementation of the publisher
+ *  file format. 
+ */
+public final class HPBFDocument extends POIDocument {
+       private MainContents mainContents;
+       private QuillContents quillContents;
+       private EscherStm escherStm;
+       private EscherDelayStm escherDelayStm;
+       
+       /**
+        * Opens a new publisher document
+        */
+       public HPBFDocument(POIFSFileSystem fs) throws IOException {
+               this(fs.getRoot(), fs);
+       }
+       public HPBFDocument(InputStream inp) throws IOException {
+               this(new POIFSFileSystem(inp));
+       }
+       
+       /**
+        * Opens an embeded publisher document,
+        *  at the given directory.
+        */
+       public HPBFDocument(DirectoryNode dir, POIFSFileSystem fs) throws IOException {
+               super(dir, fs);
+               
+               // Go looking for our interesting child
+               //  streams
+               mainContents = new MainContents(dir);
+               quillContents = new QuillContents(dir);
+               
+               // Now the Escher bits
+               escherStm = new EscherStm(dir);
+               escherDelayStm = new EscherDelayStm(dir);
+       }
+
+       public MainContents getMainContents() {
+               return mainContents;
+       }
+       public QuillContents getQuillContents() {
+               return quillContents;
+       }
+       public EscherStm getEscherStm() {
+               return escherStm;
+       }
+       public EscherDelayStm getEscherDelayStm() {
+               return escherDelayStm;
+       }
+       
+       public void write(OutputStream out) throws IOException {
+               throw new IllegalStateException("Writing is not yet implemented, see http://poi.apache.org/hpbf/");
+       }
+}
diff --git a/src/scratchpad/src/org/apache/poi/hpbf/extractor/PublisherTextExtractor.java b/src/scratchpad/src/org/apache/poi/hpbf/extractor/PublisherTextExtractor.java
new file mode 100644 (file)
index 0000000..2257283
--- /dev/null
@@ -0,0 +1,78 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hpbf.extractor;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.poi.POIOLE2TextExtractor;
+import org.apache.poi.hpbf.HPBFDocument;
+import org.apache.poi.hpbf.model.qcbits.QCBit;
+import org.apache.poi.hpbf.model.qcbits.QCTextBit;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+
+/**
+ * Extract text from HPBF Publisher files 
+ */
+public class PublisherTextExtractor extends POIOLE2TextExtractor {
+       private HPBFDocument doc;
+       
+       public PublisherTextExtractor(HPBFDocument doc) {
+               super(doc);
+               this.doc = doc;
+       }
+       public PublisherTextExtractor(POIFSFileSystem fs) throws IOException {
+               this(new HPBFDocument(fs));
+       }
+       public PublisherTextExtractor(InputStream is) throws IOException {
+               this(new POIFSFileSystem(is));
+       }
+       
+       public String getText() {
+               StringBuffer text = new StringBuffer();
+               
+               // Get the text from the Quill Contents
+               QCBit[] bits = doc.getQuillContents().getBits();
+               for(int i=0; i<bits.length; i++) {
+                       if(bits[i] != null && bits[i] instanceof QCTextBit) {
+                               QCTextBit t = (QCTextBit)bits[i];
+                               text.append( t.getText().replace('\r', '\n') );
+                       }
+               }
+               
+               // Get more text
+               // TODO
+               
+               return text.toString();
+       }
+       
+       
+       public static void main(String[] args) throws Exception {
+               if(args.length == 0) {
+                       System.err.println("Use:");
+                       System.err.println("  PublisherTextExtractor <file.pub>");
+               }
+               
+               for(int i=0; i<args.length; i++) {
+                       PublisherTextExtractor te = new PublisherTextExtractor(
+                                       new FileInputStream(args[i])
+                       );
+                       System.out.println(te.getText());
+               }
+       }
+}
diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java b/src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java
new file mode 100644 (file)
index 0000000..0324846
--- /dev/null
@@ -0,0 +1,30 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hpbf.model;
+
+import java.io.IOException;
+
+import org.apache.poi.poifs.filesystem.DirectoryNode;
+
+public final class EscherDelayStm extends EscherPart {
+       private static final String[] PATH = { "Escher", "EscherDelayStm", };
+
+       public EscherDelayStm(DirectoryNode baseDir) throws IOException {
+               super(baseDir, PATH);
+       }
+}
diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java b/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java
new file mode 100644 (file)
index 0000000..00e685f
--- /dev/null
@@ -0,0 +1,80 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hpbf.model;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.apache.poi.ddf.DefaultEscherRecordFactory;
+import org.apache.poi.ddf.EscherRecord;
+import org.apache.poi.poifs.filesystem.DirectoryNode;
+
+/**
+ * Parent class of all Escher parts
+ */
+public abstract class EscherPart extends HPBFPart {
+       private EscherRecord[] records;
+       
+       /**
+        * Creates the Escher Part, and finds our child
+        *  escher records
+        */
+       public EscherPart(DirectoryNode baseDir, String[] parts) throws IOException {
+               super(baseDir, parts);
+               
+               // Now create our Escher children
+               DefaultEscherRecordFactory erf = 
+                       new DefaultEscherRecordFactory();
+               
+               ArrayList ec = new ArrayList();
+               int left = data.length;
+               while(left > 0) {
+                       EscherRecord er = erf.createRecord(data, 0);
+                       er.fillFields(data, 0, erf);
+                       left -= er.getRecordSize();
+                       
+                       ec.add(er);
+               }
+               
+               records = (EscherRecord[])
+                       ec.toArray(new EscherRecord[ec.size()]);
+       }
+       
+       public EscherRecord[] getEscherRecords() {
+               return records;
+       }
+       
+       /**
+        * Serialises our Escher children back
+        *  into bytes.
+        */
+       protected void generateData() {
+               int size = 0;
+               for(int i=0; i<records.length; i++) {
+                       size += records[i].getRecordSize(); 
+               }
+               
+               data = new byte[size];
+               size = 0;
+               for(int i=0; i<records.length; i++) {
+                       int thisSize = 
+                               records[i].serialize(size, data);
+                       size += thisSize;
+               }
+       }
+}
diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/EscherStm.java b/src/scratchpad/src/org/apache/poi/hpbf/model/EscherStm.java
new file mode 100644 (file)
index 0000000..2ed79ea
--- /dev/null
@@ -0,0 +1,29 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hpbf.model;
+
+import java.io.IOException;
+
+import org.apache.poi.poifs.filesystem.DirectoryNode;
+
+public final class EscherStm extends EscherPart {
+       private static final String[] PATH = { "Escher", "EscherStm", };
+       public EscherStm(DirectoryNode baseDir) throws IOException {
+               super(baseDir, PATH);
+       }
+}
diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java b/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java
new file mode 100644 (file)
index 0000000..9db15c6
--- /dev/null
@@ -0,0 +1,104 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hpbf.model;
+
+import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import org.apache.poi.poifs.filesystem.DirectoryNode;
+import org.apache.poi.poifs.filesystem.DocumentEntry;
+
+/**
+ * Parent class of all HPBF sub-parts, handling
+ *  the fiddly reading in / writing out bits
+ *  for all of them.
+ */
+public abstract class HPBFPart {
+       protected byte[] data;
+       /**
+        * @param path  the path to the part, eg Contents or Quill, QuillSub, CONTENTS
+        */
+       public HPBFPart(DirectoryNode baseDir, String[] path) throws IOException {
+                
+               DirectoryNode dir = getDir(path, baseDir);
+               String name = path[path.length-1];
+               
+               DocumentEntry docProps;
+               try {
+                       docProps = (DocumentEntry)dir.getEntry(name);
+               } catch (FileNotFoundException e) {
+                       throw new IllegalArgumentException("File invalid - failed to find document entry '" 
+                                       + name + "'");
+               }
+
+               // Grab the data from the part stream
+               data = new byte[docProps.getSize()];
+               dir.createDocumentInputStream(name).read(data);
+       }
+       private DirectoryNode getDir(String[] path, DirectoryNode baseDir) {
+               DirectoryNode dir = baseDir;
+               for(int i=0; i<path.length-1; i++) {
+                       try {
+                               dir = (DirectoryNode)dir.getEntry(path[i]);
+                       } catch (FileNotFoundException e) {
+                               throw new IllegalArgumentException("File invalid - failed to find directory entry '" 
+                                               + path[i] + "'");
+                       }
+               }
+               return dir;
+       }
+       
+       public void writeOut(DirectoryNode baseDir) throws IOException {
+               String[] path = getPath();
+               
+               // Ensure that all parent directories exist
+               DirectoryNode dir = baseDir;
+               for(int i=0; i<path.length-1; i++) {
+                       try {
+                               dir = (DirectoryNode)dir.getEntry(path[i]);
+                       } catch(FileNotFoundException e) {
+                               dir.createDirectory(path[i]);
+                       }
+               }
+               
+               // Update the byte array with the latest data
+               generateData();
+               
+               // Write out
+               ByteArrayInputStream bais = new ByteArrayInputStream(data);
+               dir.createDocument(path[path.length-1], bais);
+       }
+       
+       /**
+        * Called just before writing out, to trigger
+        *  the data byte array to be updated with the
+        *  latest contents.
+        */
+       protected abstract void generateData();
+       
+       /**
+        * Returns the raw data that makes up
+        *  this document part.
+        */
+       public byte[] getData() { return data; }
+
+       /**
+        * Returns
+        */
+       public final String[] getPath() {return null;}
+}
diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/MainContents.java b/src/scratchpad/src/org/apache/poi/hpbf/model/MainContents.java
new file mode 100644 (file)
index 0000000..9783ebd
--- /dev/null
@@ -0,0 +1,38 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hpbf.model;
+
+import java.io.IOException;
+
+import org.apache.poi.poifs.filesystem.DirectoryNode;
+
+/**
+ * The main Contents. Not yet understood
+ */
+public final class MainContents extends HPBFPart {
+       private static final String[] PATH = { "Contents", };
+       
+       public MainContents(DirectoryNode baseDir) throws IOException {
+               super(baseDir, PATH);
+       }
+
+       protected void generateData() {
+               // We don't parse the contents, so
+               //  nothing will have changed
+       }
+}
diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java b/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java
new file mode 100644 (file)
index 0000000..ae626fc
--- /dev/null
@@ -0,0 +1,87 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hpbf.model;
+
+import java.io.IOException;
+
+import org.apache.poi.hpbf.model.qcbits.QCBit;
+import org.apache.poi.hpbf.model.qcbits.QCTextBit;
+import org.apache.poi.hpbf.model.qcbits.UnknownQCBit;
+import org.apache.poi.poifs.filesystem.DirectoryNode;
+import org.apache.poi.util.LittleEndian;
+
+/**
+ * Quill -> QuillSub -> CONTENTS
+ */
+public final class QuillContents extends HPBFPart {
+       private static final String[] PATH = { "Quill", "QuillSub", "CONTENTS", };
+       private QCBit[] bits;
+       
+       public QuillContents(DirectoryNode baseDir) throws IOException {
+               super(baseDir, PATH);
+               
+               // Now parse the first 512 bytes, and produce
+               //  all our bits
+               
+               // Check first 8 bytes
+               String f8 = new String(data, 0, 8);
+               if(! f8.equals("CHNKINK ")) {
+                       throw new IllegalArgumentException("Expecting 'CHNKINK ' but was '"+f8+"'");
+               }
+               // Ignore the next 24, for now at least
+               
+               // Now, parse all our QC Bits
+               bits = new QCBit[20];
+               for(int i=0; i<20; i++) {
+                       int offset = 0x20 + i*24;
+                       if(data[offset] == 0x18 && data[offset+1] == 0x00) {
+                               // Has some data
+                               String thingType = new String(data, offset+2, 4);
+                               int optA = LittleEndian.getUShort(data, offset+6);
+                               int optB = LittleEndian.getUShort(data, offset+8);
+                               int optC = LittleEndian.getUShort(data, offset+10);
+                               String bitType = new String(data, offset+12, 4);
+                               int from = (int)LittleEndian.getUInt(data, offset+16);
+                               int len = (int)LittleEndian.getUInt(data, offset+20);
+                               
+                               byte[] bitData = new byte[len];
+                               System.arraycopy(data, from, bitData, 0, len);
+                               
+                               // Create
+                               if(bitType.equals("TEXT")) {
+                                       bits[i] = new QCTextBit(thingType, bitType, bitData);
+                               } else {
+                                       bits[i] = new UnknownQCBit(thingType, bitType, bitData);
+                               }
+                               bits[i].setOptA(optA);
+                               bits[i].setOptB(optB);
+                               bits[i].setOptC(optC);
+                       } else {
+                               // Doesn't have data
+                       }
+               }
+       }
+
+       public QCBit[] getBits() {
+               return bits;
+       }
+       
+       protected void generateData() {
+               // TODO
+               throw new IllegalStateException("Not done yet!");
+       }
+}
diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/qcbits/QCBit.java b/src/scratchpad/src/org/apache/poi/hpbf/model/qcbits/QCBit.java
new file mode 100644 (file)
index 0000000..61c7955
--- /dev/null
@@ -0,0 +1,69 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hpbf.model.qcbits;
+
+/**
+ * Parent of all Quill CONTENTS bits
+ */
+public abstract class QCBit {
+       protected String thingType;
+       protected String bitType;
+       protected byte[] data;
+       
+       protected int optA;
+       protected int optB;
+       protected int optC;
+       
+       public QCBit(String thingType, String bitType, byte[] data) {
+               this.thingType = thingType;
+               this.bitType = bitType;
+               this.data = data;
+       }
+       
+       /**
+        * Returns the type of the thing, eg TEXT, FONT
+        *  or TOKN
+        */
+       public String getThingType() { return thingType; }
+       /**
+        * Returns the type of the bit data, eg TEXT
+        *  or PLC
+        */
+       public String getBitType() { return bitType; }
+       public byte[] getData() { return data; }
+
+       public int getOptA() {
+               return optA;
+       }
+       public void setOptA(int optA) {
+               this.optA = optA;
+       }
+
+       public int getOptB() {
+               return optB;
+       }
+       public void setOptB(int optB) {
+               this.optB = optB;
+       }
+
+       public int getOptC() {
+               return optC;
+       }
+       public void setOptC(int optC) {
+               this.optC = optC;
+       }
+}
diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/qcbits/QCTextBit.java b/src/scratchpad/src/org/apache/poi/hpbf/model/qcbits/QCTextBit.java
new file mode 100644 (file)
index 0000000..e3c8dcb
--- /dev/null
@@ -0,0 +1,43 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hpbf.model.qcbits;
+
+import org.apache.poi.util.StringUtil;
+
+/**
+ * A Text based bit of Quill Contents
+ */
+public class QCTextBit extends QCBit {
+       public QCTextBit(String thingType, String bitType, byte[] data) {
+               super(thingType, bitType, data);
+       }
+
+       /**
+        * Returns the text. Note that line endings
+        *  are \r and not \n
+        */
+       public String getText() {
+               return StringUtil.getFromUnicodeLE(
+                               data, 0, data.length/2
+               );
+       }
+       
+       public void setText(String text) {
+               data = new byte[text.length()*2];
+               StringUtil.putUnicodeLE(text, data, 0);
+       }
+}
diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/qcbits/UnknownQCBit.java b/src/scratchpad/src/org/apache/poi/hpbf/model/qcbits/UnknownQCBit.java
new file mode 100644 (file)
index 0000000..2548b4f
--- /dev/null
@@ -0,0 +1,27 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hpbf.model.qcbits;
+
+/**
+ * Any Quill Contents bits we don't know
+ *  how to handle explicitly
+ */
+public class UnknownQCBit extends QCBit {
+       public UnknownQCBit(String thingType, String bitType, byte[] data) {
+               super(thingType, bitType, data);
+       }
+}
diff --git a/src/scratchpad/testcases/org/apache/poi/hpbf/TestHPBFDocument.java b/src/scratchpad/testcases/org/apache/poi/hpbf/TestHPBFDocument.java
new file mode 100644 (file)
index 0000000..c0186dd
--- /dev/null
@@ -0,0 +1,60 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hpbf;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import junit.framework.TestCase;
+
+public class TestHPBFDocument extends TestCase {
+       private String dir;
+
+       protected void setUp() throws Exception {
+               dir = System.getProperty("HPBF.testdata.path");
+       }
+
+       public void testOpen() throws Exception {
+               File f = new File(dir, "Sample.pub");
+               HPBFDocument doc = new HPBFDocument(
+                               new FileInputStream(f)
+               );
+               
+               assertNotNull(doc);
+       }
+       
+       public void testBits() throws Exception {
+               File f = new File(dir, "Sample.pub");
+               HPBFDocument doc = new HPBFDocument(
+                               new FileInputStream(f)
+               );
+
+               assertNotNull(doc.getMainContents());
+               assertNotNull(doc.getQuillContents());
+               assertNotNull(doc.getEscherStm());
+               assertNotNull(doc.getEscherDelayStm());
+               
+               assertTrue(doc.getMainContents().getData().length > 0);
+               assertTrue(doc.getQuillContents().getData().length > 0);
+               assertTrue(doc.getEscherStm().getData().length > 0);
+               assertTrue(doc.getEscherDelayStm().getData().length == 0);
+       }
+       
+       // TODO
+//     public void testWrite() throws Exception {
+//     }
+}
diff --git a/src/scratchpad/testcases/org/apache/poi/hpbf/data/Simple.pub b/src/scratchpad/testcases/org/apache/poi/hpbf/data/Simple.pub
new file mode 100755 (executable)
index 0000000..2397b9d
Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hpbf/data/Simple.pub differ
diff --git a/src/scratchpad/testcases/org/apache/poi/hpbf/extractor/TextPublisherTextExtractor.java b/src/scratchpad/testcases/org/apache/poi/hpbf/extractor/TextPublisherTextExtractor.java
new file mode 100644 (file)
index 0000000..96396e1
--- /dev/null
@@ -0,0 +1,105 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hpbf.extractor;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.poi.hpbf.HPBFDocument;
+
+import junit.framework.TestCase;
+
+public class TextPublisherTextExtractor extends TestCase {
+       private String dir;
+
+       protected void setUp() throws Exception {
+               dir = System.getProperty("HPBF.testdata.path");
+       }
+
+       public void testBasics() throws Exception {
+               File f = new File(dir, "Sample.pub");
+               HPBFDocument doc = new HPBFDocument(
+                               new FileInputStream(f)
+               );
+
+               PublisherTextExtractor ext = 
+                       new PublisherTextExtractor(doc);
+               ext.getText();
+               
+               f = new File(dir, "Simple.pub");
+               ext = new PublisherTextExtractor(
+                               new FileInputStream(f)
+               );
+               ext.getText();
+       }
+       
+       public void testContents() throws Exception {
+               File f = new File(dir, "Sample.pub");
+               HPBFDocument doc = new HPBFDocument(
+                               new FileInputStream(f)
+               );
+
+               PublisherTextExtractor ext = 
+                       new PublisherTextExtractor(doc);
+               String text = ext.getText();
+               
+               assertEquals(
+"This is some text on the first page\n" +
+"It’s in times new roman, font size 10, all normal\n" +
+"" +
+"This is in bold and italic\n" +
+"It’s Arial, 20 point font\n" +
+"It’s in the second textbox on the first page\n" +
+"" +
+"This is the second page\n\n" +
+"" +
+"It is also times new roman, 10 point\n" +
+"" +
+"Table on page 2\nTop right\n" +
+"P2 table left\nP2 table right\n" +
+"Bottom Left\nBottom Right\n" +
+"" +
+"This text is on page two\n" +
+"#This is a link to Apache POI\n" +
+"More normal text\n" +
+"Link to a file\n" +
+"" +
+"More text, more hyperlinks\n" +
+"email link\n" +
+"Final hyperlink\n" +
+"Within doc to page 1\n"
+                               , text
+               );
+               
+               // Now a simpler one
+               f = new File(dir, "Simple.pub");
+               ext = new PublisherTextExtractor(
+                               new FileInputStream(f)
+               );
+               text = ext.getText();
+               assertEquals(
+"0123456789\n" +
+"0123456789abcdef\n" +
+"0123456789abcdef0123456789abcdef\n" +
+"0123456789\n" +
+"0123456789abcdef\n" +
+"0123456789abcdef0123456789abcdef\n" +
+"0123456789abcdef0123456789abcdef0123456789abcdef\n"
+                               , text
+               );
+       }
+}
diff --git a/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestEscherParts.java b/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestEscherParts.java
new file mode 100644 (file)
index 0000000..dbaf46c
--- /dev/null
@@ -0,0 +1,50 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hpbf.model;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.poi.hpbf.HPBFDocument;
+
+import junit.framework.TestCase;
+
+public class TestEscherParts extends TestCase {
+       private String dir;
+
+       protected void setUp() throws Exception {
+               dir = System.getProperty("HPBF.testdata.path");
+       }
+
+       public void testBasics() throws Exception {
+               File f = new File(dir, "Sample.pub");
+               HPBFDocument doc = new HPBFDocument(
+                               new FileInputStream(f)
+               );
+
+               EscherStm es = doc.getEscherStm();
+               EscherDelayStm eds = doc.getEscherDelayStm();
+               
+               assertNotNull(es);
+               assertNotNull(eds);
+               
+               assertEquals(13, es.getEscherRecords().length);
+               assertEquals(0, eds.getEscherRecords().length);
+               
+               // TODO - check the contents
+       }
+}
diff --git a/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestQuillContents.java b/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestQuillContents.java
new file mode 100644 (file)
index 0000000..ce6ddf8
--- /dev/null
@@ -0,0 +1,80 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hpbf.model;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.poi.hpbf.HPBFDocument;
+import org.apache.poi.hpbf.model.qcbits.QCTextBit;
+
+import junit.framework.TestCase;
+
+public class TestQuillContents extends TestCase {
+       private String dir;
+
+       protected void setUp() throws Exception {
+               dir = System.getProperty("HPBF.testdata.path");
+       }
+
+       public void testBasics() throws Exception {
+               File f = new File(dir, "Sample.pub");
+               HPBFDocument doc = new HPBFDocument(
+                               new FileInputStream(f)
+               );
+               
+               QuillContents qc = doc.getQuillContents();
+               assertEquals(20, qc.getBits().length);
+               for(int i=0; i<19; i++) {
+                       assertNotNull(qc.getBits()[i]);
+               }
+               // Last one is blank
+               assertNull(qc.getBits()[19]);
+               
+               // Should be text, then three STSHs
+               assertEquals("TEXT", qc.getBits()[0].getThingType());
+               assertEquals("TEXT", qc.getBits()[0].getBitType());
+               assertEquals(0, qc.getBits()[0].getOptA());
+               
+               assertEquals("STSH", qc.getBits()[1].getThingType());
+               assertEquals("STSH", qc.getBits()[1].getBitType());
+               assertEquals(0, qc.getBits()[1].getOptA());
+               
+               assertEquals("STSH", qc.getBits()[2].getThingType());
+               assertEquals("STSH", qc.getBits()[2].getBitType());
+               assertEquals(1, qc.getBits()[2].getOptA());
+               
+               assertEquals("STSH", qc.getBits()[3].getThingType());
+               assertEquals("STSH", qc.getBits()[3].getBitType());
+               assertEquals(2, qc.getBits()[3].getOptA());
+       }
+       
+       public void testText() throws Exception {
+               File f = new File(dir, "Sample.pub");
+               HPBFDocument doc = new HPBFDocument(
+                               new FileInputStream(f)
+               );
+               
+               QuillContents qc = doc.getQuillContents();
+               assertEquals(20, qc.getBits().length);
+               
+               QCTextBit text = (QCTextBit)qc.getBits()[0];
+               String t = text.getText();
+               assertTrue(t.startsWith("This is some text on the first page"));
+               assertTrue(t.endsWith("Within doc to page 1\r"));
+       }
+}
diff --git a/src/testcases/org/apache/poi/hssf/data/ex45672.xls b/src/testcases/org/apache/poi/hssf/data/ex45672.xls
new file mode 100644 (file)
index 0000000..fbf48e8
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/ex45672.xls differ
diff --git a/src/testcases/org/apache/poi/hssf/data/yearfracExamples.xls b/src/testcases/org/apache/poi/hssf/data/yearfracExamples.xls
new file mode 100644 (file)
index 0000000..2b2be7d
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/yearfracExamples.xls differ
index 2d3759994ef78810fc9bb9464cdfbdcd818a3167..14e3c2c56d696135d6dff3a4330a1cdbeccf8d1a 100644 (file)
@@ -139,7 +139,7 @@ public class TestModelFactory extends TestCase
         ByteArrayOutputStream stream = new ByteArrayOutputStream();
         HSSFSheet sheet = book.createSheet("Test");
         HSSFRow   row   = sheet.createRow(0);
-        HSSFCell  cell  = row.createCell((short)0);
+        HSSFCell  cell  = row.createCell(0);
         cell.setCellValue(10.5);
         book.write(stream);
         return stream;
index 37e594940cd8ff56f42415b714cbbf073b4250b0..aa4bbcc6f0e37597d4b32103435e9395e07278a7 100644 (file)
@@ -21,6 +21,7 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
@@ -31,6 +32,7 @@ import org.apache.poi.hssf.record.BOFRecord;
 import org.apache.poi.hssf.record.LabelSSTRecord;
 import org.apache.poi.hssf.record.Record;
 import org.apache.poi.hssf.record.RowRecord;
+import org.apache.poi.hssf.record.SharedFormulaRecord;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 /**
  * Tests for MissingRecordAwareHSSFListener
@@ -39,25 +41,7 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase {
        
        private Record[] r;
 
-       public void openNormal() {
-               HSSFRequest req = new HSSFRequest();
-               MockHSSFListener mockListen = new MockHSSFListener();
-               MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(mockListen);
-               req.addListenerForAllRecords(listener);
-               
-               HSSFEventFactory factory = new HSSFEventFactory();
-               try {
-                       InputStream is = HSSFTestDataSamples.openSampleFileStream("MissingBits.xls");
-                       POIFSFileSystem fs = new POIFSFileSystem(is);
-                       factory.processWorkbookEvents(req, fs);
-               } catch (IOException e) {
-                       throw new RuntimeException(e);
-               }
-               
-               r = mockListen.getRecords();
-               assertTrue(r.length > 100);
-       } 
-       public void openAlt() {
+       private void readRecords(String sampleFileName) {
                HSSFRequest req = new HSSFRequest();
                MockHSSFListener mockListen = new MockHSSFListener();
                MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(mockListen);
@@ -65,7 +49,7 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase {
                
                HSSFEventFactory factory = new HSSFEventFactory();
                try {
-                       InputStream is = HSSFTestDataSamples.openSampleFileStream("MRExtraLines.xls");
+                       InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
                        POIFSFileSystem fs = new POIFSFileSystem(is);
                        factory.processWorkbookEvents(req, fs);
                } catch (IOException e) {
@@ -75,8 +59,11 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase {
                r = mockListen.getRecords();
                assertTrue(r.length > 100);
        } 
+       public void openNormal() {
+               readRecords("MissingBits.xls");
+       }
        
-       public void testMissingRowRecords() throws Exception {
+       public void testMissingRowRecords() {
                openNormal();
                
                // We have rows 0, 1, 2, 20 and 21
@@ -126,7 +113,7 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase {
                assertEquals(19, mr.getRowNumber());
        }
        
-       public void testEndOfRowRecords() throws Exception {
+       public void testEndOfRowRecords() {
                openNormal();
                
                // Find the cell at 0,0
@@ -248,7 +235,7 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase {
        }
        
        
-       public void testMissingCellRecords() throws Exception {
+       public void testMissingCellRecords() {
                openNormal();
                
                // Find the cell at 0,0
@@ -350,29 +337,21 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase {
        
        // Make sure we don't put in any extra new lines
        //  that aren't already there
-       public void testNoExtraNewLines() throws Exception {
+       public void testNoExtraNewLines() {
                // Load a different file
-               openAlt();
-               
-               
                // This file has has something in lines 1-33
-               List lcor = new ArrayList();
+               readRecords("MRExtraLines.xls");
+               
+               int rowCount=0;
                for(int i=0; i<r.length; i++) {
-                       if(r[i] instanceof LastCellOfRowDummyRecord)
-                               lcor.add( (LastCellOfRowDummyRecord)r[i] );
+                       if(r[i] instanceof LastCellOfRowDummyRecord) {
+                               LastCellOfRowDummyRecord eor = (LastCellOfRowDummyRecord) r[i];
+                               assertEquals(rowCount, eor.getRow());
+                               rowCount++;
+                       }
                }
-               
                // Check we got the 33 rows
-               assertEquals(33, lcor.size());
-               LastCellOfRowDummyRecord[] rowEnds = (LastCellOfRowDummyRecord[])
-                       lcor.toArray(new LastCellOfRowDummyRecord[lcor.size()]);
-               assertEquals(33, rowEnds.length);
-               
-               // And check they have the right stuff in them,
-               //  no repeats
-               for(int i=0; i<rowEnds.length; i++) {
-                       assertEquals(i, rowEnds[i].getRow());
-               }
+               assertEquals(33, rowCount);
        }
 
        private static final class MockHSSFListener implements HSSFListener {
@@ -418,4 +397,29 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase {
                        return result;
                }
        }
+       
+       /**
+        * Make sure that the presence of shared formulas does not cause extra 
+        * end-of-row records.
+        */
+       public void testEndOfRow_bug45672() {
+               readRecords("ex45672.xls");
+               Record[] rr = r;
+               int eorCount=0;
+               int sfrCount=0;
+               for (int i = 0; i < rr.length; i++) {
+                       Record record = rr[i];
+                       if (record instanceof SharedFormulaRecord) {
+                               sfrCount++;
+                       }
+                       if (record instanceof LastCellOfRowDummyRecord) {
+                               eorCount++;
+                       }
+               }
+               if (eorCount == 2) {
+                       throw new AssertionFailedError("Identified bug 45672");
+               }
+               assertEquals(1, eorCount);
+               assertEquals(1, sfrCount);
+       }
 }
index de443e18971f01dbec369ba28c6f67489f8e6893..eb58e96616380f6671b23abed9774427b4858817 100644 (file)
@@ -365,8 +365,8 @@ public final class TestSSTRecord extends TestCase {
     {
         HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("duprich1.xls");
         HSSFSheet sheet = wb.getSheetAt( 1 );
-        assertEquals( "01/05 (Wed)", sheet.getRow( 0 ).getCell( (short) 8 ).getStringCellValue() );
-        assertEquals( "01/05 (Wed)", sheet.getRow( 1 ).getCell( (short) 8 ).getStringCellValue() );
+        assertEquals( "01/05 (Wed)", sheet.getRow( 0 ).getCell(8 ).getStringCellValue() );
+        assertEquals( "01/05 (Wed)", sheet.getRow( 1 ).getCell(8 ).getStringCellValue() );
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         wb.write( baos );
@@ -375,12 +375,12 @@ public final class TestSSTRecord extends TestCase {
         wb = HSSFTestDataSamples.openSampleWorkbook("duprich2.xls");
         sheet = wb.getSheetAt( 0 );
         int row = 0;
-        assertEquals( "Testing", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
-        assertEquals( "rich", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
-        assertEquals( "text", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
-        assertEquals( "strings", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
-        assertEquals( "Testing", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
-        assertEquals( "Testing", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
+        assertEquals( "Testing", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() );
+        assertEquals( "rich", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() );
+        assertEquals( "text", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() );
+        assertEquals( "strings", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() );
+        assertEquals( "Testing", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() );
+        assertEquals( "Testing", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() );
 
         wb.write( baos );
     }
index 844430fb733a60618cadb72b6f8df0bdda9f9ec6..b3c864cdb84797ff711f6756b12f33fa4ac7722c 100644 (file)
@@ -22,6 +22,7 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.model.RecordStream;
@@ -31,6 +32,7 @@ import org.apache.poi.hssf.record.RecordFactory;
 import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.util.LittleEndian;
 
 /**
  * Tests the serialization and deserialization of the CFRecordsAggregate
@@ -63,7 +65,8 @@ public final class TestCFRecordsAggregate extends TestCase
                record = CFRecordsAggregate.createCFAggregate(new RecordStream(recs, 0));
 
                // Serialize
-               byte [] serializedRecord = record.serialize();
+               byte [] serializedRecord = new byte[record.getRecordSize()];
+               record.serialize(0, serializedRecord);
                InputStream in = new ByteArrayInputStream(serializedRecord);
 
                //Parse
@@ -98,4 +101,28 @@ public final class TestCFRecordsAggregate extends TestCase
                assertEquals(2, cellRanges.length);
                assertEquals(3, header.getNumberOfConditionalFormats());
        }
+       
+       /**
+        * Make sure that the CF Header record is properly updated with the number of rules
+        */
+       public void testNRules() {
+               HSSFWorkbook workbook = new HSSFWorkbook();
+               CellRangeAddress[] cellRanges = {
+                               new CellRangeAddress(0,1,0,0),
+                               new CellRangeAddress(0,1,2,2),
+               };
+               CFRuleRecord[] rules = {
+                       CFRuleRecord.create(workbook, "7"),
+                       CFRuleRecord.create(workbook, ComparisonOperator.BETWEEN, "2", "5"),
+               };
+               CFRecordsAggregate agg = new CFRecordsAggregate(cellRanges, rules);
+               byte[] serializedRecord = new byte[agg.getRecordSize()];
+               agg.serialize(0, serializedRecord);
+               
+               int nRules = LittleEndian.getUShort(serializedRecord, 4);
+               if (nRules == 0) {
+                       throw new AssertionFailedError("Identified bug 45682 b");
+               }
+               assertEquals(rules.length, nRules);
+       }
 }
index 2ae2eebc429da3725889f9c7a70ccaab7265892f..3464c407d01e7784b4f4d4a22b1f8a4866218eab 100755 (executable)
@@ -257,7 +257,7 @@ public class TestValueRecordsAggregate extends TestCase
         }
     }
     private static String getFormulaFromFirstCell(HSSFSheet s, int rowIx) {
-        return s.getRow(rowIx).getCell((short)0).getCellFormula();
+        return s.getRow(rowIx).getCell(0).getCellFormula();
     }
 
     /**
index 8dd8a3368126a343f60fe4f0354cb61534902874..0dd5758479199c45981c32f4aab050528073c626 100644 (file)
@@ -34,7 +34,7 @@ public class TestAreaErrPtg extends AbstractPtgTestCase
     {
         HSSFWorkbook workbook = loadWorkbook("AreaErrPtg.xls");
         assertEquals("Wrong formula string for area error", "SUM(#REF!)",
-                     workbook.getSheetAt(0).getRow(0).getCell((short) 2).getCellFormula());
+                     workbook.getSheetAt(0).getRow(0).getCell(2).getCellFormula());
     }
 }
 
index 14bcde38b3f8d2b08773e899f29dbd1a3a60f3df..2906f5e020a6a004e7925c10ce3e73fc821ccc3b 100644 (file)
@@ -103,7 +103,7 @@ public final class TestArrayPtg extends TestCase {
                HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex42564-elementOrder.xls");
 
                // The formula has an array with 3 rows and 5 columns 
-               String formula = wb.getSheetAt(0).getRow(0).getCell((short)0).getCellFormula();
+               String formula = wb.getSheetAt(0).getRow(0).getCell(0).getCellFormula();
                // TODO - These number literals should not have '.0'. Excel has different number rendering rules
 
                if (formula.equals("SUM({1.0,6.0,11.0;2.0,7.0,12.0;3.0,8.0,13.0;4.0,9.0,14.0;5.0,10.0,15.0})")) {
index c8c879c8e2a7c924c259f43b224cbbe0612e524d..a7d140cae2caf137a0b13a361bffd1844fe85a8c 100644 (file)
@@ -34,7 +34,7 @@ public class TestErrPtg extends AbstractPtgTestCase
     public void testReading() throws Exception
     {
         HSSFWorkbook workbook = loadWorkbook("ErrPtg.xls");
-        HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell((short) 0);
+        HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell(0);
         assertEquals("Wrong cell value", 4.0, cell.getNumericCellValue(), 0.0);
         assertEquals("Wrong cell formula", "ERROR.TYPE(#REF!)", cell.getCellFormula());
     }
index 2e393d6107c262a63eacef96bad1ab3c87a3c99a..cc5198acfac3c64122796de45b9a16e719315c49 100755 (executable)
@@ -71,7 +71,7 @@ public final class TestExternalFunctionFormulas extends TestCase {
                }
        }
        
-       public void DISABLEDtestEvaluate() {
+       public void testEvaluate() {
                HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls");
                HSSFSheet sheet = wb.getSheetAt(0);
                HSSFCell cell = sheet.getRow(0).getCell(0);
index 1ddd4df52dfb420ecd44da3cb4a4b2e57a1b5e0a..a80ce11837e3bd3c0a3b9b6b0fcdd10e75c59604 100644 (file)
@@ -34,7 +34,7 @@ public class TestIntersectionPtg extends AbstractPtgTestCase
     public void testReading() throws Exception
     {
         HSSFWorkbook workbook = loadWorkbook("IntersectionPtg.xls");
-        HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell((short) 2);
+        HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell(2);
         assertEquals("Wrong cell value", 5.0, cell.getNumericCellValue(), 0.0);
         assertEquals("Wrong cell formula", "SUM(A1:B2 B2:C3)", cell.getCellFormula());
     }
index fb20f18218a675bfc401d464e8136e1864af2565..e4b89abb31ca836861660cff65e27fb5aece46fd 100644 (file)
@@ -37,11 +37,11 @@ public class TestPercentPtg extends AbstractPtgTestCase
         HSSFSheet sheet = workbook.getSheetAt(0);
 
         assertEquals("Wrong numeric value for original number", 53000.0,
-                     sheet.getRow(0).getCell((short) 0).getNumericCellValue(), 0.0);
+                     sheet.getRow(0).getCell(0).getNumericCellValue(), 0.0);
         assertEquals("Wrong numeric value for percent formula result", 5300.0,
-                     sheet.getRow(1).getCell((short) 0).getNumericCellValue(), 0.0);
+                     sheet.getRow(1).getCell(0).getNumericCellValue(), 0.0);
         assertEquals("Wrong formula string for percent formula", "A1*10%",
-                     sheet.getRow(1).getCell((short) 0).getCellFormula());
+                     sheet.getRow(1).getCell(0).getCellFormula());
     }
 }
 
index f871cefba87a1651f620ee0f2327fc832a378941..2131777f8006878219dcbeaffa0c4bb420eb698d 100644 (file)
@@ -34,7 +34,7 @@ public class TestRangePtg extends AbstractPtgTestCase
     public void testReading() throws Exception
     {
         HSSFWorkbook workbook = loadWorkbook("RangePtg.xls");
-        HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell((short) 1);
+        HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell(1);
         assertEquals("Wrong cell value", 10.0, cell.getNumericCellValue(), 0.0);
         assertEquals("Wrong cell formula", "SUM(pineapple:B2)", cell.getCellFormula());
     }
index 2bc1f42ff3ada4eff003762098cfcaafaa3634fe..b50bb76b45b4eab4fcda1da7590448a07e4f5d0c 100644 (file)
@@ -41,41 +41,41 @@ public final class TestReferencePtg extends TestCase {
 
         // First row
         assertEquals("Wrong numeric value for original number", 55.0,
-                     sheet.getRow(0).getCell((short) 0).getNumericCellValue(), 0.0);
+                     sheet.getRow(0).getCell(0).getNumericCellValue(), 0.0);
         assertEquals("Wrong numeric value for referemce", 55.0,
-                     sheet.getRow(0).getCell((short) 1).getNumericCellValue(), 0.0);
+                     sheet.getRow(0).getCell(1).getNumericCellValue(), 0.0);
         assertEquals("Wrong formula string for reference", "A1",
-                     sheet.getRow(0).getCell((short) 1).getCellFormula());
+                     sheet.getRow(0).getCell(1).getCellFormula());
         
         // Now moving over the 2**15 boundary
         // (Remember that excel row (n) is poi row (n-1)
         assertEquals("Wrong numeric value for original number", 32767.0,
-                sheet.getRow(32766).getCell((short) 0).getNumericCellValue(), 0.0);
+                sheet.getRow(32766).getCell(0).getNumericCellValue(), 0.0);
         assertEquals("Wrong numeric value for referemce", 32767.0,
-                sheet.getRow(32766).getCell((short) 1).getNumericCellValue(), 0.0);
+                sheet.getRow(32766).getCell(1).getNumericCellValue(), 0.0);
         assertEquals("Wrong formula string for reference", "A32767",
-                sheet.getRow(32766).getCell((short) 1).getCellFormula());
+                sheet.getRow(32766).getCell(1).getCellFormula());
         
         assertEquals("Wrong numeric value for original number", 32768.0,
-                sheet.getRow(32767).getCell((short) 0).getNumericCellValue(), 0.0);
+                sheet.getRow(32767).getCell(0).getNumericCellValue(), 0.0);
         assertEquals("Wrong numeric value for referemce", 32768.0,
-                sheet.getRow(32767).getCell((short) 1).getNumericCellValue(), 0.0);
+                sheet.getRow(32767).getCell(1).getNumericCellValue(), 0.0);
         assertEquals("Wrong formula string for reference", "A32768",
-                sheet.getRow(32767).getCell((short) 1).getCellFormula());
+                sheet.getRow(32767).getCell(1).getCellFormula());
         
         assertEquals("Wrong numeric value for original number", 32769.0,
-                sheet.getRow(32768).getCell((short) 0).getNumericCellValue(), 0.0);
+                sheet.getRow(32768).getCell(0).getNumericCellValue(), 0.0);
         assertEquals("Wrong numeric value for referemce", 32769.0,
-                sheet.getRow(32768).getCell((short) 1).getNumericCellValue(), 0.0);
+                sheet.getRow(32768).getCell(1).getNumericCellValue(), 0.0);
         assertEquals("Wrong formula string for reference", "A32769",
-                sheet.getRow(32768).getCell((short) 1).getCellFormula());
+                sheet.getRow(32768).getCell(1).getCellFormula());
         
         assertEquals("Wrong numeric value for original number", 32770.0,
-                sheet.getRow(32769).getCell((short) 0).getNumericCellValue(), 0.0);
+                sheet.getRow(32769).getCell(0).getNumericCellValue(), 0.0);
         assertEquals("Wrong numeric value for referemce", 32770.0,
-                sheet.getRow(32769).getCell((short) 1).getNumericCellValue(), 0.0);
+                sheet.getRow(32769).getCell(1).getNumericCellValue(), 0.0);
         assertEquals("Wrong formula string for reference", "A32770",
-                sheet.getRow(32769).getCell((short) 1).getCellFormula());
+                sheet.getRow(32769).getCell(1).getCellFormula());
     }
     
     public void testBug44921() {
index b990761d2e252cb04870b031bc1a79ab36e3ae21..3c9f439752293ac79b906e414260770ac491517c 100644 (file)
@@ -34,7 +34,7 @@ public class TestUnionPtg extends AbstractPtgTestCase
     public void testReading() throws Exception
     {
         HSSFWorkbook workbook = loadWorkbook("UnionPtg.xls");
-        HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell((short) 2);
+        HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell(2);
         assertEquals("Wrong cell value", 24.0, cell.getNumericCellValue(), 0.0);
         assertEquals("Wrong cell formula", "SUM(A1:B2,B2:C3)", cell.getCellFormula());
     }
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/atp/TestYearFracCalculator.java b/src/testcases/org/apache/poi/hssf/record/formula/atp/TestYearFracCalculator.java
new file mode 100644 (file)
index 0000000..aaf03a2
--- /dev/null
@@ -0,0 +1,66 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.formula.atp;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.record.formula.eval.EvaluationException;
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
+
+/**
+ * Specific test cases for YearFracCalculator
+ */
+public final class TestYearFracCalculator extends TestCase {
+
+       public void testBasis1() {
+               confirm(md(1999, 1, 1), md(1999, 4, 5), 1, 0.257534247);
+               confirm(md(1999, 4, 1), md(1999, 4, 5), 1, 0.010958904);
+               confirm(md(1999, 4, 1), md(1999, 4, 4), 1, 0.008219178);
+               confirm(md(1999, 4, 2), md(1999, 4, 5), 1, 0.008219178);
+               confirm(md(1999, 3, 31), md(1999, 4, 3), 1, 0.008219178);
+               confirm(md(1999, 4, 5), md(1999, 4, 8), 1, 0.008219178);
+               confirm(md(1999, 4, 4), md(1999, 4, 7), 1, 0.008219178);
+       }
+
+       private void confirm(double startDate, double endDate, int basis, double expectedValue) {
+               double actualValue;
+               try {
+                       actualValue = YearFracCalculator.calculate(startDate, endDate, basis);
+               } catch (EvaluationException e) {
+                       throw new RuntimeException(e);
+               }
+               double diff = actualValue - expectedValue;
+               if (Math.abs(diff) >  0.000000001) {
+                       double hours = diff * 365 * 24;
+                       System.out.println(startDate + " " + endDate + " off by " + hours + " hours");
+                       assertEquals(expectedValue, actualValue, 0.000000001);
+               }
+               
+       }
+
+       private static double md(int year, int month, int day) {
+               Calendar c = new GregorianCalendar();
+               
+               c.set(year, month-1, day, 0, 0, 0);
+               c.set(Calendar.MILLISECOND, 0);
+               return HSSFDateUtil.getExcelDate(c.getTime());
+       }
+}
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/atp/TestYearFracCalculatorFromSpreadsheet.java b/src/testcases/org/apache/poi/hssf/record/formula/atp/TestYearFracCalculatorFromSpreadsheet.java
new file mode 100644 (file)
index 0000000..2cad8e3
--- /dev/null
@@ -0,0 +1,178 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.formula.atp;
+
+import java.io.PrintStream;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.Iterator;
+
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+import junit.framework.ComparisonFailure;
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.record.formula.eval.EvaluationException;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+
+/**
+ * Tests YearFracCalculator using test-cases listed in a sample spreadsheet
+ * 
+ * @author Josh Micich
+ */
+public final class TestYearFracCalculatorFromSpreadsheet extends TestCase {
+       
+       private static final class SS {
+
+               public static final int BASIS_COLUMN = 1; // "B"
+               public static final int START_YEAR_COLUMN = 2; // "C"
+               public static final int END_YEAR_COLUMN = 5; // "F"
+               public static final int YEARFRAC_FORMULA_COLUMN = 11; // "L"
+               public static final int EXPECTED_RESULT_COLUMN = 13; // "N"
+       }
+
+       public void testAll() {
+               
+               HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("yearfracExamples.xls");
+               HSSFSheet sheet = wb.getSheetAt(0);
+               HSSFFormulaEvaluator formulaEvaluator = new HSSFFormulaEvaluator(sheet, wb);
+               int nSuccess = 0;
+               int nFailures = 0;
+               int nUnexpectedErrors = 0;
+               Iterator rowIterator = sheet.rowIterator();
+               while(rowIterator.hasNext()) {
+                       HSSFRow row = (HSSFRow) rowIterator.next();
+                       
+                       HSSFCell cell = row.getCell(SS.YEARFRAC_FORMULA_COLUMN);
+                       if (cell == null || cell.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
+                               continue;
+                       }
+                       try {
+                               processRow(row, cell, formulaEvaluator);
+                               nSuccess++;
+                       } catch (RuntimeException e) {
+                               nUnexpectedErrors ++;
+                               printShortStackTrace(System.err, e);
+                       } catch (AssertionFailedError e) {
+                               nFailures ++;
+                               printShortStackTrace(System.err, e);
+                       }
+               }
+               if (nUnexpectedErrors + nFailures > 0) {
+                       String msg = nFailures + " failures(s) and " + nUnexpectedErrors 
+                               + " unexpected errors(s) occurred. See stderr for details";
+                       throw new AssertionFailedError(msg);
+               }
+               if (nSuccess < 1) {
+                       throw new RuntimeException("No test sample cases found");
+               }
+       }
+       
+       private static void processRow(HSSFRow row, HSSFCell cell, HSSFFormulaEvaluator formulaEvaluator) {
+               
+               double startDate = makeDate(row, SS.START_YEAR_COLUMN);
+               double endDate = makeDate(row, SS.END_YEAR_COLUMN);
+               
+               int basis = getIntCell(row, SS.BASIS_COLUMN);
+               
+               double expectedValue = getDoubleCell(row, SS.EXPECTED_RESULT_COLUMN);
+               
+               double actualValue;
+               try {
+                       actualValue = YearFracCalculator.calculate(startDate, endDate, basis);
+               } catch (EvaluationException e) {
+                       throw new RuntimeException(e);
+               }
+               if (expectedValue != actualValue) {
+                       throw new ComparisonFailure("Direct calculate failed - row " + (row.getRowNum()+1), 
+                                       String.valueOf(expectedValue), String.valueOf(actualValue));
+               }
+               actualValue = formulaEvaluator.evaluate(cell).getNumberValue();
+               if (expectedValue != actualValue) {
+                       throw new ComparisonFailure("Formula evaluate failed - row " + (row.getRowNum()+1), 
+                                       String.valueOf(expectedValue), String.valueOf(actualValue));
+               }
+       }
+
+       private static double makeDate(HSSFRow row, int yearColumn) {
+               int year = getIntCell(row, yearColumn + 0);
+               int month = getIntCell(row, yearColumn + 1);
+               int day = getIntCell(row, yearColumn + 2);
+               Calendar c = new GregorianCalendar(year, month-1, day, 0, 0, 0);
+               c.set(Calendar.MILLISECOND, 0);
+               return HSSFDateUtil.getExcelDate(c.getTime());
+       }
+
+       private static int getIntCell(HSSFRow row, int colIx) {
+               double dVal = getDoubleCell(row, colIx);
+               if (Math.floor(dVal) != dVal) {
+                       throw new RuntimeException("Non integer value (" + dVal 
+                                       + ") cell found at column " + (char)('A' + colIx));
+               }
+               return (int)dVal;
+       }
+
+       private static double getDoubleCell(HSSFRow row, int colIx) {
+               HSSFCell cell = row.getCell(colIx);
+               if (cell == null) {
+                       throw new RuntimeException("No cell found at column " + colIx);
+               }
+               double dVal = cell.getNumericCellValue();
+               return dVal;
+       }
+
+       /**
+        * Useful to keep output concise when expecting many failures to be reported by this test case
+        * TODO - refactor duplicates in other Test~FromSpreadsheet classes
+        */
+       private static void printShortStackTrace(PrintStream ps, Throwable e) {
+               StackTraceElement[] stes = e.getStackTrace();
+               
+               int startIx = 0;
+               // skip any top frames inside junit.framework.Assert
+               while(startIx<stes.length) {
+                       if(!stes[startIx].getClassName().equals(Assert.class.getName())) {
+                               break;
+                       }
+                       startIx++;
+               }
+               // skip bottom frames (part of junit framework)
+               int endIx = startIx+1;
+               while(endIx < stes.length) {
+                       if(stes[endIx].getClassName().equals(TestCase.class.getName())) {
+                               break;
+                       }
+                       endIx++;
+               }
+               if(startIx >= endIx) {
+                       // something went wrong. just print the whole stack trace
+                       e.printStackTrace(ps);
+               }
+               endIx -= 4; // skip 4 frames of reflection invocation
+               ps.println(e.toString());
+               for(int i=startIx; i<endIx; i++) {
+                       ps.println("\tat " + stes[i].toString());
+               }
+       }
+}
index 0a62d64cdbfba944ab39c668c5551c1419e34bfb..5d8ccc7521de0456cb0c2ed1709fde4a5e213687 100644 (file)
@@ -150,7 +150,7 @@ public final class TestReadMissingBuiltInFuncs extends TestCase {
                        // some other unexpected error
                        throw e;
                }
-               String result = sheet.getRow(rowIx).getCell((short)0).getCellFormula();
+               String result = sheet.getRow(rowIx).getCell(0).getCellFormula();
                if (false) {
                        System.err.println(result);
                }
index 39b949f7de2949dec5fac86fa46aed85c87070f5..1dc826cc6fd74789bbd4f9723bd6fe05e1d089d0 100644 (file)
@@ -85,7 +85,7 @@ public class TestCellStyle
                 c.setCellValue(rownum * 10000 + cellnum
                                + ((( double ) rownum / 1000)
                                   + (( double ) cellnum / 10000)));
-                c = r.createCell(( short ) (cellnum + 1));
+                c = r.createCell(cellnum + 1);
                 c.setCellValue("TEST");
                 c.setCellStyle(cs);
             }
@@ -112,16 +112,16 @@ public class TestCellStyle
         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:
-        HSSFCell cell = row.createCell((short)1);
+        HSSFCell cell = row.createCell(1);
         cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
         cell.setCellStyle(cs);
         cell.setCellValue(new Date());
 
         // with Calendar:
-        cell = row.createCell((short)2);
+        cell = row.createCell(2);
         cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
         cell.setCellStyle(cs);
         Calendar cal = Calendar.getInstance();
@@ -143,9 +143,9 @@ public class TestCellStyle
         HSSFSheet        s    = wb.createSheet();
         HSSFCellStyle    cs1  = wb.createCellStyle();
         HSSFCellStyle    cs2  = wb.createCellStyle();
-        HSSFRow row = s.createRow((short)0);
-        HSSFCell cell1 = row.createCell((short)1);
-        HSSFCell cell2 = row.createCell((short)2);
+        HSSFRow row = s.createRow(0);
+        HSSFCell cell1 = row.createCell(1);
+        HSSFCell cell2 = row.createCell(2);
         
         cs1.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
         cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/dd/yy"));
@@ -215,7 +215,7 @@ public class TestCellStyle
                                + ((( double ) rownum / 1000)
                                   + (( double ) cellnum / 10000)));
                 c.setCellStyle(cs);
-                c = r.createCell(( short ) (cellnum + 1));
+                c = r.createCell(cellnum + 1);
                 c.setCellValue("TEST");
                 c.setCellStyle(cs2);
             }
index 299372c12171188751e5e0eeb1294f4c2f61bc57..15a5b8250f86569fb4c62a28f0423dfe0c801dcf 100644 (file)
@@ -111,7 +111,7 @@ public final class TestDataValidation extends TestCase {
                                        inputBox, errorBox);
                        if (_cellStyle != null) {
                                HSSFRow row = _sheet.getRow(_sheet.getPhysicalNumberOfRows() - 1);
-                               HSSFCell cell = row.createCell((short) 0);
+                               HSSFCell cell = row.createCell(0);
                                cell.setCellStyle(_cellStyle);
                        }
                        writeOtherSettings(_sheet, _style_1, promptDescr);
@@ -144,26 +144,26 @@ public final class TestDataValidation extends TestCase {
                                boolean errorBox) {
                        HSSFRow row = sheet.createRow(sheet.getPhysicalNumberOfRows());
                        // condition's string
-                       HSSFCell cell = row.createCell((short) 1);
+                       HSSFCell cell = row.createCell(1);
                        cell.setCellStyle(style_1);
                        setCellValue(cell, strCondition);
                        // allow empty cells
-                       cell = row.createCell((short) 2);
+                       cell = row.createCell(2);
                        cell.setCellStyle(style_2);
                        setCellValue(cell, ((allowEmpty) ? "yes" : "no"));
                        // show input box
-                       cell = row.createCell((short) 3);
+                       cell = row.createCell(3);
                        cell.setCellStyle(style_2);
                        setCellValue(cell, ((inputBox) ? "yes" : "no"));
                        // show error box
-                       cell = row.createCell((short) 4);
+                       cell = row.createCell(4);
                        cell.setCellStyle(style_2);
                        setCellValue(cell, ((errorBox) ? "yes" : "no"));
                }
                private static void writeOtherSettings(HSSFSheet sheet, HSSFCellStyle style,
                                String strStettings) {
                        HSSFRow row = sheet.getRow(sheet.getPhysicalNumberOfRows() - 1);
-                       HSSFCell cell = row.createCell((short) 5);
+                       HSSFCell cell = row.createCell(5);
                        cell.setCellStyle(style);
                        setCellValue(cell, strStettings);
                }
@@ -256,7 +256,7 @@ public final class TestDataValidation extends TestCase {
                        HSSFRow row = sheet.createRow(sheet.getPhysicalNumberOfRows());
                        row = sheet.createRow(sheet.getPhysicalNumberOfRows());
                        sheet.addMergedRegion(new CellRangeAddress(sheet.getPhysicalNumberOfRows()-1, sheet.getPhysicalNumberOfRows()-1, 0, 5));
-                       HSSFCell cell = row.createCell((short) 0);
+                       HSSFCell cell = row.createCell(0);
                        setCellValue(cell, strTypeDescription);
                        cell.setCellStyle(_style_3);
                        row = sheet.createRow(sheet.getPhysicalNumberOfRows());
@@ -267,7 +267,7 @@ public final class TestDataValidation extends TestCase {
                        HSSFRow row = sheet.createRow(sheet.getPhysicalNumberOfRows());
                        row.setHeight((short) 400);
                        for (int i = 0; i < 6; i++) {
-                               row.createCell((short) i).setCellStyle(_style_4);
+                               row.createCell(i).setCellStyle(_style_4);
                                if (i == 2 || i == 3 || i == 4) {
                                        sheet.setColumnWidth((short) i, (short) 3500);
                                } else if (i == 5) {
@@ -276,17 +276,17 @@ public final class TestDataValidation extends TestCase {
                                        sheet.setColumnWidth((short) i, (short) 8000);
                                }
                        }
-                       HSSFCell cell = row.getCell((short) 0);
+                       HSSFCell cell = row.getCell(0);
                        setCellValue(cell, "Data validation cells");
-                       cell = row.getCell((short) 1);
+                       cell = row.getCell(1);
                        setCellValue(cell, "Condition");
-                       cell = row.getCell((short) 2);
+                       cell = row.getCell(2);
                        setCellValue(cell, "Allow blank");
-                       cell = row.getCell((short) 3);
+                       cell = row.getCell(3);
                        setCellValue(cell, "Prompt box");
-                       cell = row.getCell((short) 4);
+                       cell = row.getCell(4);
                        setCellValue(cell, "Error box");
-                       cell = row.getCell((short) 5);
+                       cell = row.getCell(5);
                        setCellValue(cell, "Other settings");
                }
 
@@ -298,7 +298,7 @@ public final class TestDataValidation extends TestCase {
                        HSSFSheet sheet = _currentSheet;
                        HSSFRow row = sheet.getRow(sheet.getPhysicalNumberOfRows()-1);
                        sheet.addMergedRegion(new CellRangeAddress(sheet.getPhysicalNumberOfRows()-1, sheet.getPhysicalNumberOfRows()-1, 0, 5));
-                       HSSFCell cell = row.createCell((short)0);
+                       HSSFCell cell = row.createCell(0);
                        setCellValue(cell, strTypeDescription);
                        cell.setCellStyle(_style_3);
                        row = sheet.createRow(sheet.getPhysicalNumberOfRows());
@@ -395,14 +395,14 @@ public final class TestDataValidation extends TestCase {
                // add list data on same sheet
                for (int i = 0; i < 10; i++) {
                        HSSFRow currRow = fSheet.createRow(i + 29);
-                       setCellValue(currRow.createCell((short) 0), cellStrValue);
+                       setCellValue(currRow.createCell(0), cellStrValue);
                }
                // add list data on another sheet
                for (int i = 0; i < 10; i++) {
                        HSSFRow currRow = dataSheet.createRow(i + 0);
-                       setCellValue(currRow.createCell((short) 0), "Data a" + i);
-                       setCellValue(currRow.createCell((short) 1), "Data b" + i);
-                       setCellValue(currRow.createCell((short) 2), "Data c" + i);
+                       setCellValue(currRow.createCell(0), "Data a" + i);
+                       setCellValue(currRow.createCell(1), "Data b" + i);
+                       setCellValue(currRow.createCell(2), "Data c" + i);
                }
        }
 
index 3fdc1a9dbac6e3b27006306819d219a7f8e4fc99..36eaf92f32bdffca8d6088eafd63ecedf3522876 100644 (file)
@@ -54,8 +54,8 @@ public final class TestFormulas extends TestCase {
         HSSFCell         c      = null;
 
         //get our minimum values
-        r = s.createRow((short)1);
-        c = r.createCell((short)1);
+        r = s.createRow(1);
+        c = r.createCell(1);
         c.setCellFormula(1 + "+" + 1);
 
         wb.write(out);
@@ -64,8 +64,8 @@ public final class TestFormulas extends TestCase {
         FileInputStream in = new FileInputStream(file);
         wb = new HSSFWorkbook(in);
         s  = wb.getSheetAt(0);
-        r  = s.getRow((short)1);
-        c  = r.getCell((short)1);
+        r  = s.getRow(1);
+        c  = r.getCell(1);
 
         assertTrue("Formula is as expected",("1+1".equals(c.getCellFormula())));
         in.close();
@@ -176,24 +176,24 @@ public final class TestFormulas extends TestCase {
 
         //get our minimum values
 
-        r = s.createRow((short)0);
-        c = r.createCell((short)1);
+        r = s.createRow(0);
+        c = r.createCell(1);
         c.setCellFormula(""+Float.MIN_VALUE + operator + Float.MIN_VALUE);
 
        for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2) ) {
-            r = s.createRow((short) x);
+            r = s.createRow(x);
 
             for (short y = 1; y < 256 && y > 0; y= (short) (y +2)) {
 
-                c = r.createCell((short) y);
+                c = r.createCell(y);
                 c.setCellFormula("" + x+"."+y + operator + y +"."+x);
 
 
             }
         }
         if (s.getLastRowNum() < Short.MAX_VALUE) {
-            r = s.createRow((short)0);
-            c = r.createCell((short)0);
+            r = s.createRow(0);
+            c = r.createCell(0);
             c.setCellFormula("" + Float.MAX_VALUE + operator + Float.MAX_VALUE);
         }
         wb.write(out);
@@ -216,11 +216,11 @@ public final class TestFormulas extends TestCase {
         // dont know how to check correct result .. for the moment, we just verify that the file can be read.
 
         for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) {
-            r = s.getRow((short) x);
+            r = s.getRow(x);
 
             for (short y = 1; y < 256 && y > 0; y=(short)(y+2)) {
 
-                c = r.getCell((short) y);
+                c = r.getCell(y);
                 assertTrue("got a formula",c.getCellFormula()!=null);
 
                 assertTrue("loop Formula is as expected "+x+"."+y+operator+y+"."+x+"!="+c.getCellFormula(),(
@@ -337,8 +337,8 @@ public final class TestFormulas extends TestCase {
         HSSFCell         c      = null;
 
         //get our minimum values
-        r = s.getRow((short)0);
-        c = r.getCell((short)1);
+        r = s.getRow(0);
+        c = r.getCell(1);
         //get our minimum values
         assertTrue("minval Formula is as expected A2"+operator+"A3 != "+c.getCellFormula(),
         ( ("A2"+operator+"A3").equals(c.getCellFormula())
@@ -346,7 +346,7 @@ public final class TestFormulas extends TestCase {
 
 
         for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) {
-            r = s.getRow((short) x);
+            r = s.getRow(x);
 
             for (short y = 1; y < 256 && y > 0; y++) {
 
@@ -372,7 +372,7 @@ public final class TestFormulas extends TestCase {
                     refy2=(short)(y-3);
                 }
 
-                c = r.getCell((short) y);
+                c = r.getCell(y);
                 CellReference cr= new CellReference(refx1, refy1, false, false);
                 ref=cr.formatAsString();
                 cr=new CellReference(refx2,refy2, false, false);
@@ -389,8 +389,8 @@ public final class TestFormulas extends TestCase {
         }
 
         //test our maximum values
-        r = s.getRow((short)0);
-        c = r.getCell((short)0);
+        r = s.getRow(0);
+        c = r.getCell(0);
 
         assertTrue("maxval Formula is as expected",(
         ("B1"+operator+"IV255").equals(c.getCellFormula())
@@ -416,8 +416,8 @@ public final class TestFormulas extends TestCase {
         HSSFCell         c      = null;
 
         //get our minimum values
-        r = s.createRow((short)0);
-        c = r.createCell((short)1);
+        r = s.createRow(0);
+        c = r.createCell(1);
         c.setCellFormula(formula);
 
         wb.write(out);
@@ -429,8 +429,8 @@ public final class TestFormulas extends TestCase {
         s      = wb.getSheetAt(0);
 
         //get our minimum values
-        r = s.getRow((short)0);
-        c = r.getCell((short)1);
+        r = s.getRow(0);
+        c = r.getCell(1);
         assertTrue("minval Formula is as expected",
                    formula.equals(c.getCellFormula())
                   );
@@ -496,18 +496,18 @@ public final class TestFormulas extends TestCase {
         HSSFCell         c      = null;
 
         //get our minimum values
-        r = s.getRow((short)0);
-        c = r.getCell((short)1);
+        r = s.getRow(0);
+        c = r.getCell(1);
         assertTrue("minval Formula is as expected 1"+operator+"1 != "+c.getCellFormula(),
         ( ("1"+operator+"1").equals(c.getCellFormula())
         ));
 
         for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) {
-            r = s.getRow((short) x);
+            r = s.getRow(x);
 
             for (short y = 1; y < 256 && y > 0; y++) {
 
-                c = r.getCell((short) y);
+                c = r.getCell(y);
 
                 assertTrue("loop Formula is as expected "+x+operator+y+"!="+c.getCellFormula(),(
                 (""+x+operator+y).equals(c.getCellFormula())
@@ -519,8 +519,8 @@ public final class TestFormulas extends TestCase {
         }
 
         //test our maximum values
-        r = s.getRow((short)0);
-        c = r.getCell((short)0);
+        r = s.getRow(0);
+        c = r.getCell(0);
 
 
         assertTrue("maxval Formula is as expected",(
@@ -549,9 +549,9 @@ public final class TestFormulas extends TestCase {
             HSSFCell         c      = null;
 
 
-            r = s.createRow((short) 0);
+            r = s.createRow(0);
 
-            c = r.createCell((short) 0);
+            c = r.createCell(0);
             c.setCellFormula(function+"(A2:A3)");
 
 
@@ -563,7 +563,7 @@ public final class TestFormulas extends TestCase {
             wb = new HSSFWorkbook(in);
             s = wb.getSheetAt(0);
             r = s.getRow(0);
-            c = r.getCell((short)0);
+            c = r.getCell(0);
 
             assertTrue("function ="+function+"(A2:A3)",
                         ( (function+"(A2:A3)").equals((function+"(A2:A3)")) )
@@ -586,9 +586,9 @@ public final class TestFormulas extends TestCase {
             HSSFCell         c      = null;
 
 
-            r = s.createRow((short) 0);
+            r = s.createRow(0);
 
-            c = r.createCell((short) 0);
+            c = r.createCell(0);
             c.setCellFormula(function+"(A2,A3)");
 
 
@@ -600,7 +600,7 @@ public final class TestFormulas extends TestCase {
             wb = new HSSFWorkbook(in);
             s = wb.getSheetAt(0);
             r = s.getRow(0);
-            c = r.getCell((short)0);
+            c = r.getCell(0);
 
             assertTrue("function ="+function+"(A2,A3)",
                         ( (function+"(A2,A3)").equals(c.getCellFormula()) )
@@ -624,11 +624,11 @@ public final class TestFormulas extends TestCase {
             HSSFCell         c      = null;
 
 
-            r = s.createRow((short) 0);
+            r = s.createRow(0);
 
-            c = r.createCell((short) 0);
+            c = r.createCell(0);
             c.setCellFormula(function+"(A2:A4,B2:B4)");
-            c=r.createCell((short) 1);
+            c=r.createCell(1);
             c.setCellFormula(function+"($A$2:$A4,B$2:B4)");
 
             wb.write(out);
@@ -639,13 +639,13 @@ public final class TestFormulas extends TestCase {
             wb = new HSSFWorkbook(in);
             s = wb.getSheetAt(0);
             r = s.getRow(0);
-            c = r.getCell((short)0);
+            c = r.getCell(0);
 
             assertTrue("function ="+function+"(A2:A4,B2:B4)",
                         ( (function+"(A2:A4,B2:B4)").equals(c.getCellFormula()) )
                       );
 
-            c=r.getCell((short) 1);
+            c=r.getCell(1);
              assertTrue("function ="+function+"($A$2:$A4,B$2:B4)",
                         ( (function+"($A$2:$A4,B$2:B4)").equals(c.getCellFormula()) )
                       );
@@ -663,17 +663,17 @@ public final class TestFormulas extends TestCase {
             HSSFCell         c      = null;
 
 
-            r = s.createRow((short) 0);
+            r = s.createRow(0);
 
-            c = r.createCell((short) 0);
+            c = r.createCell(0);
             c.setCellFormula("A3+A2");
-            c=r.createCell( (short) 1);
+            c=r.createCell(1);
             c.setCellFormula("$A3+$A2");
-            c=r.createCell( (short) 2);
+            c=r.createCell(2);
             c.setCellFormula("A$3+A$2");
-            c=r.createCell( (short) 3);
+            c=r.createCell(3);
             c.setCellFormula("$A$3+$A$2");
-            c=r.createCell( (short) 4);
+            c=r.createCell(4);
             c.setCellFormula("SUM($A$3,$A$2)");
 
             wb.write(out);
@@ -684,15 +684,15 @@ public final class TestFormulas extends TestCase {
             wb = new HSSFWorkbook(in);
             s = wb.getSheetAt(0);
             r = s.getRow(0);
-            c = r.getCell((short)0);
+            c = r.getCell(0);
             assertTrue("A3+A2", ("A3+A2").equals(c.getCellFormula()));
-             c = r.getCell((short)1);
+             c = r.getCell(1);
             assertTrue("$A3+$A2", ("$A3+$A2").equals(c.getCellFormula()));
-             c = r.getCell((short)2);
+             c = r.getCell(2);
             assertTrue("A$3+A$2", ("A$3+A$2").equals(c.getCellFormula()));
-             c = r.getCell((short)3);
+             c = r.getCell(3);
             assertTrue("$A$3+$A$2", ("$A$3+$A$2").equals(c.getCellFormula()));
-             c = r.getCell((short)4);
+             c = r.getCell(4);
             assertTrue("SUM($A$3,$A$2)", ("SUM($A$3,$A$2)").equals(c.getCellFormula()));
             in.close();
     }
@@ -706,15 +706,15 @@ public final class TestFormulas extends TestCase {
             HSSFSheet        s      = wb.createSheet("A");
             HSSFRow          r      = null;
             HSSFCell         c      = null;
-            r = s.createRow((short)0);
-            c = r.createCell((short)0);c.setCellValue(1);
-            c = r.createCell((short)1);c.setCellValue(2);
+            r = s.createRow(0);
+            c = r.createCell(0);c.setCellValue(1);
+            c = r.createCell(1);c.setCellValue(2);
 
             s      = wb.createSheet("B");
-            r = s.createRow((short)0);
-            c=r.createCell((short)0); c.setCellFormula("AVERAGE(A!A1:B1)");
-            c=r.createCell((short)1); c.setCellFormula("A!A1+A!B1");
-            c=r.createCell((short)2); c.setCellFormula("A!$A$1+A!$B1");
+            r = s.createRow(0);
+            c=r.createCell(0); c.setCellFormula("AVERAGE(A!A1:B1)");
+            c=r.createCell(1); c.setCellFormula("A!A1+A!B1");
+            c=r.createCell(2); c.setCellFormula("A!$A$1+A!$B1");
             wb.write(out);
             out.close();
 
@@ -724,9 +724,9 @@ public final class TestFormulas extends TestCase {
             wb = new HSSFWorkbook(in);
             s = wb.getSheet("B");
             r = s.getRow(0);
-            c = r.getCell((short)0);
+            c = r.getCell(0);
             assertTrue("expected: AVERAGE(A!A1:B1) got: "+c.getCellFormula(), ("AVERAGE(A!A1:B1)").equals(c.getCellFormula()));
-            c = r.getCell((short)1);
+            c = r.getCell(1);
             assertTrue("expected: A!A1+A!B1 got: "+c.getCellFormula(), ("A!A1+A!B1").equals(c.getCellFormula()));
             in.close();
     }
@@ -740,29 +740,29 @@ public final class TestFormulas extends TestCase {
             HSSFCell         c      = null;
 
 
-            r = s.createRow((short) 0);
+            r = s.createRow(0);
 
-            c = r.createCell((short) 0);
+            c = r.createCell(0);
             c.setCellFormula("A3+A2");
-            c=r.createCell( (short) 1);
+            c=r.createCell(1);
             c.setCellFormula("AVERAGE(A3,A2)");
-            c=r.createCell( (short) 2);
+            c=r.createCell(2);
             c.setCellFormula("ROW(A3)");
-            c=r.createCell( (short) 3);
+            c=r.createCell(3);
             c.setCellFormula("AVERAGE(A2:A3)");
-            c=r.createCell( (short) 4);
+            c=r.createCell(4);
             c.setCellFormula("POWER(A2,A3)");
-            c=r.createCell( (short) 5);
+            c=r.createCell(5);
             c.setCellFormula("SIN(A2)");
 
-            c=r.createCell( (short) 6);
+            c=r.createCell(6);
             c.setCellFormula("SUM(A2:A3)");
 
-            c=r.createCell( (short) 7);
+            c=r.createCell(7);
             c.setCellFormula("SUM(A2,A3)");
 
-            r = s.createRow((short) 1);c=r.createCell( (short) 0); c.setCellValue(2.0);
-             r = s.createRow((short) 2);c=r.createCell( (short) 0); c.setCellValue(3.0);
+            r = s.createRow(1);c=r.createCell(0); c.setCellValue(2.0);
+             r = s.createRow(2);c=r.createCell(0); c.setCellValue(3.0);
 
             wb.write(out);
             out.close();
@@ -778,10 +778,10 @@ public final class TestFormulas extends TestCase {
             HSSFSheet        s      = wb.createSheet("A");
             HSSFRow          r      = null;
             HSSFCell         c      = null;
-            r = s.createRow((short)0);
-            c=r.createCell((short)1); c.setCellFormula("UPPER(\"abc\")");
-            c=r.createCell((short)2); c.setCellFormula("LOWER(\"ABC\")");
-            c=r.createCell((short)3); c.setCellFormula("CONCATENATE(\" my \",\" name \")");
+            r = s.createRow(0);
+            c=r.createCell(1); c.setCellFormula("UPPER(\"abc\")");
+            c=r.createCell(2); c.setCellFormula("LOWER(\"ABC\")");
+            c=r.createCell(3); c.setCellFormula("CONCATENATE(\" my \",\" name \")");
 
             wb.write(out);
             out.close();
@@ -789,7 +789,7 @@ public final class TestFormulas extends TestCase {
             wb = openSample("StringFormulas.xls");
             s = wb.getSheetAt(0);
             r = s.getRow(0);
-            c = r.getCell((short)0);
+            c = r.getCell(0);
             assertTrue("expected: UPPER(\"xyz\") got "+c.getCellFormula(), ("UPPER(\"xyz\")").equals(c.getCellFormula()));
             //c = r.getCell((short)1);
             //assertTrue("expected: A!A1+A!B1 got: "+c.getCellFormula(), ("A!A1+A!B1").equals(c.getCellFormula()));
@@ -807,8 +807,8 @@ public final class TestFormulas extends TestCase {
             HSSFSheet        s      = wb.createSheet("A");
             HSSFRow          r      = null;
             HSSFCell         c      = null;
-            r = s.createRow((short)0);
-            c=r.createCell((short)1); c.setCellFormula("IF(A1<A2,B1,B2)");
+            r = s.createRow(0);
+            c=r.createCell(1); c.setCellFormula("IF(A1<A2,B1,B2)");
 
 
             wb.write(out);
@@ -820,7 +820,7 @@ public final class TestFormulas extends TestCase {
             wb = new HSSFWorkbook(in);
             s = wb.getSheetAt(0);
             r = s.getRow(0);
-            c = r.getCell((short)1);
+            c = r.getCell(1);
             assertEquals("Formula in cell 1 ","IF(A1<A2,B1,B2)",c.getCellFormula());
             in.close();
     }
@@ -835,8 +835,8 @@ public final class TestFormulas extends TestCase {
             HSSFRow          r      = null;
             HSSFCell         c      = null;
 
-            r = s.createRow(  (short)0 );
-            c = r.createCell( (short)0 );
+            r = s.createRow(0 );
+            c = r.createCell(0 );
 
             HSSFCellStyle cellStyle = wb.createCellStyle();
             cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
@@ -847,8 +847,8 @@ public final class TestFormulas extends TestCase {
            //              HSSFDateUtil.getJavaDate(excelDate).getTime());
 
             for (int k=1; k < 100; k++) {
-              r=s.createRow((short)k);
-              c=r.createCell((short)0);
+              r=s.createRow(k);
+              c=r.createCell(0);
               c.setCellFormula("A"+(k)+"+1");
               c.setCellStyle(cellStyle);
             }
@@ -870,11 +870,11 @@ public final class TestFormulas extends TestCase {
             HSSFSheet        s      = wb.createSheet("testSheet1");
             HSSFRow          r      = null;
             HSSFCell         c      = null;
-            r = s.createRow((short)0);
-            c=r.createCell((short)1); c.setCellValue(1);
-            c=r.createCell((short)2); c.setCellValue(2);
-            c=r.createCell((short)3); c.setCellFormula("MAX(A1:B1)");
-            c=r.createCell((short)4); c.setCellFormula("IF(A1=D1,\"A1\",\"B1\")");
+            r = s.createRow(0);
+            c=r.createCell(1); c.setCellValue(1);
+            c=r.createCell(2); c.setCellValue(2);
+            c=r.createCell(3); c.setCellFormula("MAX(A1:B1)");
+            c=r.createCell(4); c.setCellFormula("IF(A1=D1,\"A1\",\"B1\")");
 
             wb.write(out);
             out.close();
@@ -885,7 +885,7 @@ public final class TestFormulas extends TestCase {
             wb = new HSSFWorkbook(in);
             s = wb.getSheetAt(0);
             r = s.getRow(0);
-            c = r.getCell((short)4);
+            c = r.getCell(4);
 
             assertTrue("expected: IF(A1=D1,\"A1\",\"B1\") got "+c.getCellFormula(), ("IF(A1=D1,\"A1\",\"B1\")").equals(c.getCellFormula()));
             in.close();
@@ -893,7 +893,7 @@ public final class TestFormulas extends TestCase {
             wb = openSample("IfFormulaTest.xls");
             s = wb.getSheetAt(0);
             r = s.getRow(3);
-            c = r.getCell((short)0);
+            c = r.getCell(0);
             assertTrue("expected: IF(A3=A1,\"A1\",\"A2\") got "+c.getCellFormula(), ("IF(A3=A1,\"A1\",\"A2\")").equals(c.getCellFormula()));
             //c = r.getCell((short)1);
             //assertTrue("expected: A!A1+A!B1 got: "+c.getCellFormula(), ("A!A1+A!B1").equals(c.getCellFormula()));
@@ -905,8 +905,8 @@ public final class TestFormulas extends TestCase {
         s      = wb.createSheet("testSheet1");
         r      = null;
         c      = null;
-        r = s.createRow((short)0);
-        c=r.createCell((short)0); c.setCellFormula("IF(1=1,0,1)");
+        r = s.createRow(0);
+        c=r.createCell(0); c.setCellFormula("IF(1=1,0,1)");
 
         wb.write(out);
         out.close();
@@ -920,21 +920,21 @@ public final class TestFormulas extends TestCase {
         s      = wb.createSheet("testSheet1");
         r      = null;
         c      = null;
-        r = s.createRow((short)0);
-        c=r.createCell((short)0);
+        r = s.createRow(0);
+        c=r.createCell(0);
         c.setCellValue(1);
 
-        c=r.createCell((short)1);
+        c=r.createCell(1);
         c.setCellValue(3);
 
 
-        HSSFCell formulaCell=r.createCell((short)3);
+        HSSFCell formulaCell=r.createCell(3);
 
-        r = s.createRow((short)1);
-        c=r.createCell((short)0);
+        r = s.createRow(1);
+        c=r.createCell(0);
         c.setCellValue(3);
 
-        c=r.createCell((short)1);
+        c=r.createCell(1);
         c.setCellValue(7);
 
         formulaCell.setCellFormula("IF(A1=B1,AVERAGE(A1:B1),AVERAGE(A2:B2))");
@@ -956,7 +956,7 @@ public final class TestFormulas extends TestCase {
 
         HSSFSheet        s      = wb.getSheetAt(0);
         HSSFRow          r      = s.getRow(0);
-        HSSFCell         c      = r.getCell((short)2);
+        HSSFCell         c      = r.getCell(2);
         assertEquals(function, c.getCellFormula());
 
 
@@ -965,29 +965,29 @@ public final class TestFormulas extends TestCase {
         wb     = new HSSFWorkbook();
         s      = wb.createSheet();
 
-        r = s.createRow((short)0);
-        c=r.createCell((short)0); c.setCellValue((double)1000);
-        c=r.createCell((short)1); c.setCellValue((double)1);
+        r = s.createRow(0);
+        c=r.createCell(0); c.setCellValue((double)1000);
+        c=r.createCell(1); c.setCellValue((double)1);
 
 
-        r = s.createRow((short)1);
-        c=r.createCell((short)0); c.setCellValue((double)2000);
-        c=r.createCell((short)1); c.setCellValue((double)2);
+        r = s.createRow(1);
+        c=r.createCell(0); c.setCellValue((double)2000);
+        c=r.createCell(1); c.setCellValue((double)2);
 
-        r = s.createRow((short)2);
-        c=r.createCell((short)0); c.setCellValue((double)3000);
-        c=r.createCell((short)1); c.setCellValue((double)3);
+        r = s.createRow(2);
+        c=r.createCell(0); c.setCellValue((double)3000);
+        c=r.createCell(1); c.setCellValue((double)3);
 
-        r = s.createRow((short)3);
-        c=r.createCell((short)0); c.setCellValue((double)4000);
-        c=r.createCell((short)1); c.setCellValue((double)4);
+        r = s.createRow(3);
+        c=r.createCell(0); c.setCellValue((double)4000);
+        c=r.createCell(1); c.setCellValue((double)4);
 
-        r = s.createRow((short)4);
-        c=r.createCell((short)0); c.setCellValue((double)5000);
-        c=r.createCell((short)1); c.setCellValue((double)5);
+        r = s.createRow(4);
+        c=r.createCell(0); c.setCellValue((double)5000);
+        c=r.createCell(1); c.setCellValue((double)5);
 
         r = s.getRow(0);
-        c=r.createCell((short)2); c.setCellFormula(function);
+        c=r.createCell(2); c.setCellFormula(function);
 
         wb.write(out);
         out.close();
@@ -1002,42 +1002,42 @@ public final class TestFormulas extends TestCase {
         HSSFSheet s0 = w.getSheetAt(0);
         HSSFRow[] r = {s0.getRow(0), s0.getRow(1)};
 
-        HSSFCell a1 = r[0].getCell((short) 0);
+        HSSFCell a1 = r[0].getCell(0);
         assertEquals("square(1)", a1.getCellFormula());
         assertEquals(1d, a1.getNumericCellValue(), 1e-9);
 
-        HSSFCell a2 = r[1].getCell((short) 0);
+        HSSFCell a2 = r[1].getCell(0);
         assertEquals("square(2)", a2.getCellFormula());
         assertEquals(4d, a2.getNumericCellValue(), 1e-9);
 
-        HSSFCell b1 = r[0].getCell((short) 1);
+        HSSFCell b1 = r[0].getCell(1);
         assertEquals("IF(TRUE,square(1))", b1.getCellFormula());
         assertEquals(1d, b1.getNumericCellValue(), 1e-9);
 
-        HSSFCell b2 = r[1].getCell((short) 1);
+        HSSFCell b2 = r[1].getCell(1);
         assertEquals("IF(TRUE,square(2))", b2.getCellFormula());
         assertEquals(4d, b2.getNumericCellValue(), 1e-9);
 
-        HSSFCell c1 = r[0].getCell((short) 2);
+        HSSFCell c1 = r[0].getCell(2);
         assertEquals("square(square(1))", c1.getCellFormula());
         assertEquals(1d, c1.getNumericCellValue(), 1e-9);
 
-        HSSFCell c2 = r[1].getCell((short) 2);
+        HSSFCell c2 = r[1].getCell(2);
         assertEquals("square(square(2))", c2.getCellFormula());
         assertEquals(16d, c2.getNumericCellValue(), 1e-9);
 
-        HSSFCell d1 = r[0].getCell((short) 3);
+        HSSFCell d1 = r[0].getCell(3);
         assertEquals("square(one())", d1.getCellFormula());
         assertEquals(1d, d1.getNumericCellValue(), 1e-9);
 
-        HSSFCell d2 = r[1].getCell((short) 3);
+        HSSFCell d2 = r[1].getCell(3);
         assertEquals("square(two())", d2.getCellFormula());
         assertEquals(4d, d2.getNumericCellValue(), 1e-9);
     }
 
     public void testStringFormulaRead() {
         HSSFWorkbook w = openSample("StringFormulas.xls");
-        HSSFCell c = w.getSheetAt(0).getRow(0).getCell((short)0);
+        HSSFCell c = w.getSheetAt(0).getRow(0).getCell(0);
         assertEquals("String Cell value","XYZ",c.getRichStringCellValue().getString());
     }
 
@@ -1046,8 +1046,8 @@ public final class TestFormulas extends TestCase {
          HSSFWorkbook sb = new HSSFWorkbook();
          HSSFSheet s1 = sb.createSheet("Sheet a.1");
          HSSFSheet s2 = sb.createSheet("Sheet.A");
-         s2.createRow(1).createCell((short) 2).setCellFormula("'Sheet a.1'!A1");
-         s1.createRow(1).createCell((short) 2).setCellFormula("'Sheet.A'!A1");
+         s2.createRow(1).createCell(2).setCellFormula("'Sheet a.1'!A1");
+         s1.createRow(1).createCell(2).setCellFormula("'Sheet.A'!A1");
          File file = TempFile.createTempFile("testComplexSheetRefs",".xls");
          sb.write(new FileOutputStream(file));
     }
@@ -1073,17 +1073,17 @@ public final class TestFormulas extends TestCase {
     /* MissingArgPtg */
     public void testMissingArgPtg() throws Exception {
         HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFCell cell = wb.createSheet("Sheet1").createRow(4).createCell((short) 0);
+        HSSFCell cell = wb.createSheet("Sheet1").createRow(4).createCell(0);
         cell.setCellFormula("IF(A1=\"A\",1,)");
     }
 
     public void testSharedFormula() {
         HSSFWorkbook wb = openSample("SharedFormulaTest.xls");
 
-        assertEquals("A$1*2", wb.getSheetAt(0).getRow(1).getCell((short)1).toString());
-        assertEquals("$A11*2", wb.getSheetAt(0).getRow(11).getCell((short)1).toString());
-        assertEquals("DZ2*2", wb.getSheetAt(0).getRow(1).getCell((short)128).toString());
-        assertEquals("B32770*2", wb.getSheetAt(0).getRow(32768).getCell((short)1).toString());
+        assertEquals("A$1*2", wb.getSheetAt(0).getRow(1).getCell(1).toString());
+        assertEquals("$A11*2", wb.getSheetAt(0).getRow(11).getCell(1).toString());
+        assertEquals("DZ2*2", wb.getSheetAt(0).getRow(1).getCell(128).toString());
+        assertEquals("B32770*2", wb.getSheetAt(0).getRow(32768).getCell(1).toString());
     }
 
     public static void main(String [] args) {
index da5d2cc6a991bf123e8fc5b22d46ec4075e76f52..30f63ab4a2027790f420ba8b76ee1804fd2cc1fb 100644 (file)
@@ -76,7 +76,7 @@ public final class TestHSSFCell extends TestCase {
         HSSFSheet        s      = wb.createSheet("testSheet1");
         HSSFRow          r      = null;
         HSSFCell         c      = null;
-        r = s.createRow((short)0);
+        r = s.createRow(0);
         c=r.createCell(1);
         //c.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);
         c.setCellValue(true);
@@ -85,7 +85,7 @@ public final class TestHSSFCell extends TestCase {
         //c.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);
         c.setCellValue(false);
 
-        r = s.createRow((short)1);
+        r = s.createRow(1);
         c=r.createCell(1);
         //c.setCellType(HSSFCell.CELL_TYPE_ERROR);
         c.setCellErrorValue((byte)0);
@@ -241,7 +241,7 @@ public final class TestHSSFCell extends TestCase {
             cs.setBorderLeft((short)1);
             cs.setBorderBottom((short)1);
             
-            r = s.createRow((short)0);
+            r = s.createRow(0);
             c=r.createCell(0);
             c.setCellStyle(cs);
             c.setCellFormula("2*3");
index 978f43577382887cc8d8f77d3a7df90366634590..4ea0762dda577b6fe082c15c628cae5b8d90e936 100644 (file)
@@ -116,7 +116,7 @@ public final class TestHSSFComment extends TestCase {
 
          for (int rownum = 0; rownum < 3; rownum++) {
              row = sheet.getRow(rownum);
-             cell = row.getCell((short)0);
+             cell = row.getCell(0);
              comment = cell.getCellComment();
              assertNull("Cells in the first column are not commented", comment);
              assertNull(sheet.getCellComment(rownum, 0));
@@ -124,7 +124,7 @@ public final class TestHSSFComment extends TestCase {
 
          for (int rownum = 0; rownum < 3; rownum++) {
              row = sheet.getRow(rownum);
-             cell = row.getCell((short)1);
+             cell = row.getCell(1);
              comment = cell.getCellComment();
              assertNotNull("Cells in the second column have comments", comment);
              assertNotNull("Cells in the second column have comments", sheet.getCellComment(rownum, 1));
@@ -153,7 +153,7 @@ public final class TestHSSFComment extends TestCase {
 
          for (int rownum = 0; rownum < 3; rownum++) {
              row = sheet.getRow(rownum);
-             cell = row.getCell((short)1);
+             cell = row.getCell(1);
              comment = cell.getCellComment();
              comment.setAuthor("Mofified["+rownum+"] by Yegor");
              comment.setString(new HSSFRichTextString("Modified comment at row " + rownum));
@@ -168,7 +168,7 @@ public final class TestHSSFComment extends TestCase {
 
         for (int rownum = 0; rownum < 3; rownum++) {
             row = sheet.getRow(rownum);
-            cell = row.getCell((short)1);
+            cell = row.getCell(1);
             comment = cell.getCellComment();
 
             assertEquals("Mofified["+rownum+"] by Yegor", comment.getAuthor());
index fcb0b8f41e185aa2e3dfc26ed720090ce0dc433b..f9e62ffbf9d8a72988ba0fc7b6234f4cff7ab7a7 100644 (file)
@@ -17,6 +17,7 @@
 
 package org.apache.poi.hssf.usermodel;
 
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator;
@@ -109,4 +110,44 @@ public final class TestHSSFConditionalFormatting extends TestCase
                assertEquals("2",rule2.getFormula2()); 
                assertEquals("1",rule2.getFormula1()); 
        }
+       
+       public void testClone() {
+
+               HSSFWorkbook wb = new HSSFWorkbook();
+               HSSFSheet sheet = wb.createSheet();
+               String formula = "7";
+
+               HSSFSheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
+               
+               HSSFConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(formula);
+               HSSFFontFormatting fontFmt = rule1.createFontFormatting();
+               fontFmt.setFontStyle(true, false);
+
+               HSSFPatternFormatting patternFmt = rule1.createPatternFormatting();
+               patternFmt.setFillBackgroundColor(HSSFColor.YELLOW.index);
+
+               
+               HSSFConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule(ComparisonOperator.BETWEEN, "1", "2");
+               HSSFConditionalFormattingRule [] cfRules =
+               {
+                       rule1, rule2
+               };
+
+               short col = 1;
+               CellRangeAddress [] regions = {
+                       new CellRangeAddress(0, 65535, col, col)
+               };
+
+               sheetCF.addConditionalFormatting(regions, cfRules);
+                       
+               try {
+                       wb.cloneSheet(0);
+               } catch (RuntimeException e) {
+                       if (e.getMessage().indexOf("needs to define a clone method") > 0) {
+                               throw new AssertionFailedError("Indentified bug 45682");
+                       }
+                       throw e;
+               }
+               assertEquals(2, wb.getNumberOfSheets());
+       }
 }
index 377a8ffe2474980728c364260f7746e0280767d4..9e451ee052aed2aa2167b7539fd1fe00a3a88af0 100644 (file)
@@ -16,7 +16,6 @@
    limitations under the License.
 ==================================================================== */
 
-
 package org.apache.poi.hssf.usermodel;
 
 import java.util.Calendar;
@@ -52,9 +51,7 @@ public final class TestHSSFDateUtil extends TestCase {
      * Checks the date conversion functions in the HSSFDateUtil class.
      */
 
-    public void testDateConversion()
-            throws Exception
-    {
+    public void testDateConversion() {
 
         // Iteratating over the hours exposes any rounding issues.
         for (int hour = 0; hour < 23; hour++)
@@ -131,7 +128,7 @@ public final class TestHSSFDateUtil extends TestCase {
         for (int hour = 0; hour < 24; hour++, excelDate += oneHour) {
 
             // Skip 02:00 CET as that is the Daylight change time
-            // and Java converts it automatically to 03:00 CEST            
+            // and Java converts it automatically to 03:00 CEST
             if (hour == 2) {
                 continue;
             }
@@ -186,7 +183,7 @@ public final class TestHSSFDateUtil extends TestCase {
                     HSSFDateUtil.getExcelDate(javaDate, false), oneMinute);
         }
     }
-    
+
     /**
      * Tests that we deal with time-zones properly
      */
@@ -207,8 +204,7 @@ public final class TestHSSFDateUtil extends TestCase {
             assertEquals("Checking timezone " + id, expected.getTime(), javaDate.getTime());
         }
     }
-    
-    
+
     /**
      * Tests that we correctly detect date formats as such
      */
@@ -220,7 +216,7 @@ public final class TestHSSFDateUtil extends TestCase {
             assertTrue( HSSFDateUtil.isInternalDateFormat(builtins[i]) );
             assertTrue( HSSFDateUtil.isADateFormat(builtins[i],formatStr) );
         }
-        
+
         // Now try a few built-in non date formats
         builtins = new short[] { 0x01, 0x02, 0x17, 0x1f, 0x30 };
         for(int i=0; i<builtins.length; i++) {
@@ -228,14 +224,14 @@ public final class TestHSSFDateUtil extends TestCase {
             assertFalse( HSSFDateUtil.isInternalDateFormat(builtins[i]) );
             assertFalse( HSSFDateUtil.isADateFormat(builtins[i],formatStr) );
         }
-        
+
         // Now for some non-internal ones
         // These come after the real ones
         int numBuiltins = HSSFDataFormat.getNumberOfBuiltinBuiltinFormats();
         assertTrue(numBuiltins < 60);
         short formatId = 60;
         assertFalse( HSSFDateUtil.isInternalDateFormat(formatId) );
-        
+
         // Valid ones first
         String[] formats = new String[] {
                 "yyyy-mm-dd", "yyyy/mm/dd", "yy/mm/dd", "yy/mmm/dd",
@@ -243,7 +239,7 @@ public final class TestHSSFDateUtil extends TestCase {
                 "dd-mm-yy", "dd-mm-yyyy",
                 "DD-MM-YY", "DD-mm-YYYY",
                 "dd\\-mm\\-yy", // Sometimes escaped
-                
+
                 // These crazy ones are valid
                 "yyyy-mm-dd;@", "yyyy/mm/dd;@",
                 "dd-mm-yy;@", "dd-mm-yyyy;@",
@@ -257,14 +253,14 @@ public final class TestHSSFDateUtil extends TestCase {
         };
         for(int i=0; i<formats.length; i++) {
             assertTrue(
-                       formats[i] + " is a date format", 
-                       HSSFDateUtil.isADateFormat(formatId, formats[i])
+                    formats[i] + " is a date format",
+                    HSSFDateUtil.isADateFormat(formatId, formats[i])
             );
         }
-        
+
         // Then time based ones too
         formats = new String[] {
-                "yyyy-mm-dd hh:mm:ss", "yyyy/mm/dd HH:MM:SS", 
+                "yyyy-mm-dd hh:mm:ss", "yyyy/mm/dd HH:MM:SS",
                 "mm/dd HH:MM", "yy/mmm/dd SS",
                 "mm/dd HH:MM AM", "mm/dd HH:MM am",
                 "mm/dd HH:MM PM", "mm/dd HH:MM pm",
@@ -272,30 +268,30 @@ public final class TestHSSFDateUtil extends TestCase {
         };
         for(int i=0; i<formats.length; i++) {
             assertTrue(
-                       formats[i] + " is a datetime format", 
-                       HSSFDateUtil.isADateFormat(formatId, formats[i])
+                    formats[i] + " is a datetime format",
+                    HSSFDateUtil.isADateFormat(formatId, formats[i])
             );
         }
-        
+
         // Then invalid ones
         formats = new String[] {
-                "yyyy*mm*dd", 
+                "yyyy*mm*dd",
                 "0.0", "0.000",
                 "0%", "0.0%",
                 "[]Foo", "[BLACK]0.00%",
                 "", null
         };
         for(int i=0; i<formats.length; i++) {
-            assertFalse( 
-                       formats[i] + " is not a date or datetime format",
-                       HSSFDateUtil.isADateFormat(formatId, formats[i])
+            assertFalse(
+                    formats[i] + " is not a date or datetime format",
+                    HSSFDateUtil.isADateFormat(formatId, formats[i])
             );
         }
-        
+
         // And these are ones we probably shouldn't allow,
         //  but would need a better regexp
         formats = new String[] {
-                "yyyy:mm:dd", 
+                "yyyy:mm:dd",
         };
         for(int i=0; i<formats.length; i++) {
         //    assertFalse( HSSFDateUtil.isADateFormat(formatId, formats[i]) );
@@ -306,63 +302,63 @@ public final class TestHSSFDateUtil extends TestCase {
      * Test that against a real, test file, we still do everything
      *  correctly
      */
-    public void testOnARealFile() throws Exception {
+    public void testOnARealFile() {
 
         HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("DateFormats.xls");
         HSSFSheet sheet       = workbook.getSheetAt(0);
         Workbook wb           = workbook.getWorkbook();
-        
+
         HSSFRow  row;
         HSSFCell cell;
         HSSFCellStyle style;
-        
+
         double aug_10_2007 = 39304.0;
-        
+
         // Should have dates in 2nd column
         // All of them are the 10th of August
         // 2 US dates, 3 UK dates
         row  = sheet.getRow(0);
-        cell = row.getCell((short)1);
+        cell = row.getCell(1);
         style = cell.getCellStyle();
         assertEquals(aug_10_2007, cell.getNumericCellValue(), 0.0001);
         assertEquals("d-mmm-yy", style.getDataFormatString());
         assertTrue(HSSFDateUtil.isInternalDateFormat(style.getDataFormat()));
         assertTrue(HSSFDateUtil.isADateFormat(style.getDataFormat(), style.getDataFormatString()));
         assertTrue(HSSFDateUtil.isCellDateFormatted(cell));
-        
+
         row  = sheet.getRow(1);
-        cell = row.getCell((short)1);
+        cell = row.getCell(1);
         style = cell.getCellStyle();
         assertEquals(aug_10_2007, cell.getNumericCellValue(), 0.0001);
         assertFalse(HSSFDateUtil.isInternalDateFormat(cell.getCellStyle().getDataFormat()));
         assertTrue(HSSFDateUtil.isADateFormat(style.getDataFormat(), style.getDataFormatString()));
         assertTrue(HSSFDateUtil.isCellDateFormatted(cell));
-        
+
         row  = sheet.getRow(2);
-        cell = row.getCell((short)1);
+        cell = row.getCell(1);
         style = cell.getCellStyle();
         assertEquals(aug_10_2007, cell.getNumericCellValue(), 0.0001);
         assertTrue(HSSFDateUtil.isInternalDateFormat(cell.getCellStyle().getDataFormat()));
         assertTrue(HSSFDateUtil.isADateFormat(style.getDataFormat(), style.getDataFormatString()));
         assertTrue(HSSFDateUtil.isCellDateFormatted(cell));
-        
+
         row  = sheet.getRow(3);
-        cell = row.getCell((short)1);
+        cell = row.getCell(1);
         style = cell.getCellStyle();
         assertEquals(aug_10_2007, cell.getNumericCellValue(), 0.0001);
         assertFalse(HSSFDateUtil.isInternalDateFormat(cell.getCellStyle().getDataFormat()));
         assertTrue(HSSFDateUtil.isADateFormat(style.getDataFormat(), style.getDataFormatString()));
         assertTrue(HSSFDateUtil.isCellDateFormatted(cell));
-        
+
         row  = sheet.getRow(4);
-        cell = row.getCell((short)1);
+        cell = row.getCell(1);
         style = cell.getCellStyle();
         assertEquals(aug_10_2007, cell.getNumericCellValue(), 0.0001);
         assertFalse(HSSFDateUtil.isInternalDateFormat(cell.getCellStyle().getDataFormat()));
         assertTrue(HSSFDateUtil.isADateFormat(style.getDataFormat(), style.getDataFormatString()));
         assertTrue(HSSFDateUtil.isCellDateFormatted(cell));
     }
-    
+
     public void testDateBug_2Excel() {
         assertEquals(59.0, HSSFDateUtil.getExcelDate(createDate(1900, CALENDAR_FEBRUARY, 28), false), 0.00001);
         assertEquals(61.0, HSSFDateUtil.getExcelDate(createDate(1900, CALENDAR_MARCH, 1), false), 0.00001);
@@ -372,41 +368,49 @@ public final class TestHSSFDateUtil extends TestCase {
         assertEquals(37257.00, HSSFDateUtil.getExcelDate(createDate(2002, CALENDAR_JANUARY, 1), false), 0.00001);
         assertEquals(38074.00, HSSFDateUtil.getExcelDate(createDate(2004, CALENDAR_MARCH, 28), false), 0.00001);
     }
-    
+
     public void testDateBug_2Java() {
         assertEquals(createDate(1900, CALENDAR_FEBRUARY, 28), HSSFDateUtil.getJavaDate(59.0, false));
         assertEquals(createDate(1900, CALENDAR_MARCH, 1), HSSFDateUtil.getJavaDate(61.0, false));
-        
+
         assertEquals(createDate(2002, CALENDAR_FEBRUARY, 28), HSSFDateUtil.getJavaDate(37315.00, false));
         assertEquals(createDate(2002, CALENDAR_MARCH, 1), HSSFDateUtil.getJavaDate(37316.00, false));
         assertEquals(createDate(2002, CALENDAR_JANUARY, 1), HSSFDateUtil.getJavaDate(37257.00, false));
         assertEquals(createDate(2004, CALENDAR_MARCH, 28), HSSFDateUtil.getJavaDate(38074.00, false));
     }
-    
+
     public void testDate1904() {
         assertEquals(createDate(1904, CALENDAR_JANUARY, 2), HSSFDateUtil.getJavaDate(1.0, true));
         assertEquals(createDate(1904, CALENDAR_JANUARY, 1), HSSFDateUtil.getJavaDate(0.0, true));
         assertEquals(0.0, HSSFDateUtil.getExcelDate(createDate(1904, CALENDAR_JANUARY, 1), true), 0.00001);
         assertEquals(1.0, HSSFDateUtil.getExcelDate(createDate(1904, CALENDAR_JANUARY, 2), true), 0.00001);
-        
+
         assertEquals(createDate(1998, CALENDAR_JULY, 5), HSSFDateUtil.getJavaDate(35981, false));
         assertEquals(createDate(1998, CALENDAR_JULY, 5), HSSFDateUtil.getJavaDate(34519, true));
-        
+
         assertEquals(35981.0, HSSFDateUtil.getExcelDate(createDate(1998, CALENDAR_JULY, 5), false), 0.00001);
         assertEquals(34519.0, HSSFDateUtil.getExcelDate(createDate(1998, CALENDAR_JULY, 5), true), 0.00001);
     }
-    
+
     /**
-     * @param month zero based 
+     * @param month zero based
      * @param day one based
      */
     private static Date createDate(int year, int month, int day) {
+        return createDate(year, month, day, 0, 0, 0);
+    }
+
+    /**
+     * @param month zero based
+     * @param day one based
+     */
+    private static Date createDate(int year, int month, int day, int hour, int minute, int second) {
         Calendar c = new GregorianCalendar();
-        c.set(year, month, day, 0, 0, 0);
+        c.set(year, month, day, hour, minute, second);
         c.set(Calendar.MILLISECOND, 0);
         return c.getTime();
     }
-    
+
     /**
      * Check if HSSFDateUtil.getAbsoluteDay works as advertised.
      */
@@ -420,16 +424,27 @@ public final class TestHSSFDateUtil extends TestCase {
     }
 
     public void testConvertTime() {
-       
+
         final double delta = 1E-7; // a couple of digits more accuracy than strictly required
         assertEquals(0.5, HSSFDateUtil.convertTime("12:00"), delta);
         assertEquals(2.0/3, HSSFDateUtil.convertTime("16:00"), delta);
         assertEquals(0.0000116, HSSFDateUtil.convertTime("0:00:01"), delta);
         assertEquals(0.7330440, HSSFDateUtil.convertTime("17:35:35"), delta);
     }
-    
+
     public void testParseDate() {
         assertEquals(createDate(2008, Calendar.AUGUST, 3), HSSFDateUtil.parseYYYYMMDDDate("2008/08/03"));
         assertEquals(createDate(1994, Calendar.MAY, 1), HSSFDateUtil.parseYYYYMMDDDate("1994/05/01"));
     }
+
+    /**
+     * Ensure that date values *with* a fractional portion get the right time of day
+     */
+    public void testConvertDateTime() {
+       // Excel day 30000 is date 18-Feb-1982 
+        // 0.7 corresponds to time 16:48:00
+        Date actual = HSSFDateUtil.getJavaDate(30000.7);
+        Date expected = createDate(1982, 1, 18, 16, 48, 0);
+        assertEquals(expected, actual);
+    }
 }
index 15ec903b4d42e2b510aaa2a85866a784fa2a523e..071e265bd7ebfb259f6df03f86da0d95753455e0 100755 (executable)
@@ -42,14 +42,14 @@ public final class TestHSSFHyperlink extends TestCase {
         HSSFHyperlink link;\r
 \r
         sheet = wb.getSheet("WebLinks");\r
-        cell = sheet.getRow(4).getCell((short)0);\r
+        cell = sheet.getRow(4).getCell(0);\r
         link = cell.getHyperlink();\r
         assertNotNull(link);\r
         assertEquals("POI", link.getLabel());\r
         assertEquals("POI", cell.getRichStringCellValue().getString());\r
         assertEquals("http://poi.apache.org/", link.getAddress());\r
 \r
-        cell = sheet.getRow(8).getCell((short)0);\r
+        cell = sheet.getRow(8).getCell(0);\r
         link = cell.getHyperlink();\r
         assertNotNull(link);\r
         assertEquals("HSSF", link.getLabel());\r
@@ -57,7 +57,7 @@ public final class TestHSSFHyperlink extends TestCase {
         assertEquals("http://poi.apache.org/hssf/", link.getAddress());\r
 \r
         sheet = wb.getSheet("Emails");\r
-        cell = sheet.getRow(4).getCell((short)0);\r
+        cell = sheet.getRow(4).getCell(0);\r
         link = cell.getHyperlink();\r
         assertNotNull(link);\r
         assertEquals("dev", link.getLabel());\r
@@ -65,7 +65,7 @@ public final class TestHSSFHyperlink extends TestCase {
         assertEquals("mailto:dev@poi.apache.org", link.getAddress());\r
 \r
         sheet = wb.getSheet("Internal");\r
-        cell = sheet.getRow(4).getCell((short)0);\r
+        cell = sheet.getRow(4).getCell(0);\r
         link = cell.getHyperlink();\r
         assertNotNull(link);\r
         assertEquals("Link To First Sheet", link.getLabel());\r
@@ -81,7 +81,7 @@ public final class TestHSSFHyperlink extends TestCase {
         HSSFHyperlink link;\r
 \r
         sheet = wb.getSheet("WebLinks");\r
-        cell = sheet.getRow(4).getCell((short)0);\r
+        cell = sheet.getRow(4).getCell(0);\r
         link = cell.getHyperlink();\r
         //modify the link\r
         link.setAddress("www.apache.org");\r
@@ -92,7 +92,7 @@ public final class TestHSSFHyperlink extends TestCase {
 \r
         wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));\r
         sheet = wb.getSheet("WebLinks");\r
-        cell = sheet.getRow(4).getCell((short)0);\r
+        cell = sheet.getRow(4).getCell(0);\r
         link = cell.getHyperlink();\r
         assertNotNull(link);\r
         assertEquals("www.apache.org", link.getAddress());\r
@@ -106,21 +106,21 @@ public final class TestHSSFHyperlink extends TestCase {
         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
         cell.setHyperlink(link);\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
         cell.setHyperlink(link);\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
@@ -131,9 +131,9 @@ public final class TestHSSFHyperlink extends TestCase {
 \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
@@ -145,22 +145,22 @@ public final class TestHSSFHyperlink extends TestCase {
 \r
         wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));\r
         sheet = wb.getSheet("Hyperlinks");\r
-        cell = sheet.getRow(0).getCell((short)0);\r
+        cell = sheet.getRow(0).getCell(0);\r
         link = cell.getHyperlink();\r
         assertNotNull(link);\r
         assertEquals("http://poi.apache.org/", link.getAddress());\r
 \r
-        cell = sheet.getRow(1).getCell((short)0);\r
+        cell = sheet.getRow(1).getCell(0);\r
         link = cell.getHyperlink();\r
         assertNotNull(link);\r
         assertEquals("link1.xls", link.getAddress());\r
 \r
-        cell = sheet.getRow(2).getCell((short)0);\r
+        cell = sheet.getRow(2).getCell(0);\r
         link = cell.getHyperlink();\r
         assertNotNull(link);\r
         assertEquals("mailto:poi@apache.org?subject=Hyperlinks", link.getAddress());\r
 \r
-        cell = sheet.getRow(3).getCell((short)0);\r
+        cell = sheet.getRow(3).getCell(0);\r
         link = cell.getHyperlink();\r
         assertNotNull(link);\r
         assertEquals("'Target Sheet'!A1", link.getAddress());\r
@@ -174,12 +174,12 @@ public final class TestHSSFHyperlink extends TestCase {
 \r
         HSSFSheet sheet = wb.cloneSheet(0);\r
 \r
-        cell = sheet.getRow(4).getCell((short)0);\r
+        cell = sheet.getRow(4).getCell(0);\r
         link = cell.getHyperlink();\r
         assertNotNull(link);\r
         assertEquals("http://poi.apache.org/", link.getAddress());\r
 \r
-        cell = sheet.getRow(8).getCell((short)0);\r
+        cell = sheet.getRow(8).getCell(0);\r
         link = cell.getHyperlink();\r
         assertNotNull(link);\r
         assertEquals("http://poi.apache.org/hssf/", link.getAddress());\r
index b998fdd5191702df0cd5840e6a5719f8460a561a..a3efa0393dfc38b7b82658b33e2f7541936604ae 100644 (file)
@@ -107,13 +107,13 @@ public class TestHSSFOptimiser extends TestCase {
                HSSFRichTextString rtr1 = new HSSFRichTextString("Test");
                rtr1.applyFont(0, 2, f1);
                rtr1.applyFont(3, 4, f2);
-               r.createCell((short)0).setCellValue(rtr1);
+               r.createCell(0).setCellValue(rtr1);
                
                HSSFRichTextString rtr2 = new HSSFRichTextString("AlsoTest");
                rtr2.applyFont(0, 2, f3);
                rtr2.applyFont(3, 5, f5);
                rtr2.applyFont(6, 8, f6);
-               r.createCell((short)1).setCellValue(rtr2);
+               r.createCell(1).setCellValue(rtr2);
                
                
                // Check what we have now
@@ -198,14 +198,14 @@ public class TestHSSFOptimiser extends TestCase {
                HSSFSheet s = wb.createSheet();
                HSSFRow r = s.createRow(0);
                
-               r.createCell((short)0).setCellStyle(cs1);
-               r.createCell((short)1).setCellStyle(cs2);
-               r.createCell((short)2).setCellStyle(cs3);
-               r.createCell((short)3).setCellStyle(cs4);
-               r.createCell((short)4).setCellStyle(cs5);
-               r.createCell((short)5).setCellStyle(cs6);
-               r.createCell((short)6).setCellStyle(cs1);
-               r.createCell((short)7).setCellStyle(cs2);
+               r.createCell(0).setCellStyle(cs1);
+               r.createCell(1).setCellStyle(cs2);
+               r.createCell(2).setCellStyle(cs3);
+               r.createCell(3).setCellStyle(cs4);
+               r.createCell(4).setCellStyle(cs5);
+               r.createCell(5).setCellStyle(cs6);
+               r.createCell(6).setCellStyle(cs1);
+               r.createCell(7).setCellStyle(cs2);
                
                assertEquals(21, r.getCell(0).getCellValueRecord().getXFIndex());
                assertEquals(26, r.getCell(5).getCellValueRecord().getXFIndex());
index c3c0ed22597255c07300b0c48edac5af2f3da1d5..3ce255a0e4150331d76c8934efb097a0deb39fd0 100644 (file)
@@ -94,11 +94,11 @@ public final class TestHSSFPalette extends TestCase {
         
         HSSFPalette p = book.getCustomPalette();
         
-        HSSFCell cellA = book.getSheetAt(0).getRow(0).getCell((short)0);
-        HSSFCell cellB = book.getSheetAt(0).getRow(1).getCell((short)0);
-        HSSFCell cellC = book.getSheetAt(0).getRow(2).getCell((short)0);
-        HSSFCell cellD = book.getSheetAt(0).getRow(3).getCell((short)0);
-        HSSFCell cellE = book.getSheetAt(0).getRow(4).getCell((short)0);
+        HSSFCell cellA = book.getSheetAt(0).getRow(0).getCell(0);
+        HSSFCell cellB = book.getSheetAt(0).getRow(1).getCell(0);
+        HSSFCell cellC = book.getSheetAt(0).getRow(2).getCell(0);
+        HSSFCell cellD = book.getSheetAt(0).getRow(3).getCell(0);
+        HSSFCell cellE = book.getSheetAt(0).getRow(4).getCell(0);
         
         // Plain
         assertEquals("I'm plain", cellA.getStringCellValue());
index b09753bcbd1ec6127a7a31475854a12550315c37..c9b3bc74d1120c714fea2285f1c4b4def8039dde 100644 (file)
@@ -36,16 +36,16 @@ public final class TestHSSFRow extends TestCase {
         assertEquals(-1, row.getFirstCellNum());
         assertEquals(-1, row.getLastCellNum());
 
-        row.createCell((short) 2);
+        row.createCell(2);
         assertEquals(2, row.getFirstCellNum());
         assertEquals(3, row.getLastCellNum());
 
-        row.createCell((short) 1);
+        row.createCell(1);
         assertEquals(1, row.getFirstCellNum());
         assertEquals(3, row.getLastCellNum());
 
         // check the exact case reported in 'bug' 43901 - notice that the cellNum is '0' based
-        row.createCell((short) 3);
+        row.createCell(3);
         assertEquals(1, row.getFirstCellNum());
         assertEquals(4, row.getLastCellNum());
     }
@@ -59,20 +59,20 @@ public final class TestHSSFRow extends TestCase {
         HSSFSheet sheet = workbook.createSheet();
         HSSFRow rowA = sheet.createRow(0);
 
-        rowA.createCell((short) 10);
-        rowA.createCell((short) 5);
+        rowA.createCell(10);
+        rowA.createCell(5);
         assertEquals(5, rowA.getFirstCellNum());
         assertEquals(11, rowA.getLastCellNum());
 
         HSSFRow rowB = sheet.createRow(1);
-        rowB.createCell((short) 15);
-        rowB.createCell((short) 30);
+        rowB.createCell(15);
+        rowB.createCell(30);
         assertEquals(15, rowB.getFirstCellNum());
         assertEquals(31, rowB.getLastCellNum());
 
         assertEquals(5, rowA.getFirstCellNum());
         assertEquals(11, rowA.getLastCellNum());
-        rowA.createCell((short) 50);
+        rowA.createCell(50);
         assertEquals(51, rowA.getLastCellNum());
 
         assertEquals(31, rowB.getLastCellNum());
@@ -81,19 +81,19 @@ public final class TestHSSFRow extends TestCase {
     public void testRemoveCell() {
         HSSFWorkbook workbook = new HSSFWorkbook();
         HSSFSheet sheet = workbook.createSheet();
-        HSSFRow row = sheet.createRow((short) 0);
+        HSSFRow row = sheet.createRow(0);
         assertEquals(-1, row.getLastCellNum());
         assertEquals(-1, row.getFirstCellNum());
-        row.createCell((short) 1);
+        row.createCell(1);
         assertEquals(2, row.getLastCellNum());
         assertEquals(1, row.getFirstCellNum());
-        row.createCell((short) 3);
+        row.createCell(3);
         assertEquals(4, row.getLastCellNum());
         assertEquals(1, row.getFirstCellNum());
-        row.removeCell(row.getCell((short) 3));
+        row.removeCell(row.getCell(3));
         assertEquals(2, row.getLastCellNum());
         assertEquals(1, row.getFirstCellNum());
-        row.removeCell(row.getCell((short) 1));
+        row.removeCell(row.getCell(1));
         assertEquals(-1, row.getLastCellNum());
         assertEquals(-1, row.getFirstCellNum());
 
@@ -114,18 +114,18 @@ public final class TestHSSFRow extends TestCase {
     public void testMoveCell() {
         HSSFWorkbook workbook = new HSSFWorkbook();
         HSSFSheet sheet = workbook.createSheet();
-        HSSFRow row = sheet.createRow((short) 0);
-        HSSFRow rowB = sheet.createRow((short) 1);
+        HSSFRow row = sheet.createRow(0);
+        HSSFRow rowB = sheet.createRow(1);
 
-        HSSFCell cellA2 = rowB.createCell((short)0);
+        HSSFCell cellA2 = rowB.createCell(0);
         assertEquals(0, rowB.getFirstCellNum());
         assertEquals(0, rowB.getFirstCellNum());
 
         assertEquals(-1, row.getLastCellNum());
         assertEquals(-1, row.getFirstCellNum());
-        HSSFCell cellB2 = row.createCell((short) 1);
-        HSSFCell cellB3 = row.createCell((short) 2);
-        HSSFCell cellB4 = row.createCell((short) 3);
+        HSSFCell cellB2 = row.createCell(1);
+        HSSFCell cellB3 = row.createCell(2);
+        HSSFCell cellB4 = row.createCell(3);
 
         assertEquals(1, row.getFirstCellNum());
         assertEquals(4, row.getLastCellNum());
@@ -147,10 +147,10 @@ public final class TestHSSFRow extends TestCase {
         }
 
         // Move somewhere spare
-        assertNotNull(row.getCell((short)1));
+        assertNotNull(row.getCell(1));
         row.moveCell(cellB2, (short)5);
-        assertNull(row.getCell((short)1));
-        assertNotNull(row.getCell((short)5));
+        assertNull(row.getCell(1));
+        assertNotNull(row.getCell(5));
 
         assertEquals(5, cellB2.getCellNum());
         assertEquals(2, row.getFirstCellNum());
@@ -161,7 +161,7 @@ public final class TestHSSFRow extends TestCase {
       HSSFWorkbook workbook = new HSSFWorkbook();
       HSSFSheet sheet = workbook.createSheet();
       //Test low row bound
-      sheet.createRow( (short) 0);
+      sheet.createRow(0);
       //Test low row bound exception
       try {
         sheet.createRow(-1);
@@ -200,9 +200,9 @@ public final class TestHSSFRow extends TestCase {
 
         // Create two cells, will return one higher
         //  than that for the last number
-        row.createCell((short) 0);
+        row.createCell(0);
         assertEquals(1, row.getLastCellNum());
-        row.createCell((short) 255);
+        row.createCell(255);
         assertEquals(256, row.getLastCellNum());
     }
     
@@ -220,10 +220,10 @@ public final class TestHSSFRow extends TestCase {
         // 3 missing
         // 4 -> blank
         // 5 -> num
-        row.createCell((short)0).setCellValue(new HSSFRichTextString("test"));
-        row.createCell((short)1).setCellValue(3.2);
-        row.createCell((short)4, HSSFCell.CELL_TYPE_BLANK);
-        row.createCell((short)5).setCellValue(4);
+        row.createCell(0).setCellValue(new HSSFRichTextString("test"));
+        row.createCell(1).setCellValue(3.2);
+        row.createCell(4, HSSFCell.CELL_TYPE_BLANK);
+        row.createCell(5).setCellValue(4);
         
         // First up, no policy given, uses default
         assertEquals(HSSFCell.CELL_TYPE_STRING,  row.getCell(0).getCellType());
@@ -281,12 +281,12 @@ public final class TestHSSFRow extends TestCase {
     public void testRowHeight() {
         HSSFWorkbook workbook = new HSSFWorkbook();
         HSSFSheet sheet = workbook.createSheet();
-        HSSFRow row1 = sheet.createRow( (short) 0);
+        HSSFRow row1 = sheet.createRow(0);
 
         assertEquals(0xFF, row1.getHeight());
         assertEquals(sheet.getDefaultRowHeight(), row1.getHeight());
 
-        HSSFRow row2 = sheet.createRow( (short) 1);
+        HSSFRow row2 = sheet.createRow(1);
         row2.setHeight((short)400);
 
         assertEquals(400, row2.getHeight());
index a24e5e7970bcfd02eb8c5e0ee4958e2d1c94d15a..4c8c8c5d6acefe51dfec3935f8183a9c0c4f6778 100644 (file)
@@ -147,10 +147,10 @@ public final class TestHSSFSheet extends TestCase {
        public void testReadBooleans() {
                HSSFWorkbook workbook = new HSSFWorkbook();
                HSSFSheet sheet = workbook.createSheet("Test boolean");
-               HSSFRow row = sheet.createRow((short) 2);
-               HSSFCell cell = row.createCell((short) 9);
+               HSSFRow row = sheet.createRow(2);
+               HSSFCell cell = row.createCell(9);
                cell.setCellValue(true);
-               cell = row.createCell((short) 11);
+               cell = row.createCell(11);
                cell.setCellValue(true);
                
                workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
@@ -164,7 +164,7 @@ public final class TestHSSFSheet extends TestCase {
        public void testRemoveRow() {
                HSSFWorkbook workbook = new HSSFWorkbook();
                HSSFSheet sheet = workbook.createSheet("Test boolean");
-               HSSFRow row = sheet.createRow((short) 2);
+               HSSFRow row = sheet.createRow(2);
                sheet.removeRow(row);
        }
 
@@ -186,8 +186,8 @@ public final class TestHSSFSheet extends TestCase {
                HSSFWorkbook workbook = new HSSFWorkbook();
                HSSFSheet sheet = workbook.createSheet("Test Clone");
                HSSFRow row = sheet.createRow(0);
-               HSSFCell cell = row.createCell((short) 0);
-               HSSFCell cell2 = row.createCell((short) 1);
+               HSSFCell cell = row.createCell(0);
+               HSSFCell cell2 = row.createCell(1);
                cell.setCellValue(new HSSFRichTextString("clone_test"));
                cell2.setCellFormula("sin(1)");
 
@@ -216,8 +216,8 @@ public final class TestHSSFSheet extends TestCase {
        public void testCloneSheetMultipleTimes() {
                HSSFWorkbook workbook = new HSSFWorkbook();
                HSSFSheet sheet = workbook.createSheet("Test Clone");
-               HSSFRow row = sheet.createRow((short) 0);
-               HSSFCell cell = row.createCell((short) 0);
+               HSSFRow row = sheet.createRow(0);
+               HSSFCell cell = row.createCell(0);
                cell.setCellValue(new HSSFRichTextString("clone_test"));
                //Clone the sheet multiple times
                workbook.cloneSheet(0);
@@ -510,11 +510,11 @@ public final class TestHSSFSheet extends TestCase {
                HSSFWorkbook wb = new HSSFWorkbook();
                HSSFSheet sheet = wb.createSheet();
                HSSFRow row = sheet.createRow(0);
-               HSSFCell cell = row.createCell((short)0);
+               HSSFCell cell = row.createCell(0);
                cell.setCellValue(new HSSFRichTextString("first row, first cell"));
 
                row = sheet.createRow(1);
-               cell = row.createCell((short)1);
+               cell = row.createCell(1);
                cell.setCellValue(new HSSFRichTextString("second row, second cell"));
 
                CellRangeAddress region = new CellRangeAddress(1, 1, 0, 1);
@@ -617,13 +617,13 @@ public final class TestHSSFSheet extends TestCase {
                HSSFWorkbook wb = new HSSFWorkbook();
                HSSFSheet s = wb.createSheet("Sheet1");
                HSSFRow r = s.createRow(0);
-               r.createCell((short) 0).setCellValue(1);
-               r.createCell((short) 1).setCellFormula("A1*2");
+               r.createCell(0).setCellValue(1);
+               r.createCell(1).setCellFormula("A1*2");
                HSSFSheet s1 = wb.cloneSheet(0);
                r = s1.getRow(0);
-               assertEquals("double", r.getCell((short) 0).getNumericCellValue(), 1, 0); // sanity check
-               assertNotNull(r.getCell((short) 1));
-               assertEquals("formula", r.getCell((short) 1).getCellFormula(), "A1*2");
+               assertEquals("double", r.getCell(0).getNumericCellValue(), 1, 0); // sanity check
+               assertNotNull(r.getCell(1));
+               assertEquals("formula", r.getCell(1).getCellFormula(), "A1*2");
        }
 
        /** test that new default column styles get applied */
@@ -633,7 +633,7 @@ public final class TestHSSFSheet extends TestCase {
                HSSFSheet s = wb.createSheet();
                s.setDefaultColumnStyle((short) 0, style);
                HSSFRow r = s.createRow(0);
-               HSSFCell c = r.createCell((short) 0);
+               HSSFCell c = r.createCell(0);
                assertEquals("style should match", style.getIndex(), c.getCellStyle().getIndex());
        }
 
@@ -710,8 +710,8 @@ public final class TestHSSFSheet extends TestCase {
                HSSFSheet sheet = workbook.getSheetAt(0);
                HSSFSheet sheet2 = workbook.getSheetAt(0);
                HSSFRow row = sheet.getRow(0);
-               row.createCell((short) 0).setCellValue(5);
-               row.createCell((short) 1).setCellValue(8);
+               row.createCell(0).setCellValue(5);
+               row.createCell(1).setCellValue(8);
                assertFalse(sheet.getForceFormulaRecalculation());
                assertFalse(sheet2.getForceFormulaRecalculation());
 
index 35a2d955fb12fe5d4764274b328237f151fb46f7..658a3f48840e66c29e2b1f587734fdf0f62c1e45 100644 (file)
@@ -290,10 +290,10 @@ public final class TestHSSFWorkbook extends TestCase {
         assertEquals(true, sheet3.isActive());
 
         if (false) { // helpful if viewing this workbook in excel:
-            sheet1.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Sheet1"));
-            sheet2.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Sheet2"));
-            sheet3.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Sheet3"));
-            sheet4.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Sheet4"));
+            sheet1.createRow(0).createCell(0).setCellValue(new HSSFRichTextString("Sheet1"));
+            sheet2.createRow(0).createCell(0).setCellValue(new HSSFRichTextString("Sheet2"));
+            sheet3.createRow(0).createCell(0).setCellValue(new HSSFRichTextString("Sheet3"));
+            sheet4.createRow(0).createCell(0).setCellValue(new HSSFRichTextString("Sheet4"));
 
             try {
                 File fOut = TempFile.createTempFile("sheetMultiSelect", ".xls");
index 342f6e26f1531ec089d26b5b72cec5944295e8c2..186ee18a6ba1eda5c54d8676651467c32d2ff2b0 100644 (file)
@@ -39,14 +39,14 @@ public final class TestReadWriteChart extends TestCase {
         HSSFWorkbook workbook  = HSSFTestDataSamples.openSampleWorkbook("SimpleChart.xls");
         HSSFSheet       sheet     = workbook.getSheetAt(0);
         HSSFRow         firstRow  = sheet.getRow(0);
-        HSSFCell        firstCell = firstRow.getCell(( short ) 0);
+        HSSFCell        firstCell = firstRow.getCell(0);
 
         //System.out.println("first assertion for date");
         assertEquals(new GregorianCalendar(2000, 0, 1, 10, 51, 2).getTime(),
                      HSSFDateUtil
                          .getJavaDate(firstCell.getNumericCellValue(), false));
-        HSSFRow  row  = sheet.createRow(( short ) 15);
-        HSSFCell cell = row.createCell(( short ) 1);
+        HSSFRow  row  = sheet.createRow(15);
+        HSSFCell cell = row.createCell(1);
 
         cell.setCellValue(22);
         Sheet newSheet = workbook.getSheetAt(0).getSheet();
index 62a26e90b5293728aba73bd37ca2de43c7f0d33c..ddd9101593a3d6e875176d333ba51a51678d6fe8 100644 (file)
@@ -61,10 +61,10 @@ public final class TestSheetHiding extends TestCase {
                assertEquals(1, wbU.getSheetAt(1).getRow(0).getLastCellNum());
 
                // Text should be sheet based
-               assertEquals("Sheet1A1", wbH.getSheetAt(0).getRow(0).getCell((short)0).getRichStringCellValue().getString());
-               assertEquals("Sheet2A1", wbH.getSheetAt(1).getRow(0).getCell((short)0).getRichStringCellValue().getString());
-               assertEquals("Sheet1A1", wbU.getSheetAt(0).getRow(0).getCell((short)0).getRichStringCellValue().getString());
-               assertEquals("Sheet2A1", wbU.getSheetAt(1).getRow(0).getCell((short)0).getRichStringCellValue().getString());
+               assertEquals("Sheet1A1", wbH.getSheetAt(0).getRow(0).getCell(0).getRichStringCellValue().getString());
+               assertEquals("Sheet2A1", wbH.getSheetAt(1).getRow(0).getCell(0).getRichStringCellValue().getString());
+               assertEquals("Sheet1A1", wbU.getSheetAt(0).getRow(0).getCell(0).getRichStringCellValue().getString());
+               assertEquals("Sheet2A1", wbU.getSheetAt(1).getRow(0).getCell(0).getRichStringCellValue().getString());
        }
 
        /**
index 03d67cc21c9bea916e5fde57113b7e33e129ba6d..101bd325df893703ee12d6b616b6281ba667daa2 100755 (executable)
@@ -99,8 +99,8 @@ public final class TestSheetShiftRows extends TestCase {
     public void testShiftRow(){
        HSSFWorkbook b = new HSSFWorkbook();
        HSSFSheet s    = b.createSheet();
-       s.createRow(0).createCell((short)0).setCellValue("TEST1");
-       s.createRow(3).createCell((short)0).setCellValue("TEST2");
+       s.createRow(0).createCell(0).setCellValue("TEST1");
+       s.createRow(3).createCell(0).setCellValue("TEST2");
        s.shiftRows(0,4,1);
     }
 
@@ -112,8 +112,8 @@ public final class TestSheetShiftRows extends TestCase {
     public void testShiftRow0(){
        HSSFWorkbook b = new HSSFWorkbook();
        HSSFSheet s    = b.createSheet();
-       s.createRow(0).createCell((short)0).setCellValue("TEST1");
-       s.createRow(3).createCell((short)0).setCellValue("TEST2");
+       s.createRow(0).createCell(0).setCellValue("TEST1");
+       s.createRow(3).createCell(0).setCellValue("TEST2");
        s.shiftRows(0,4,1);
     }
 
@@ -125,7 +125,7 @@ public final class TestSheetShiftRows extends TestCase {
       HSSFWorkbook b = new HSSFWorkbook();
       HSSFSheet s    = b.createSheet();
       HSSFRow row = s.createRow(4);
-      row.createCell((short)0).setCellValue("test");
+      row.createCell(0).setCellValue("test");
       s.setRowBreak(4);
 
       s.shiftRows(4, 4, 2);
@@ -203,34 +203,34 @@ public final class TestSheetShiftRows extends TestCase {
         HSSFSheet sheet = wb.getSheet("Sheet1");
         assertEquals(19, sheet.getLastRowNum());
 
-        assertEquals("cell B1 (ref)", sheet.getRow(0).getCell((short)3).getRichStringCellValue().toString());
-        assertEquals("CONCATENATE(B1,\" (ref)\")", sheet.getRow(0).getCell((short)3).getCellFormula());
-        assertEquals("cell B2 (ref)", sheet.getRow(1).getCell((short)3).getRichStringCellValue().toString());
-        assertEquals("CONCATENATE(B2,\" (ref)\")", sheet.getRow(1).getCell((short)3).getCellFormula());
-        assertEquals("cell B3 (ref)", sheet.getRow(2).getCell((short)3).getRichStringCellValue().toString());
-        assertEquals("CONCATENATE(B3,\" (ref)\")", sheet.getRow(2).getCell((short)3).getCellFormula());
-        assertEquals("cell B2 (ref)", sheet.getRow(6).getCell((short)1).getRichStringCellValue().toString());
-        assertEquals("CONCATENATE(B2,\" (ref)\")", sheet.getRow(6).getCell((short)1).getCellFormula());
+        assertEquals("cell B1 (ref)", sheet.getRow(0).getCell(3).getRichStringCellValue().toString());
+        assertEquals("CONCATENATE(B1,\" (ref)\")", sheet.getRow(0).getCell(3).getCellFormula());
+        assertEquals("cell B2 (ref)", sheet.getRow(1).getCell(3).getRichStringCellValue().toString());
+        assertEquals("CONCATENATE(B2,\" (ref)\")", sheet.getRow(1).getCell(3).getCellFormula());
+        assertEquals("cell B3 (ref)", sheet.getRow(2).getCell(3).getRichStringCellValue().toString());
+        assertEquals("CONCATENATE(B3,\" (ref)\")", sheet.getRow(2).getCell(3).getCellFormula());
+        assertEquals("cell B2 (ref)", sheet.getRow(6).getCell(1).getRichStringCellValue().toString());
+        assertEquals("CONCATENATE(B2,\" (ref)\")", sheet.getRow(6).getCell(1).getCellFormula());
 
         sheet.shiftRows(1, 1, 10);
 
         // Row 1 => Row 11
         // So strings on row 11 unchanged, but reference in formula is
-        assertEquals("cell B1 (ref)", sheet.getRow(0).getCell((short)3).getRichStringCellValue().toString());
-        assertEquals("CONCATENATE(B1,\" (ref)\")", sheet.getRow(0).getCell((short)3).getCellFormula());
+        assertEquals("cell B1 (ref)", sheet.getRow(0).getCell(3).getRichStringCellValue().toString());
+        assertEquals("CONCATENATE(B1,\" (ref)\")", sheet.getRow(0).getCell(3).getCellFormula());
         assertEquals(0, sheet.getRow(1).getPhysicalNumberOfCells());
 
         // still save b2
-        assertEquals("cell B2 (ref)", sheet.getRow(11).getCell((short)3).getRichStringCellValue().toString());
+        assertEquals("cell B2 (ref)", sheet.getRow(11).getCell(3).getRichStringCellValue().toString());
         // but points to b12
-        assertEquals("CONCATENATE(B12,\" (ref)\")", sheet.getRow(11).getCell((short)3).getCellFormula());
+        assertEquals("CONCATENATE(B12,\" (ref)\")", sheet.getRow(11).getCell(3).getCellFormula());
 
-        assertEquals("cell B3 (ref)", sheet.getRow(2).getCell((short)3).getRichStringCellValue().toString());
-        assertEquals("CONCATENATE(B3,\" (ref)\")", sheet.getRow(2).getCell((short)3).getCellFormula());
+        assertEquals("cell B3 (ref)", sheet.getRow(2).getCell(3).getRichStringCellValue().toString());
+        assertEquals("CONCATENATE(B3,\" (ref)\")", sheet.getRow(2).getCell(3).getCellFormula());
 
         // one on a non-shifted row also updated
-        assertEquals("cell B2 (ref)", sheet.getRow(6).getCell((short)1).getRichStringCellValue().toString());
-        assertEquals("CONCATENATE(B12,\" (ref)\")", sheet.getRow(6).getCell((short)1).getCellFormula());
+        assertEquals("cell B2 (ref)", sheet.getRow(6).getCell(1).getRichStringCellValue().toString());
+        assertEquals("CONCATENATE(B12,\" (ref)\")", sheet.getRow(6).getCell(1).getCellFormula());
     }
 }
 
index d67c3f4693425a9ebbd8574b4174cc9d5b1badcf..2a9215285781e676959834c5fd59358ed67587ed 100644 (file)
@@ -57,14 +57,14 @@ public class TestUnicodeWorkbook extends TestCase {
         f.setRight("\u20ac");                
 
         HSSFRow r = s.createRow(0);
-        HSSFCell c = r.createCell((short)1);
+        HSSFCell c = r.createCell(1);
         c.setCellValue(12.34);
         c.getCellStyle().setDataFormat(fmt);
         
-        HSSFCell c2 = r.createCell((short)2);
+        HSSFCell c2 = r.createCell(2);
         c.setCellValue(new HSSFRichTextString("\u20ac"));
 
-        HSSFCell c3 = r.createCell((short)3);
+        HSSFCell c3 = r.createCell(3);
         String formulaString = "TEXT(12.34,\"\u20ac###,##\")";
         c3.setCellFormula(formulaString);
 
@@ -95,16 +95,16 @@ public class TestUnicodeWorkbook extends TestCase {
 
         //Test the dataformat
         r = s.getRow(0);
-        c = r.getCell((short)1);
+        c = r.getCell(1);
         df = wb.createDataFormat();
         assertEquals(formatStr, df.getFormat(c.getCellStyle().getDataFormat()));
         
         //Test the cell string value
-        c2 = r.getCell((short)2);
+        c2 = r.getCell(2);
         assertEquals(c.getRichStringCellValue().getString(), "\u20ac");
         
         //Test the cell formula
-        c3 = r.getCell((short)3);
+        c3 = r.getCell(3);
         assertEquals(c3.getCellFormula(), formulaString);
     }
     
@@ -122,7 +122,7 @@ public class TestUnicodeWorkbook extends TestCase {
         HSSFSheet s = wb.createSheet("test");
         
         HSSFRow r = s.createRow(0);
-        HSSFCell c = r.createCell((short)1);
+        HSSFCell c = r.createCell(1);
         c.setCellValue(new HSSFRichTextString("\u00e4"));
         
         //Confirm that the sring will be compressed
@@ -140,7 +140,7 @@ public class TestUnicodeWorkbook extends TestCase {
         s = wb.getSheet("test");
         assertNotNull(s);
         
-        c = r.getCell((short)1);
+        c = r.getCell(1);
         assertEquals(c.getRichStringCellValue().getString(), "\u00e4");
     }    
 
index c0231cdfea61c24074fce60e2b33fad095ff8d8e..c6fa2ee0d9faf27c35d648079698526a99416034 100644 (file)
@@ -96,7 +96,7 @@ public final class TestWorkbook extends TestCase {
                 c.setCellValue(rownum * 10000 + cellnum
                                + ((( double ) rownum / 1000)
                                   + (( double ) cellnum / 10000)));
-                c = r.createCell(( short ) (cellnum + 1));
+                c = r.createCell(cellnum + 1);
                 c.setCellValue(new HSSFRichTextString("TEST"));
             }
         }
@@ -142,7 +142,7 @@ public final class TestWorkbook extends TestCase {
                 c.setCellValue(rownum * 10000 + cellnum
                                + ((( double ) rownum / 1000)
                                   + (( double ) cellnum / 10000)));
-                c = r.createCell(( short ) (cellnum + 1));
+                c = r.createCell(cellnum + 1);
                 c.setCellValue(new HSSFRichTextString("TEST"));
             }
         }
@@ -226,8 +226,8 @@ public final class TestWorkbook extends TestCase {
     short df = format.getFormat("0.0");
     cs.setDataFormat(df);
 
-    r = s.createRow((short)0);
-    c = r.createCell((short)0);
+    r = s.createRow(0);
+    c = r.createCell(0);
     c.setCellStyle(cs);
     c.setCellValue(1.25);
 
@@ -239,7 +239,7 @@ public final class TestWorkbook extends TestCase {
         HSSFWorkbook    workbook = new HSSFWorkbook(fs);
         HSSFSheet       sheet    = workbook.getSheetAt(0);
     HSSFCell    cell     =
-                     sheet.getRow(( short ) 0).getCell(( short ) 0);
+                     sheet.getRow(0).getCell(0);
     format = workbook.createDataFormat();
 
         assertEquals(1.25,cell.getNumericCellValue(), 1e-10);
@@ -350,7 +350,7 @@ public final class TestWorkbook extends TestCase {
 
         for (int k = 0; k < 4; k++)
         {
-            HSSFCell cell = sheet.getRow(( short ) k).getCell(( short ) 0);
+            HSSFCell cell = sheet.getRow(k).getCell(0);
 
             cell.setCellValue(new HSSFRichTextString(REPLACED));
         }
@@ -360,7 +360,7 @@ public final class TestWorkbook extends TestCase {
         sheet    = workbook.getSheetAt(0);
         for (int k = 0; k < 4; k++)
         {
-            HSSFCell cell = sheet.getRow(( short ) k).getCell(( short ) 0);
+            HSSFCell cell = sheet.getRow(k).getCell(0);
 
             assertEquals(REPLACED, cell.getRichStringCellValue().getString());
         }
@@ -439,7 +439,7 @@ public final class TestWorkbook extends TestCase {
                 c.setCellValue(rownum * 10000 + cellnum
                                + ((( double ) rownum / 1000)
                                   + (( double ) cellnum / 10000)));
-                c = r.createCell(( short ) (cellnum + 1));
+                c = r.createCell(cellnum + 1);
                 c.setCellValue(new HSSFRichTextString("TEST"));
             }
         }
@@ -530,7 +530,7 @@ public final class TestWorkbook extends TestCase {
         for ( i = 0, j = 32771; j > 0; i++, j-- )
         {
             row = sheet.createRow(i);
-            cell = row.createCell((short) 0);
+            cell = row.createCell(0);
             cell.setCellValue(i);
         }
         sanityChecker.checkHSSFWorkbook(workbook);
@@ -556,7 +556,7 @@ public final class TestWorkbook extends TestCase {
 
         HSSFRow row = sheet.createRow(0);
 
-        HSSFCell cell = row.createCell((short)1);
+        HSSFCell cell = row.createCell(1);
         cell.setCellValue(new HSSFRichTextString("hi"));