https://bz.apache.org/bugzilla/show_bug.cgi?id=58452
--- Comment #2 from Javen ONeal <[email protected]> --- Created attachment 33167 --> https://bz.apache.org/bugzilla/attachment.cgi?id=33167&action=edit supporting changes (java docs, add FormulaParsingWorkbook.createName) Two approaches here how to handle when an "completely unknown name" is found in the workbook: 1) Add the name to the workbook and use that to create the NamePtg that is linked to the workbook. > nameToken = _book.getNameXPtg(name, null); > if (nameToken == null) { > // name is not an internal or external name > if (log.check(POILogger.WARN)) { > log.log(POILogger.WARN, > "Name '" + name + "' is completely unknown in the current > workbook."); > } > // name is probably the name of an unregistered User-Defined Function > addName(name); > hName = _book.getName(name, _sheetIndex); > nameToken = hName.createPtg(); > } 2) Do not add the name to the workbook. Create a NamePtg that isn't linked to the workbook. https://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java?revision=1700670&view=markup#l943 > nameToken = _book.getNameXPtg(name, null); > if (nameToken == null) { > if (log.check(POILogger.WARN)) { > log.log(POILogger.WARN, > "Name '" + name + "' is completely unknown in the current > workbook."); > } > switch(_book.getSpreadsheetVersion()) { > case EXCEL97: > nameToken = new NameXPtg(name); > break; > case EXCEL2007: > nameToken = new NameXPxg(name); > break; > default: > throw new IllegalStateException("Unrecognized SpreadsheetVersion" > + _book.getSpreadsheetVersion()); > } > } The second case seems like a cleaner solution since it doesn't introduce weird side-effects (name gets added to workbook). However, HSSFWorkbooks require all non-built-in-names (for named ranges and UDFs, registered or not) to have an entry in the internal or external names table. Thus, in order to save an HSSFWorkbook, we must add the name to the workbook, meaning option 1 is the only feasible option here. This is because the function name token is serialized as an index into the worksheet names table, not a string of the function name. Workbook.createName is currently not accessible in FormulaParser.parse. In the attached patch, I add createName to the FormulaParsingWorkbook interface so that these names can be created. FormulaParsingWorkbook { public Name createName() { return _uBook.createName() } } Alternatively, we could just expose the _uBook Workbook via a getWorkbook() call, and that'd save us from proxying so many functions to the underlying Workbook. Let me know if you'd prefer that solution and I will upload the patches with those changes. -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
