diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java b/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java index 568222b19..841d042da 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java @@ -19,6 +19,9 @@ package org.apache.poi.hssf.usermodel; import junit.framework.TestCase; + +import org.apache.poi.hssf.util.AreaReference; +import org.apache.poi.hssf.util.CellReference; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.TempFile; @@ -33,6 +36,7 @@ import java.io.IOException; * @author ROMANL * @author Andrew C. Oliver (acoliver at apache dot org) * @author Danny Mui (danny at muibros.com) + * @author Amol S. Deshmukh < amol at ap ache dot org > */ public class TestNamedRange extends TestCase { @@ -507,6 +511,78 @@ public class TestNamedRange workbook.removePrintArea(0); assertNull("PrintArea was not removed", workbook.getPrintArea(0)); } + + /** + * Verifies correct functioning for "single cell named range" (aka "named cell") + */ + public void testNamedCell_1() { + // setup for this testcase + String sheetName = "Test Named Cell"; + String cellName = "A name for a named cell"; + String cellValue = "TEST Value"; + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet sheet = wb.createSheet(sheetName); + sheet.createRow(0).createCell((short) 0).setCellValue(cellValue); + + // create named range for a single cell using areareference + HSSFName namedCell = wb.createName(); + namedCell.setNameName(cellName); + String reference = sheetName+"!A1:A1"; + namedCell.setReference(reference); + + // retrieve the newly created named range + int namedCellIdx = wb.getNameIndex(cellName); + HSSFName aNamedCell = wb.getNameAt(namedCellIdx); + assertNotNull(aNamedCell); + + // retrieve the cell at the named range and test its contents + AreaReference aref = new AreaReference(aNamedCell.getReference()); + CellReference[] crefs = aref.getCells(); + assertNotNull(crefs); + assertEquals("Should be exactly 1 cell in the named cell :'" +cellName+"'", 1, crefs.length); + for (int i=0, iSize=crefs.length; i