View | Details | Raw Unified | Return to bug 43510
Collapse All | Expand All

(-)src/java/org/apache/poi/hssf/model/FormulaParser.java (-3 / +10 lines)
Lines 48-53 Link Here
48
 *  @author Pavel Krupets (pkrupets at palmtreebusiness dot com)
48
 *  @author Pavel Krupets (pkrupets at palmtreebusiness dot com)
49
 */
49
 */
50
public class FormulaParser {
50
public class FormulaParser {
51
    private final static Pattern CELL_REFERENCE_PATTERN = Pattern.compile("(?:('?)[^:\\\\/\\?\\*\\[\\]]+\\1!)?\\$?[A-Za-z]+\\$?[\\d]+");
51
    
52
    
52
    public static int FORMULA_TYPE_CELL = 0;
53
    public static int FORMULA_TYPE_CELL = 0;
53
    public static int FORMULA_TYPE_SHARED = 1;
54
    public static int FORMULA_TYPE_SHARED = 1;
Lines 299-313 Link Here
299
                tokens.add(new Ref3DPtg(first,externIdx));
300
                tokens.add(new Ref3DPtg(first,externIdx));
300
            }
301
            }
301
        } else {
302
        } else {
302
            //this can be either a cell ref or a named range !!
303
            //this can be either a cell ref or a named range
303
            boolean cellRef = true ; //we should probably do it with reg exp??
304
            boolean cellRef = CELL_REFERENCE_PATTERN.matcher(name).matches();
304
            boolean boolLit = (name.equals("TRUE") || name.equals("FALSE"));
305
            boolean boolLit = (name.equals("TRUE") || name.equals("FALSE"));
305
            if (boolLit) {
306
            if (boolLit) {
306
                tokens.add(new BoolPtg(name));
307
                tokens.add(new BoolPtg(name));
307
            } else if (cellRef) {
308
            } else if (cellRef) {
308
                tokens.add(new ReferencePtg(name));
309
                tokens.add(new ReferencePtg(name));
309
            }else {
310
            }else {
310
                //handle after named range is integrated!!
311
                boolean nameRecordExists = false;
312
                for(int i = 0; i < book.getNumNames(); i++)
313
                    if(book.getNameRecord(i).getNameText().equals(name))
314
                        nameRecordExists = true;
315
                if(!nameRecordExists)
316
                    Abort("Invalid reference to possible named range \"" + name + "\"");
317
                tokens.add(new NamePtg(name, book));
311
            }
318
            }
312
        }
319
        }
313
    }
320
    }

Return to bug 43510