dmui        2003/03/07 13:52:37

  Modified:    src/documentation/xdocs/hssf quick-guide.xml
               src/java/org/apache/poi/hssf/model Workbook.java
               src/java/org/apache/poi/hssf/usermodel HSSFWorkbook.java
               src/testcases/org/apache/poi/hssf/usermodel
                        TestNamedRange.java
  Log:
  Added remove and another PrintArea setting method and documentation update
  
  Revision  Changes    Path
  1.16      +6 -3      jakarta-poi/src/documentation/xdocs/hssf/quick-guide.xml
  
  Index: quick-guide.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/documentation/xdocs/hssf/quick-guide.xml,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- quick-guide.xml   6 Mar 2003 21:04:47 -0000       1.15
  +++ quick-guide.xml   7 Mar 2003 21:52:36 -0000       1.16
  @@ -445,15 +445,18 @@
                       <source>
       HSSFWorkbook wb = new HSSFWorkbook();
       HSSFSheet sheet = wb.createSheet("Sheet1");
  -    wb.setPrintArea(0, "Sheet1!$A$1:$C$2");
  +    wb.setPrintArea(0, "$A$1:$C$2");
       //sets the print area for the first sheet
  -    
  +    //Alternatively:
  +    //wb.setPrintArea(0, 0, 1, 0, 0) is equivalent to using the name reference (See 
the JavaDocs for more details)  
   
       // Create various cells and rows for spreadsheet.
   
       FileOutputStream fileOut = new FileOutputStream("workbook.xls");
       wb.write(fileOut);
       fileOut.close();
  +    
  +    
                       </source>
                   </section>
   
  @@ -479,7 +482,7 @@
                   <anchor id="Convenience Functions"/>
                   <section title="Using the Convenience Functions">
                       <p>
  -                        The convience functions live in contrib and provide
  +                        The convenience functions live in contrib and provide
                           utility features such as setting borders around merged
                           regions and changing style attributes without explicitly
                           creating new styles.
  
  
  
  1.28      +16 -1     jakarta-poi/src/java/org/apache/poi/hssf/model/Workbook.java
  
  Index: Workbook.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/model/Workbook.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- Workbook.java     6 Mar 2003 20:41:16 -0000       1.27
  +++ Workbook.java     7 Mar 2003 21:52:37 -0000       1.28
  @@ -339,7 +339,7 @@
        /**Retrieves the Builtin NameRecord that matches the name and index
         * There shouldn't be too many names to make the sequential search too slow
         * @param name byte representation of the builtin name to match
  -      * @param sheetIndex zero-based sheet reference
  +      * @param sheetIndex Index to match
         * @return null if no builtin NameRecord matches
         */
        public NameRecord getSpecificBuiltinRecord(byte name, int sheetIndex)
  @@ -356,6 +356,21 @@
            
            return null;
            
  +     }
  +
  +     /**
  +      * Removes the specified Builtin NameRecord that matches the name and index
  +      * @param name byte representation of the builtin to match
  +      * @param sheetIndex zero-based sheet reference
  +      */
  +     public void removeBuiltinRecord(byte name, int sheetIndex) {
  +             //the name array is smaller so searching through it should be faster 
than
  +             //using the findFirstXXXX methods
  +             NameRecord record = getSpecificBuiltinRecord(name, sheetIndex);
  +             if (record != null) {
  +                     names.remove(record);
  +             }
  +             
        }
   
       public int getNumRecords() {
  
  
  
  1.22      +58 -20    
jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
  
  Index: HSSFWorkbook.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- HSSFWorkbook.java 6 Mar 2003 20:41:16 -0000       1.21
  +++ HSSFWorkbook.java 7 Mar 2003 21:52:37 -0000       1.22
  @@ -1,7 +1,7 @@
   /* ====================================================================
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2002, 2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -59,30 +59,38 @@
    */
   package org.apache.poi.hssf.usermodel;
   
  -import org.apache.poi.util.POILogFactory;
  +import java.io.ByteArrayInputStream;
  +import java.io.IOException;
  +import java.io.InputStream;
  +import java.io.OutputStream;
  +import java.util.ArrayList;
  +import java.util.Iterator;
  +import java.util.List;
  +import java.util.Stack;
  +
   import org.apache.poi.hssf.eventmodel.EventRecordFactory;
   import org.apache.poi.hssf.model.Sheet;
   import org.apache.poi.hssf.model.Workbook;
  -import org.apache.poi.hssf.record.*;
  -import org.apache.poi.hssf.record.formula.MemFuncPtg;
  +import org.apache.poi.hssf.record.BackupRecord;
  +import org.apache.poi.hssf.record.ExtendedFormatRecord;
  +import org.apache.poi.hssf.record.FontRecord;
  +import org.apache.poi.hssf.record.NameRecord;
  +import org.apache.poi.hssf.record.RecordFactory;
  +import org.apache.poi.hssf.record.SSTRecord;
  +import org.apache.poi.hssf.record.UnknownRecord;
  +import org.apache.poi.hssf.record.WindowTwoRecord;
   import org.apache.poi.hssf.record.formula.Area3DPtg;
  +import org.apache.poi.hssf.record.formula.MemFuncPtg;
   import org.apache.poi.hssf.record.formula.UnionPtg;
  -import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  -import org.apache.poi.poifs.filesystem.Entry;
  +import org.apache.poi.hssf.util.CellReference;
   import org.apache.poi.poifs.filesystem.DirectoryEntry;
   import org.apache.poi.poifs.filesystem.DocumentEntry;
   import org.apache.poi.poifs.filesystem.DocumentInputStream;
  +import org.apache.poi.poifs.filesystem.Entry;
  +import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  +import org.apache.poi.util.POILogFactory;
   import org.apache.poi.util.POILogger;
   
  -import java.io.ByteArrayInputStream;
  -import java.io.IOException;
  -import java.io.InputStream;
  -import java.io.OutputStream;
  -import java.util.ArrayList;
  -import java.util.List;
  -import java.util.Iterator;
  -import java.util.Stack;
  -
   /**
    * High level representation of a workbook.  This is the first object most users
    * will construct whether they are reading or writing a workbook.  It is also the
  @@ -816,7 +824,7 @@
        /**
         * Sets the printarea for the sheet provided
         * <p>
  -      * i.e. Reference = Sheet2!$A$1:$B$2
  +      * i.e. Reference = $A$1:$B$2
         * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to 
keep consistent with java)
         * @param reference Valid name Reference for the Print Area 
         */
  @@ -829,15 +837,38 @@
                        name = 
workbook.createBuiltInName(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
          //adding one here because 0 indicates a global named region; doesnt make 
sense for print areas
          
  -       HSSFName nameWrapper = new HSSFName(workbook, name);
  -       //the external name does some housekeeping, refactor to lower level?
  +         short externSheetIndex = getWorkbook().checkExternSheet(sheetIndex);
  +             name.setExternSheetNumber(externSheetIndex);       
  +             name.setAreaReference(reference);
          
  -             nameWrapper.setReference(reference);
  +             
        }
        
  +     /**
  +      * For the Convenience of Java Programmers maintaining pointers.
  +      * @see setPrintArea(int, String)
  +      * @param sheetIndex Zero-based sheet index (0 = First Sheet)
  +      * @param startColumn Column to begin printarea
  +      * @param endColumn Column to end the printarea
  +      * @param startRow Row to begin the printarea
  +      * @param endRow Row to end the printarea
  +      */
  +     public void setPrintArea(int sheetIndex, int startColumn, int endColumn,
  +                                                       int startRow, int endRow) {
  +                                                             
  +             //using absolute references because they dont get copied and pasted 
anyway                                                              
  +             CellReference cell = new CellReference(startRow, startColumn, true, 
true);
  +             String reference = cell.toString();
  +             
  +             cell = new CellReference(endRow, endColumn, true, true);
  +             reference = reference+":"+cell.toString();
  +             
  +             setPrintArea(sheetIndex, reference);                                   
                         
  +     }
  +                                                       
            
        /**
  -      * Retrieves the reference for the printarea of the specified sheet
  +      * Retrieves the reference for the printarea of the specified sheet, the sheet 
name is appended to the reference even if it was not specified.
         * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to 
keep consistent with java) 
         * @return String Null if no print area has been defined
         */         
  @@ -850,6 +881,13 @@
                return name.getAreaReference(workbook.getSheetReferences());
        }    
       
  +    /**
  +     * Delete the printarea for the sheet specified
  +     * @param sheetIndex Zero-based sheet index (0 = First Sheet)
  +     */
  +    public void removePrintArea(int sheetIndex) {
  +     getWorkbook().removeBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, 
sheetIndex+1); 
  +    }
       
       /** creates a new named range and add it to the model
        * @return named range high level
  
  
  
  1.6       +58 -0     
jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java
  
  Index: TestNamedRange.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestNamedRange.java       6 Mar 2003 20:41:17 -0000       1.5
  +++ TestNamedRange.java       7 Mar 2003 21:52:37 -0000       1.6
  @@ -370,6 +370,26 @@
         }
   
         /**
  +       * For Convenience, dont force sheet names to be used
  +       */
  +      public void testSinglePrintAreaWOSheet()
  +      {
  +              HSSFWorkbook workbook = new HSSFWorkbook();        
  +              HSSFSheet sheet = workbook.createSheet("Test Print Area");            
    
  +              String sheetName = workbook.getSheetName(0);
  +          
  +              String reference = "$A$1:$B$1";
  +              workbook.setPrintArea(0, reference);
  +                  
  +              String retrievedPrintArea = workbook.getPrintArea(0);
  +         
  +              assertNotNull("Print Area not defined for first sheet", 
retrievedPrintArea);        
  +              assertEquals(sheetName+"!"+reference, retrievedPrintArea);
  +          
  +      }
  +
  +
  +      /**
          * Test to see if the print area can be retrieved from an excel created file
          */
         public void testPrintAreaFileRead()
  @@ -486,6 +506,44 @@
            
            
        }
  +    
  +    /**
  +     * Tests the setting of print areas with coordinates (Row/Column designations)
  +     *
  +     */
  +    public void testPrintAreaCoords(){
  +             HSSFWorkbook workbook = new HSSFWorkbook();        
  +             HSSFSheet sheet = workbook.createSheet("Test Print Area");             
   
  +             String sheetName = workbook.getSheetName(0);
  +          
  +             String reference = sheetName+"!$A$1:$B$1";
  +             workbook.setPrintArea(0, 0, 1, 0, 0);
  +                  
  +             String retrievedPrintArea = workbook.getPrintArea(0);
  +         
  +             assertNotNull("Print Area not defined for first sheet", 
retrievedPrintArea);        
  +             assertEquals(reference, retrievedPrintArea);            
  +    }
  +     
  +    /**
  +     * Verifies an existing print area is deleted
  +     *
  +     */
  +    public void testPrintAreaRemove() {
  +             HSSFWorkbook workbook = new HSSFWorkbook();        
  +             HSSFSheet sheet = workbook.createSheet("Test Print Area");             
   
  +             String sheetName = workbook.getSheetName(0);
  +          
  +             String reference = sheetName+"!$A$1:$B$1";
  +             workbook.setPrintArea(0, 0, 1, 0, 0);
  +                  
  +             String retrievedPrintArea = workbook.getPrintArea(0);
  +         
  +             assertNotNull("Print Area not defined for first sheet", 
retrievedPrintArea);        
  +     
  +     workbook.removePrintArea(0);
  +     assertNull("PrintArea was not removed", workbook.getPrintArea(0)); 
  +    }
           
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to