Lines 57-62
Link Here
|
57 |
|
57 |
|
58 |
public class Workbook implements Model |
58 |
public class Workbook implements Model |
59 |
{ |
59 |
{ |
|
|
60 |
private static final String EXCEL_BUILT_IN_TITLES_ = "Excel_BuiltIn_Titles_"; |
60 |
private static final int DEBUG = POILogger.DEBUG; |
61 |
private static final int DEBUG = POILogger.DEBUG; |
61 |
|
62 |
|
62 |
// public static Workbook currentBook = null; |
63 |
// public static Workbook currentBook = null; |
Lines 1895-1918
Link Here
|
1895 |
*/ |
1896 |
*/ |
1896 |
public NameRecord addName(NameRecord name) |
1897 |
public NameRecord addName(NameRecord name) |
1897 |
{ |
1898 |
{ |
1898 |
|
|
|
1899 |
getOrCreateLinkTable().addName(name); |
1900 |
|
1899 |
|
|
|
1900 |
LinkTable linkTable = getOrCreateLinkTable(); |
1901 |
if (checkNameAlreadyExists(linkTable, name)) { |
1902 |
throw new IllegalArgumentException( |
1903 |
"You are trying to assign an already existing builtname record: " |
1904 |
+ name.getNameText()); |
1905 |
|
1906 |
} |
1907 |
linkTable.addName(name); |
1908 |
|
1901 |
return name; |
1909 |
return name; |
1902 |
} |
1910 |
} |
|
|
1911 |
|
1912 |
/** |
1913 |
* checks if the given name is already included in the given linkTable |
1914 |
* @param linkTable |
1915 |
* @param name |
1916 |
* @return |
1917 |
*/ |
1918 |
private boolean checkNameAlreadyExists(LinkTable linkTable, NameRecord name) { |
1919 |
for (int i = 0; i < linkTable.getNumNames(); i++) { |
1920 |
NameRecord nameRecord = linkTable.getNameRecord(i); |
1921 |
if (nameRecord.getNameText().equals(name.getNameText())) { |
1922 |
return true; |
1923 |
} |
1924 |
} |
1925 |
return false; |
1926 |
} |
1903 |
|
1927 |
|
1904 |
/**Generates a NameRecord to represent a built-in region |
1928 |
/**Generates a NameRecord to represent a built-in region |
1905 |
* @return a new NameRecord unless the index is invalid |
1929 |
* @return a new NameRecord unless the index is invalid |
1906 |
*/ |
1930 |
*/ |
1907 |
public NameRecord createBuiltInName(byte builtInName, int index) |
1931 |
public NameRecord createBuiltInName(byte builtInName, int index) |
1908 |
{ |
1932 |
{ |
1909 |
if (index == -1 || index+1 > Short.MAX_VALUE) |
1933 |
if (index == -1 || index + 1 > Short.MAX_VALUE) |
1910 |
throw new IllegalArgumentException("Index is not valid ["+index+"]"); |
1934 |
throw new IllegalArgumentException("Index is not valid [" + index |
1911 |
|
1935 |
+ "]"); |
1912 |
NameRecord name = new NameRecord(builtInName, (short)(index)); |
1936 |
|
1913 |
|
1937 |
NameRecord name = new NameRecord(builtInName, (short) (index)); |
|
|
1938 |
String prefix = EXCEL_BUILT_IN_TITLES_ + index + " "; |
1939 |
int cont = 0; |
1940 |
while (checkNameAlreadyExists(linkTable, name)) { |
1941 |
cont++; |
1942 |
name = new NameRecord(); |
1943 |
String built_in_name = prefix + cont; |
1944 |
name.setNameText(built_in_name); |
1945 |
} |
1946 |
|
1947 |
|
1914 |
addName(name); |
1948 |
addName(name); |
1915 |
|
1949 |
|
1916 |
return name; |
1950 |
return name; |
1917 |
} |
1951 |
} |
1918 |
|
1952 |
|