mirror of https://github.com/apache/poi.git
remove some deprecated Name methods from Workbook
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1879255 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f99533c56e
commit
38e58f1ead
File diff suppressed because it is too large
Load Diff
|
@ -365,16 +365,6 @@ public interface Workbook extends Closeable, Iterable<Sheet> {
|
|||
*/
|
||||
List<? extends Name> getAllNames();
|
||||
|
||||
/**
|
||||
* @param nameIndex position of the named range (0-based)
|
||||
* @return the defined name at the specified index
|
||||
* @throws IllegalArgumentException if the supplied index is invalid
|
||||
* @deprecated 4.0.0. New projects should avoid accessing named ranges by index.
|
||||
*/
|
||||
@Deprecated
|
||||
@Removal(version="5.0.0")
|
||||
Name getNameAt(int nameIndex);
|
||||
|
||||
/**
|
||||
* Creates a new (uninitialised) defined name in this workbook
|
||||
*
|
||||
|
@ -382,41 +372,6 @@ public interface Workbook extends Closeable, Iterable<Sheet> {
|
|||
*/
|
||||
Name createName();
|
||||
|
||||
/**
|
||||
* Gets the defined name index by name<br>
|
||||
* <i>Note:</i> Excel defined names are case-insensitive and
|
||||
* this method performs a case-insensitive search.
|
||||
*
|
||||
* @param name the name of the defined name
|
||||
* @return zero based index of the defined name. <tt>-1</tt> if not found.
|
||||
* @deprecated 3.18. New projects should avoid accessing named ranges by index.
|
||||
* Use {@link #getName(String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@Removal(version="3.20")
|
||||
int getNameIndex(String name);
|
||||
|
||||
/**
|
||||
* Remove the defined name at the specified index
|
||||
*
|
||||
* @param index named range index (0 based)
|
||||
*
|
||||
* @deprecated 3.18. New projects should use {@link #removeName(Name)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@Removal(version="3.20")
|
||||
void removeName(int index);
|
||||
|
||||
/**
|
||||
* Remove a defined name by name
|
||||
*
|
||||
* @param name the name of the defined name
|
||||
* @deprecated 3.18. New projects should use {@link #removeName(Name)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@Removal(version="3.20")
|
||||
void removeName(String name);
|
||||
|
||||
/**
|
||||
* Remove a defined name
|
||||
*
|
||||
|
|
|
@ -1236,69 +1236,6 @@ public class SXSSFWorkbook implements Workbook {
|
|||
public void setSheetVisibility(int sheetIx, SheetVisibility visibility) {
|
||||
_wb.setSheetVisibility(sheetIx, visibility);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nameIndex position of the named range (0-based)
|
||||
* @return the defined name at the specified index
|
||||
* @throws IllegalArgumentException if the supplied index is invalid
|
||||
* @deprecated 3.16. New projects should avoid accessing named ranges by index.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
@Removal(version="3.20")
|
||||
public Name getNameAt(int nameIndex) {
|
||||
//noinspection deprecation
|
||||
return _wb.getNameAt(nameIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the defined name index by name
|
||||
*
|
||||
* <i>Note:</i> Excel defined names are case-insensitive and
|
||||
* this method performs a case-insensitive search.
|
||||
*
|
||||
* @param name the name of the defined name
|
||||
* @return zero based index of the defined name. <code>-1</code> if not found.
|
||||
*
|
||||
* @deprecated 3.16. New projects should avoid accessing named ranges by index.
|
||||
* Use {@link #getName(String)} instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
@Removal(version="3.20")
|
||||
public int getNameIndex(String name) {
|
||||
//noinspection deprecation
|
||||
return _wb.getNameIndex(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the defined name at the specified index
|
||||
* @param index named range index (0 based)
|
||||
*
|
||||
* @deprecated 3.16. New projects should use {@link #removeName(Name)}.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
@Removal(version="3.20")
|
||||
public void removeName(int index) {
|
||||
//noinspection deprecation
|
||||
_wb.removeName(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a defined name by name
|
||||
*
|
||||
* @param name the name of the defined name
|
||||
*
|
||||
* @deprecated 3.16. New projects should use {@link #removeName(Name)}.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
@Removal(version="3.20")
|
||||
public void removeName(String name) {
|
||||
//noinspection deprecation
|
||||
_wb.removeName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* <i>Not implemented for SXSSFWorkbook</i>
|
||||
|
|
|
@ -1018,28 +1018,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
|
|||
return Collections.unmodifiableList(namedRangesByName.get(name.toLowerCase(Locale.ENGLISH)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the named range at the given index.
|
||||
*
|
||||
* @param nameIndex the index of the named range
|
||||
* @return the XSSFName at the given index
|
||||
*
|
||||
* @deprecated 3.16. New projects should avoid accessing named ranges by index.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public XSSFName getNameAt(int nameIndex) {
|
||||
int nNames = namedRanges.size();
|
||||
if (nNames < 1) {
|
||||
throw new IllegalStateException("There are no defined names in this workbook");
|
||||
}
|
||||
if (nameIndex < 0 || nameIndex > nNames) {
|
||||
throw new IllegalArgumentException("Specified name index " + nameIndex
|
||||
+ " is outside the allowable range (0.." + (nNames-1) + ").");
|
||||
}
|
||||
return namedRanges.get(nameIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all the named ranges in the workbook.
|
||||
*
|
||||
|
@ -1050,25 +1028,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
|
|||
return Collections.unmodifiableList(namedRanges);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the named range index by name.
|
||||
*
|
||||
* @param name named range name
|
||||
* @return named range index. <code>-1</code> is returned if no named ranges could be found.
|
||||
*
|
||||
* @deprecated 3.16. New projects should avoid accessing named ranges by index.
|
||||
* Use {@link #getName(String)} instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public int getNameIndex(String name) {
|
||||
XSSFName nm = getName(name);
|
||||
if (nm != null) {
|
||||
return namedRanges.indexOf(nm);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of styles the workbook contains
|
||||
*
|
||||
|
@ -1265,43 +1224,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
|
|||
return getPackagePart().getContentType().equals(XSSFRelation.MACROS_WORKBOOK.getContentType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the named range at the given index.
|
||||
*
|
||||
* @param nameIndex the index of the named range name to remove
|
||||
*
|
||||
* @deprecated 3.16. New projects should use {@link #removeName(Name)}.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void removeName(int nameIndex) {
|
||||
removeName(getNameAt(nameIndex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the first named range found with the given name.
|
||||
*
|
||||
* Note: names of named ranges are not unique (name + sheet
|
||||
* index is unique), so {@link #removeName(Name)} should
|
||||
* be used if possible.
|
||||
*
|
||||
* @param name the named range name to remove
|
||||
*
|
||||
* @throws IllegalArgumentException if no named range could be found
|
||||
*
|
||||
* @deprecated 3.16. New projects should use {@link #removeName(Name)}.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void removeName(String name) {
|
||||
List<XSSFName> names = namedRangesByName.get(name.toLowerCase(Locale.ENGLISH));
|
||||
if (names.isEmpty()) {
|
||||
throw new IllegalArgumentException("Named range was not found: " + name);
|
||||
}
|
||||
removeName(names.get(0));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* As {@link #removeName(String)} is not necessarily unique
|
||||
* (name + sheet index is unique), this method is more accurate.
|
||||
|
|
|
@ -25,6 +25,8 @@ import org.apache.poi.hssf.record.NameRecord;
|
|||
import org.apache.poi.ss.formula.FormulaType;
|
||||
import org.apache.poi.ss.formula.ptg.Ptg;
|
||||
import org.apache.poi.ss.usermodel.BaseTestNamedRange;
|
||||
import org.apache.poi.ss.usermodel.Name;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -50,7 +52,7 @@ public final class TestHSSFName extends BaseTestNamedRange {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRepeatingRowsAndColumsNames() throws Exception {
|
||||
public void testRepeatingRowsAndColumnsNames() throws Exception {
|
||||
// First test that setting RR&C for same sheet more than once only creates a
|
||||
// single Print_Titles built-in record
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
|
@ -240,4 +242,48 @@ public final class TestHSSFName extends BaseTestNamedRange {
|
|||
}
|
||||
wb.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testUnicodeNamedRange() throws Exception {
|
||||
HSSFWorkbook wb1 = new HSSFWorkbook();
|
||||
wb1.createSheet("Test");
|
||||
Name name = wb1.createName();
|
||||
name.setNameName("\u03B1");
|
||||
name.setRefersToFormula("Test!$D$3:$E$8");
|
||||
|
||||
|
||||
HSSFWorkbook wb2 = HSSFITestDataProvider.instance.writeOutAndReadBack(wb1);
|
||||
Name name2 = wb2.getNameAt(0);
|
||||
|
||||
assertEquals("\u03B1", name2.getNameName());
|
||||
assertEquals("Test!$D$3:$E$8", name2.getRefersToFormula());
|
||||
|
||||
wb2.close();
|
||||
wb1.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testHSSFAddRemove() throws Exception {
|
||||
HSSFWorkbook wb = HSSFITestDataProvider.instance.createWorkbook();
|
||||
assertEquals(0, wb.getNumberOfNames());
|
||||
Name name1 = wb.createName();
|
||||
name1.setNameName("name1");
|
||||
assertEquals(1, wb.getNumberOfNames());
|
||||
|
||||
Name name2 = wb.createName();
|
||||
name2.setNameName("name2");
|
||||
assertEquals(2, wb.getNumberOfNames());
|
||||
|
||||
Name name3 = wb.createName();
|
||||
name3.setNameName("name3");
|
||||
assertEquals(3, wb.getNumberOfNames());
|
||||
|
||||
wb.removeName(wb.getName("name2"));
|
||||
assertEquals(2, wb.getNumberOfNames());
|
||||
|
||||
wb.removeName(0);
|
||||
assertEquals(1, wb.getNumberOfNames());
|
||||
|
||||
wb.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,25 +116,6 @@ public abstract class BaseTestNamedRange {
|
|||
wb.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testUnicodeNamedRange() throws Exception {
|
||||
Workbook wb1 = _testDataProvider.createWorkbook();
|
||||
wb1.createSheet("Test");
|
||||
Name name = wb1.createName();
|
||||
name.setNameName("\u03B1");
|
||||
name.setRefersToFormula("Test!$D$3:$E$8");
|
||||
|
||||
|
||||
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
|
||||
Name name2 = wb2.getNameAt(0);
|
||||
|
||||
assertEquals("\u03B1", name2.getNameName());
|
||||
assertEquals("Test!$D$3:$E$8", name2.getRefersToFormula());
|
||||
|
||||
wb2.close();
|
||||
wb1.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testAddRemove() throws Exception {
|
||||
Workbook wb = _testDataProvider.createWorkbook();
|
||||
|
@ -151,12 +132,9 @@ public abstract class BaseTestNamedRange {
|
|||
name3.setNameName("name3");
|
||||
assertEquals(3, wb.getNumberOfNames());
|
||||
|
||||
wb.removeName("name2");
|
||||
wb.removeName(wb.getName("name2"));
|
||||
assertEquals(2, wb.getNumberOfNames());
|
||||
|
||||
wb.removeName(0);
|
||||
assertEquals(1, wb.getNumberOfNames());
|
||||
|
||||
wb.close();
|
||||
}
|
||||
|
||||
|
@ -460,10 +438,8 @@ public abstract class BaseTestNamedRange {
|
|||
newNamedRange2.setNameName("AnotherTest");
|
||||
newNamedRange2.setRefersToFormula(sheetName + "!$F$1:$G$6");
|
||||
|
||||
wb1.getNameAt(0);
|
||||
|
||||
Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1);
|
||||
Name nm =wb2.getName("RangeTest");
|
||||
Name nm = wb2.getName("RangeTest");
|
||||
assertEquals("Name is " + nm.getNameName(), "RangeTest", nm.getNameName());
|
||||
assertEquals("Reference is " + nm.getRefersToFormula(), (wb2.getSheetName(0) + "!$D$4:$E$8"), nm.getRefersToFormula());
|
||||
|
||||
|
@ -474,6 +450,7 @@ public abstract class BaseTestNamedRange {
|
|||
wb2.close();
|
||||
wb1.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies correct functioning for "single cell named range" (aka "named cell")
|
||||
*/
|
||||
|
@ -666,7 +643,7 @@ public abstract class BaseTestNamedRange {
|
|||
assertEquals("2", names.get(1).getRefersToFormula());
|
||||
|
||||
assertEquals("1", wb.getName("x").getRefersToFormula());
|
||||
wb.removeName("x");
|
||||
wb.removeName(wb.getName("x"));
|
||||
assertEquals("2", wb.getName("x").getRefersToFormula());
|
||||
|
||||
wb.close();
|
||||
|
|
Loading…
Reference in New Issue