I hava created with Excel 2002 an empty workbook named input.xls I hava defined a named range A1:D10 and I gave it the name NamedRangeName After that I tried playing with that. The problem is that HSSFName.getReference returns characters of the range like ASCII-1, in my case @1:C10 instead of A1:D10 I tried to write then to a file output.xls and if i opened it with Excel, the named range was corect,so I suppose there is no internal problem, maybe just in getReference() method. I tested with the poi jar build 05.06.2002 Here is the source: import junit.framework.*; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.*; import org.apache.poi.hssf.usermodel.*; public class TestNR { public static void main(java.lang.String[] args) throws IOException { FileInputStream fis = null; POIFSFileSystem fs = null; HSSFWorkbook wb = null; fis = new FileInputStream("input.xls"); fs = new POIFSFileSystem(fis); wb = new HSSFWorkbook(fs); //Get index of the namedrange with the name = "NamedRangeName" , which was defined in input.xls as A1:D10 int NamedRangeIndex = wb.getNameIndex("NamedRangeName"); //Getting NAmed Range HSSFName namedRange1 = wb.getNameAt(NamedRangeIndex); //Getting its reference String reference = namedRange1.getReference(); //Display reference System.out.println("\nreference="+reference+"\n"); fis.close(); } }
Fixed in the nightly as of 03/06/2003