poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r695549 - in /poi/branches/ooxml: ./ src/documentation/content/xdocs/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/ src/java/org/apache/poi/hssf/record/formula/ src/java/org/apache/poi/hssf/record/formula/function...
Date Mon, 15 Sep 2008 17:01:49 GMT
Author: nick
Date: Mon Sep 15 10:01:46 2008
New Revision: 695549

URL: http://svn.apache.org/viewvc?rev=695549&view=rev
Log:
Merged revisions 695264,695303,695420 via svnmerge from 
https://svn.apache.org:443/repos/asf/poi/trunk

........
  r695264 | josh | 2008-09-14 19:55:28 +0100 (Sun, 14 Sep 2008) | 1 line
  
  Fix for bug 45978 - removed eager initialisation of SheetReferences
........
  r695303 | nick | 2008-09-14 23:19:06 +0100 (Sun, 14 Sep 2008) | 1 line
  
  Make a start on exposing the StyleRecord details into HSSFCellStyle, but not fully there
yet
........
  r695420 | nick | 2008-09-15 12:02:18 +0100 (Mon, 15 Sep 2008) | 1 line
  
  Finish exposing the name of Named Cell Styles via HSSFCellStyle (normally held on the parent
style though)
........

Added:
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/data/WithExtendedStyles.xls
      - copied unchanged from r695420, poi/trunk/src/testcases/org/apache/poi/hssf/data/WithExtendedStyles.xls
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/data/ex45978-extraLinkTableSheets.xls
      - copied unchanged from r695420, poi/trunk/src/testcases/org/apache/poi/hssf/data/ex45978-extraLinkTableSheets.xls
Removed:
    poi/branches/ooxml/src/java/org/apache/poi/hssf/util/SheetReferences.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/util/TestSheetReferences.java
Modified:
    poi/branches/ooxml/   (props changed)
    poi/branches/ooxml/src/documentation/content/xdocs/changes.xml
    poi/branches/ooxml/src/documentation/content/xdocs/status.xml
    poi/branches/ooxml/src/java/org/apache/poi/hssf/model/LinkTable.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Workbook.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/StyleRecord.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/functions/DateFunc.java
  (props changed)
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/LazyAreaEval.java   (props changed)
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/LazyRefEval.java   (props changed)
    poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Workbook.java
    poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/HSSFTests.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestLinkTable.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java

Propchange: poi/branches/ooxml/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Sep 15 10:01:46 2008
@@ -1 +1 @@
-/poi/trunk:693591-694881
+/poi/trunk:693591-694881,695264-695420

Propchange: poi/branches/ooxml/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Sep 15 10:01:46 2008
@@ -1 +1 @@
-/poi/trunk:1-638784,638786-639486,639488-639601,639603-640056,640058-642562,642564-642566,642568-642574,642576-642736,642739-650914,650916-694946
+/poi/trunk:1-638784,638786-639486,639488-639601,639603-640056,640058-642562,642564-642566,642568-642574,642576-642736,642739-650914,650916-695536

Modified: poi/branches/ooxml/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/documentation/content/xdocs/changes.xml?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/documentation/content/xdocs/changes.xml (original)
+++ poi/branches/ooxml/src/documentation/content/xdocs/changes.xml Mon Sep 15 10:01:46 2008
@@ -66,6 +66,8 @@
            <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="add">Expose the name of Named Cell Styles
via HSSFCellStyle (normally held on the parent style though)</action>
+           <action dev="POI-DEVELOPERS" type="fix">45978 - Fixed IOOBE in Ref3DPtg.toFormulaString()
due eager initialisation of SheetReferences</action>
            <action dev="POI-DEVELOPERS" type="add">Made HSSFFormulaEvaluator no longer
require initialisation with sheet or row</action>
            <action dev="POI-DEVELOPERS" type="add">Extended support for cached results
of formula cells</action>
            <action dev="POI-DEVELOPERS" type="fix">45639 - Fixed AIOOBE due to bad
index logic in ColumnInfoRecordsAggregate</action>

Modified: poi/branches/ooxml/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/documentation/content/xdocs/status.xml?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/documentation/content/xdocs/status.xml (original)
+++ poi/branches/ooxml/src/documentation/content/xdocs/status.xml Mon Sep 15 10:01:46 2008
@@ -63,6 +63,8 @@
            <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="add">Expose the name of Named Cell Styles
via HSSFCellStyle (normally held on the parent style though)</action>
+           <action dev="POI-DEVELOPERS" type="fix">45978 - Fixed IOOBE in Ref3DPtg.toFormulaString()
due eager initialisation of SheetReferences</action>
            <action dev="POI-DEVELOPERS" type="add">Made HSSFFormulaEvaluator no longer
require initialisation with sheet or row</action>
            <action dev="POI-DEVELOPERS" type="add">Extended support for cached results
of formula cells</action>
            <action dev="POI-DEVELOPERS" type="fix">45639 - Fixed AIOOBE due to bad
index logic in ColumnInfoRecordsAggregate</action>

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/model/LinkTable.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/model/LinkTable.java?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/model/LinkTable.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/model/LinkTable.java Mon Sep 15 10:01:46
2008
@@ -348,10 +348,6 @@
 		return -1;
 	}
 
-	public int getNumberOfREFStructures() {
-		return _externSheetRecord.getNumOfRefs();
-	}
-
 	public String resolveNameXText(int refIndex, int definedNameIndex) {
 		int extBookIndex = _externSheetRecord.getExtbookIndexFromRefIndex(refIndex);
 		return _externalBookBlocks[extBookIndex].getNameText(definedNameIndex);

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Workbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Workbook.java?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Workbook.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Workbook.java Mon Sep 15 10:01:46
2008
@@ -26,7 +26,6 @@
 import org.apache.poi.hssf.record.*;
 import org.apache.poi.hssf.record.formula.NameXPtg;
 import org.apache.poi.hssf.util.HSSFColor;
-import org.apache.poi.hssf.util.SheetReferences;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 
@@ -774,6 +773,61 @@
         numxfs++;
         return xf;
     }
+    
+    /**
+     * Returns the StyleRecord for the given
+     *  xfIndex, or null if that ExtendedFormat doesn't
+     *  have a Style set.
+     */
+    public StyleRecord getStyleRecord(int xfIndex) {
+    	// Style records always follow after 
+    	//  the ExtendedFormat records
+    	boolean done = false;
+    	for(int i=records.getXfpos(); i<records.size() &&
+    			!done; i++) {
+    		Record r = records.get(i);
+    		if(r instanceof ExtendedFormatRecord) {
+    		} else if(r instanceof StyleRecord) {
+    			StyleRecord sr = (StyleRecord)r;
+    			if(sr.getIndex() == xfIndex) {
+    				return sr;
+    			}
+    		} else {
+    			done = true;
+    		}
+    	}
+    	return null;
+    }
+    /**
+     * Creates a new StyleRecord, for the given Extended
+     *  Format index, and adds it onto the end of the
+     *  records collection
+     */
+    public StyleRecord createStyleRecord(int xfIndex) {
+    	// Style records always follow after 
+    	//  the ExtendedFormat records
+    	StyleRecord newSR = new StyleRecord();
+    	newSR.setIndex((short)xfIndex);
+    	
+    	// Find the spot
+    	int addAt = -1;
+    	for(int i=records.getXfpos(); i<records.size() &&
+    			addAt == -1; i++) {
+    		Record r = records.get(i);
+    		if(r instanceof ExtendedFormatRecord ||
+    				r instanceof StyleRecord) {
+    			// Keep going
+    		} else {
+    			addAt = i;
+    		}
+    	}
+    	if(addAt == -1) {
+    		throw new IllegalStateException("No XF Records found!");
+    	}
+    	records.add(addAt, newSR);
+    	
+    	return newSR;
+    }
 
     /**
      * Adds a string to the SST table and returns its index (if its a duplicate
@@ -1902,34 +1956,23 @@
         return linkTable;
     }
 
-    public SheetReferences getSheetReferences() {
-        SheetReferences refs = new SheetReferences();
-        
-        if (linkTable != null) {
-            int numRefStructures = linkTable.getNumberOfREFStructures();
-            for (short k = 0; k < numRefStructures; k++) {
-                
-                String sheetName = findSheetNameFromExternSheet(k);
-                refs.addSheetReference(sheetName, k);
-                
-            }
-        }
-        return refs;
-    }
-
     /** finds the sheet name by his extern sheet index
-     * @param num extern sheet index
-     * @return sheet name
+     * @param externSheetIndex extern sheet index
+     * @return sheet name.
      */
-    public String findSheetNameFromExternSheet(short num){
+    public String findSheetNameFromExternSheet(int externSheetIndex){
 
-        int indexToSheet = linkTable.getIndexToSheet(num);
+        int indexToSheet = linkTable.getIndexToSheet(externSheetIndex);
         
         if (indexToSheet < 0) {
             // TODO - what does '-1' mean here?
             //error check, bail out gracefully!
             return "";
         }
+        if (indexToSheet >= boundsheets.size()) {
+            // Not sure if this can ever happen (See bug 45798)
+            return ""; // Seems to be what excel would do in this case
+        }
         return getSheetName(indexToSheet);
     }
 

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/StyleRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/StyleRecord.java?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/StyleRecord.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/StyleRecord.java Mon Sep 15 10:01:46
2008
@@ -160,7 +160,10 @@
     public void setName(String name)
     {
         field_4_name = name;
-        //TODO set name length and string options
+        
+        // Fix up the length
+        field_2_name_length = (short)name.length();
+        //TODO set name string options
     }
 
     // end user defined

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java Mon Sep
15 10:01:46 2008
@@ -92,7 +92,7 @@
 	public String toFormulaString(Workbook book) {
 		// First do the sheet name
 		StringBuffer retval = new StringBuffer();
-		String sheetName = Ref3DPtg.getSheetName(book, field_1_index_extern_sheet);
+		String sheetName = book.findSheetNameFromExternSheet(field_1_index_extern_sheet);
 		if(sheetName != null) {
 			if(sheetName.length() == 0) {
 				// What excel does if sheet has been deleted

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java Mon Sep 15
10:01:46 2008
@@ -160,20 +160,6 @@
 
     }
 
-    // TODO - find a home for this method
-    // There is already a method on Workbook called getSheetName but it seems to do something
different.
-	static String getSheetName(Workbook book, int externSheetIndex) {
-        // TODO - there are 3 ways this method can return null. Is each valid?
-        if (book == null) {
-            return null;
-        }
-
-        SheetReferences refs = book.getSheetReferences();
-        if (refs == null) {
-            return null;
-        }
-        return refs.getSheetName(externSheetIndex);
-    }
     /**
      * @return text representation of this cell reference that can be used in text 
      * formulas. The sheet name will get properly delimited if required.
@@ -181,7 +167,7 @@
     public String toFormulaString(Workbook book)
     {
         StringBuffer retval = new StringBuffer();
-        String sheetName = getSheetName(book, field_1_index_extern_sheet);
+        String sheetName = book.findSheetNameFromExternSheet(field_1_index_extern_sheet);
         if(sheetName != null) {
             SheetNameFormatter.appendFormat(retval, sheetName);
             retval.append( '!' );

Propchange: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/functions/DateFunc.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Sep 15 10:01:46 2008
@@ -0,0 +1 @@
+/poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/DateFunc.java:695264-695420

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java Mon Sep 15
10:01:46 2008
@@ -21,6 +21,7 @@
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.ExtendedFormatRecord;
 import org.apache.poi.hssf.record.FontRecord;
+import org.apache.poi.hssf.record.StyleRecord;
 import org.apache.poi.hssf.util.HSSFColor;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Font;
@@ -255,6 +256,22 @@
     {
         return index;
     }
+    
+    /**
+     * Return the parent style for this cell style.
+     * In most cases this will be null, but in a few
+     *  cases there'll be a fully defined parent.
+     */
+    public HSSFCellStyle getParentStyle() {
+    	if(format.getParentIndex() == 0) {
+    		return null;
+    	}
+    	return new HSSFCellStyle(
+    			format.getParentIndex(),
+    			workbook.getExFormatAt(format.getParentIndex()),
+    			workbook
+    	);
+    }
 
     /**
      * set the data format (must be a valid format)
@@ -943,6 +960,37 @@
     {
         return format.getFillForeground();
     }
+    
+    /**
+     * Gets the name of the user defined style.
+     * Returns null for built in styles, and
+     *  styles where no name has been defined
+     */
+    public String getUserStyleName() {
+    	StyleRecord sr = workbook.getStyleRecord(index);
+    	if(sr == null) {
+    		return null;
+    	}
+    	if(sr.getType() == StyleRecord.STYLE_BUILT_IN) {
+    		return null;
+    	}
+    	return sr.getName();
+    }
+    
+    /**
+     * Sets the name of the user defined style.
+     * Will complain if you try this on a built in style.
+     */
+    public void setUserStyleName(String styleName) {
+    	StyleRecord sr = workbook.getStyleRecord(index);
+    	if(sr == null) {
+    		sr = workbook.createStyleRecord(index);
+    	}
+    	if(sr.getType() == StyleRecord.STYLE_BUILT_IN) {
+    		throw new IllegalArgumentException("Unable to set user specified style names for built
in styles!");
+    	}
+    	sr.setName(styleName);
+    }
 
     /**
      * Verifies that this style belongs to the supplied Workbook.

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Mon Sep 15
10:01:46 2008
@@ -35,7 +35,6 @@
 import org.apache.poi.ddf.EscherRecord;
 import org.apache.poi.hssf.model.Sheet;
 import org.apache.poi.hssf.model.Workbook;
-import org.apache.poi.hssf.model.DrawingManager2;
 import org.apache.poi.hssf.record.AbstractEscherHolderRecord;
 import org.apache.poi.hssf.record.BackupRecord;
 import org.apache.poi.hssf.record.DrawingGroupRecord;
@@ -59,7 +58,6 @@
 import org.apache.poi.hssf.record.formula.Ref3DPtg;
 import org.apache.poi.hssf.record.formula.UnionPtg;
 import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.util.SheetReferences;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.ss.usermodel.CreationHelper;
@@ -864,8 +862,13 @@
         return retval;
     }
 
-    public SheetReferences getSheetReferences() {
-        return workbook.getSheetReferences();
+    /**
+     * @deprecated for POI internal use only (formula rendering).  This method is likely
to
+     * be removed in future versions of POI.
+     */
+    public String findSheetNameFromExternSheet(int externSheetIndex){
+        // TODO - don't expose internal ugliness like externSheet indexes to the user model
API
+        return workbook.findSheetNameFromExternSheet(externSheetIndex);
     }
 
     /**
@@ -1379,12 +1382,15 @@
     }
 
     /**
-     * TODO - make this less cryptic / move elsewhere
+     * @deprecated for POI internal use only (formula rendering).  This method is likely
to
+     * be removed in future versions of POI.
+     * 
      * @param refIndex Index to REF entry in EXTERNSHEET record in the Link Table
      * @param definedNameIndex zero-based to DEFINEDNAME or EXTERNALNAME record
      * @return the string representation of the defined or external name
      */
     public String resolveNameXText(int refIndex, int definedNameIndex) {
+        // TODO - make this less cryptic / move elsewhere
         return workbook.resolveNameXText(refIndex, definedNameIndex);
     }
 

Propchange: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/LazyAreaEval.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Sep 15 10:01:46 2008
@@ -0,0 +1 @@
+/poi/trunk/src/java/org/apache/poi/hssf/usermodel/LazyAreaEval.java:695264-695420

Propchange: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/LazyRefEval.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Sep 15 10:01:46 2008
@@ -0,0 +1 @@
+/poi/trunk/src/java/org/apache/poi/hssf/usermodel/LazyRefEval.java:695264-695420

Modified: poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Workbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Workbook.java?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Workbook.java
(original)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Workbook.java
Mon Sep 15 10:01:46 2008
@@ -19,7 +19,6 @@
 
 import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
 import org.apache.poi.hssf.usermodel.*;
-import org.apache.poi.hssf.util.SheetReferences;
 
 /**
  * This is a JDK 1.4 compatible interface for HSSFWorkbook.
@@ -39,7 +38,7 @@
 
     String getSheetName(int sheet);
     HSSFSheet getSheetAt(int index);
-    SheetReferences getSheetReferences();
+    String findSheetNameFromExternSheet(int externSheetIndex);
     int getSheetIndex(String name);
     int getSheetIndex(Sheet sheet);
     int getSheetIndexFromExternSheetIndex(int externSheetNumber);

Modified: poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
(original)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
Mon Sep 15 10:01:46 2008
@@ -22,7 +22,6 @@
 import java.util.List;
 
 import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
-import org.apache.poi.ss.util.SheetReferences;
 
 public interface Workbook {
 
@@ -218,7 +217,7 @@
 
     void removeSheetAt(int index);
 
-    SheetReferences getSheetReferences();
+    String findSheetNameFromExternSheet(int externSheetIndex);
     
     /**
      * determine whether the Excel GUI will backup the workbook when saving.

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Mon
Sep 15 10:01:46 2008
@@ -39,7 +39,6 @@
 import org.apache.poi.ss.usermodel.StylesSource;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
-import org.apache.poi.ss.util.SheetReferences;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 import org.apache.poi.xssf.model.CommentsTable;
@@ -463,6 +462,14 @@
     public int getSheetIndexFromExternSheetIndex(int externSheetNumber) {
 		return externSheetNumber;
 	}
+    /**
+     * Doesn't do anything special - returns the same as getSheetName()
+     * TODO - figure out if this is a ole2 specific thing, or
+     *  if we need to do something proper here too!
+     */
+    public String findSheetNameFromExternSheet(int externSheetIndex) {
+		return getSheetName(externSheetIndex);
+	}
 
 	public Sheet getSheet(String name) {
         CTSheet[] sheets = this.workbook.getSheets().getSheetArray();  
@@ -509,14 +516,6 @@
         return this.workbook.getSheets().getSheetArray(sheet).getName();
     }
     
-    public SheetReferences getSheetReferences() {
-    	SheetReferences sr = new SheetReferences();
-    	for(int i=0; i<getNumberOfSheets(); i++) {
-    		sr.addSheetReference(getSheetName(i), i);
-    	}
-    	return sr;
-	}
-    
     /**
      * Are we a normal workbook (.xlsx), or a 
      *  macro enabled workbook (.xlsm)?

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/HSSFTests.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/HSSFTests.java?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/HSSFTests.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/HSSFTests.java Mon Sep 15 10:01:46
2008
@@ -23,14 +23,11 @@
 import org.apache.poi.hssf.eventmodel.TestEventRecordFactory;
 import org.apache.poi.hssf.eventmodel.TestModelFactory;
 import org.apache.poi.hssf.eventusermodel.AllEventUserModelTests;
+import org.apache.poi.hssf.extractor.TestExcelExtractor;
 import org.apache.poi.hssf.model.AllModelTests;
 import org.apache.poi.hssf.record.AllRecordTests;
 import org.apache.poi.hssf.usermodel.AllUserModelTests;
-import org.apache.poi.hssf.util.TestAreaReference;
-import org.apache.poi.hssf.util.TestCellReference;
-import org.apache.poi.hssf.util.TestRKUtil;
-import org.apache.poi.hssf.util.TestRangeAddress;
-import org.apache.poi.hssf.util.TestSheetReferences;
+import org.apache.poi.hssf.util.AllHSSFUtilTests;
 
 /**
  * Test Suite for all sub-packages of org.apache.poi.hssf<br/>
@@ -41,27 +38,20 @@
  */
 public final class HSSFTests {
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(suite());
-    }
-
     public static Test suite() {
-        TestSuite suite = new TestSuite("Tests for org.apache.poi.hssf");
-        // $JUnit-BEGIN$
+        TestSuite suite = new TestSuite(HSSFTests.class.getName());
 
         suite.addTest(AllEventUserModelTests.suite());
         suite.addTest(AllModelTests.suite());
         suite.addTest(AllUserModelTests.suite());
         suite.addTest(AllRecordTests.suite());
+        suite.addTest(AllHSSFUtilTests.suite());
 
-        suite.addTest(new TestSuite(TestAreaReference.class));
-        suite.addTest(new TestSuite(TestCellReference.class));
-        suite.addTest(new TestSuite(TestRangeAddress.class));
-        suite.addTest(new TestSuite(TestRKUtil.class));
-        suite.addTest(new TestSuite(TestSheetReferences.class));
+        if (false) { // TODO - hook this test up
+            suite.addTest(new TestSuite(TestExcelExtractor.class));
+        }
         suite.addTest(new TestSuite(TestEventRecordFactory.class));
         suite.addTest(new TestSuite(TestModelFactory.class));
-        // $JUnit-END$
         return suite;
     }
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java
Mon Sep 15 10:01:46 2008
@@ -16,6 +16,7 @@
 ==================================================================== */
 
 package org.apache.poi.hssf.eventusermodel;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -32,7 +33,6 @@
 import org.apache.poi.hssf.record.formula.Ptg;
 import org.apache.poi.hssf.record.formula.Ref3DPtg;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.util.SheetReferences;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 /**
  * Tests for {@link EventWorkbookBuilder}
@@ -66,9 +66,6 @@
 	public void testGetStubWorkbooks() {
 		assertNotNull(listener.getStubWorkbook());
 		assertNotNull(listener.getStubHSSFWorkbook());
-		
-		assertNotNull(listener.getStubWorkbook().getSheetReferences());
-		assertNotNull(listener.getStubHSSFWorkbook().getSheetReferences());
 	}
 	
 	public void testContents() {
@@ -78,10 +75,10 @@
 		
 		assertEquals(3, listener.getStubWorkbook().getNumSheets());
 		
-		SheetReferences ref = listener.getStubWorkbook().getSheetReferences();
-		assertEquals("Sh3", ref.getSheetName(0));
-		assertEquals("Sheet1", ref.getSheetName(1));
-		assertEquals("S2", ref.getSheetName(2));
+		Workbook ref = listener.getStubWorkbook();
+		assertEquals("Sh3", ref.findSheetNameFromExternSheet(0));
+		assertEquals("Sheet1", ref.findSheetNameFromExternSheet(1));
+		assertEquals("S2", ref.findSheetNameFromExternSheet(2));
 	}
 	
 	public void testFormulas() {

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java Mon
Sep 15 10:01:46 2008
@@ -29,6 +29,8 @@
 import java.util.*;
 
 import junit.framework.*;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.util.TempFile;
 
 /**
@@ -41,6 +43,10 @@
     extends TestCase
 {
 
+    private static HSSFWorkbook openSample(String sampleFileName) {
+        return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
+    }
+
     /** Creates a new instance of TestCellStyle */
 
     public TestCellStyle(String name)
@@ -303,6 +309,54 @@
     	assertFalse(fmtClone.getFormat("Test##") == fmt.getFormat("Test##"));
     	assertEquals(5, wbClone.getNumberOfFonts());
     }
+    
+    public void testStyleNames() throws Exception {
+        HSSFWorkbook wb = openSample("WithExtendedStyles.xls");
+    	HSSFSheet s = wb.getSheetAt(0);
+    	HSSFCell c1 = s.getRow(0).getCell(0);
+    	HSSFCell c2 = s.getRow(1).getCell(0);
+    	HSSFCell c3 = s.getRow(2).getCell(0);
+    	
+    	HSSFCellStyle cs1 = c1.getCellStyle();
+    	HSSFCellStyle cs2 = c2.getCellStyle();
+    	HSSFCellStyle cs3 = c3.getCellStyle();
+    	
+    	assertNotNull(cs1);
+    	assertNotNull(cs2);
+    	assertNotNull(cs3);
+    	
+    	// Check we got the styles we'd expect
+    	assertEquals(10, cs1.getFont(wb).getFontHeightInPoints());
+    	assertEquals(9,  cs2.getFont(wb).getFontHeightInPoints());
+    	assertEquals(12, cs3.getFont(wb).getFontHeightInPoints());
+    	
+    	assertEquals(15, cs1.getIndex());
+    	assertEquals(23, cs2.getIndex());
+    	assertEquals(24, cs3.getIndex());
+    	
+    	assertNull(cs1.getParentStyle());
+    	assertNotNull(cs2.getParentStyle());
+    	assertNotNull(cs3.getParentStyle());
+    	
+    	assertEquals(21, cs2.getParentStyle().getIndex());
+    	assertEquals(22, cs3.getParentStyle().getIndex());
+    	
+    	// Now check we can get style records for 
+    	//  the parent ones
+    	assertNull(wb.getWorkbook().getStyleRecord(15));
+    	assertNull(wb.getWorkbook().getStyleRecord(23));
+    	assertNull(wb.getWorkbook().getStyleRecord(24));
+    	
+    	assertNotNull(wb.getWorkbook().getStyleRecord(21));
+    	assertNotNull(wb.getWorkbook().getStyleRecord(22));
+    	
+    	// Now check the style names
+    	assertEquals(null, cs1.getUserStyleName());
+    	assertEquals(null, cs2.getUserStyleName());
+    	assertEquals(null, cs3.getUserStyleName());
+    	assertEquals("style1", cs2.getParentStyle().getUserStyleName());
+    	assertEquals("style2", cs3.getParentStyle().getUserStyleName());
+    }
 
     public static void main(String [] ignored_args)
     {

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestLinkTable.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestLinkTable.java?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestLinkTable.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestLinkTable.java Mon
Sep 15 10:01:46 2008
@@ -6,7 +6,7 @@
 import org.apache.poi.hssf.HSSFTestDataSamples;
 /**
  * Tests for LinkTable
- * 
+ *
  * @author Josh Micich
  */
 public final class TestLinkTable extends TestCase {
@@ -14,9 +14,9 @@
 	/**
 	 * The example file attached to bugzilla 45046 is a clear example of Name records being
present
 	 * without an External Book (SupBook) record.  Excel has no trouble reading this file.<br/>
-	 * TODO get OOO documentation updated to reflect this (that EXTERNALBOOK is optional). 
-	 * 
-	 * It's not clear what exact steps need to be taken in Excel to create such a workbook 
+	 * TODO get OOO documentation updated to reflect this (that EXTERNALBOOK is optional).
+	 *
+	 * It's not clear what exact steps need to be taken in Excel to create such a workbook
 	 */
 	public void testLinkTableWithoutExternalBookRecord_bug45046() {
 		HSSFWorkbook wb;
@@ -32,16 +32,16 @@
 		// some other sanity checks
 		assertEquals(3, wb.getNumberOfSheets());
 		String formula = wb.getSheetAt(0).getRow(4).getCell(13).getCellFormula();
-		
+
 		if ("ipcSummenproduktIntern($P5,N$6,$A$9,N$5)".equals(formula)) {
-			// The reported symptom of this bugzilla is an earlier bug (already fixed) 
-			throw new AssertionFailedError("Identified bug 41726"); 
+			// The reported symptom of this bugzilla is an earlier bug (already fixed)
+			throw new AssertionFailedError("Identified bug 41726");
 			// This is observable in version 3.0
 		}
-		
+
 		assertEquals("ipcSummenproduktIntern($C5,N$2,$A$9,N$1)", formula);
 	}
-	
+
 	public void testMultipleExternSheetRecords_bug45698() {
 		HSSFWorkbook wb;
 
@@ -56,4 +56,45 @@
 		// some other sanity checks
 		assertEquals(7, wb.getNumberOfSheets());
 	}
+
+	public void testExtraSheetRefs_bug45978() {
+		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex45978-extraLinkTableSheets.xls");
+		/*
+		ex45978-extraLinkTableSheets.xls is a cut-down version of attachment 22561.
+		The original file produces the same error.
+
+		This bug was caused by a combination of invalid sheet indexes in the EXTERNSHEET
+		record, and eager initialisation of the extern sheet references. Note - the worbook
+		has 2 sheets, but the EXTERNSHEET record refers to sheet indexes 0, 1 and 2.
+
+		Offset 0x3954 (14676)
+		recordid = 0x17, size = 32
+		[EXTERNSHEET]
+		   numOfRefs	 = 5
+		refrec		 #0: extBook=0 firstSheet=0 lastSheet=0
+		refrec		 #1: extBook=1 firstSheet=2 lastSheet=2
+		refrec		 #2: extBook=2 firstSheet=1 lastSheet=1
+		refrec		 #3: extBook=0 firstSheet=-1 lastSheet=-1
+		refrec		 #4: extBook=0 firstSheet=1 lastSheet=1
+		[/EXTERNSHEET]
+
+		As it turns out, the formula in question doesn't even use externSheetIndex #1 - it
+		uses #4, which resolves to sheetIndex 1 -> 'Data'.
+
+		It is not clear exactly what externSheetIndex #4 would refer to.  Excel seems to
+		display such a formula as "''!$A2", but then complains of broken link errors.
+		*/
+
+		HSSFCell cell = wb.getSheetAt(0).getRow(1).getCell(1);
+		String cellFormula;
+		try {
+			cellFormula = cell.getCellFormula();
+		} catch (IndexOutOfBoundsException e) {
+			if (e.getMessage().equals("Index: 2, Size: 2")) {
+				throw new AssertionFailedError("Identified bug 45798");
+			}
+			throw e;
+		}
+		assertEquals("Data!$A2", cellFormula);
+	}
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java?rev=695549&r1=695548&r2=695549&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/util/AllHSSFUtilTests.java Mon Sep
15 10:01:46 2008
@@ -34,7 +34,6 @@
 		result.addTestSuite(TestHSSFColor.class);
 		result.addTestSuite(TestRangeAddress.class);
 		result.addTestSuite(TestRKUtil.class);
-		result.addTestSuite(TestSheetReferences.class);
 		return result;
 	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message