/** * Constructor called when creating a data validation from the API */ public DVParser(int c1, int r1, int c2, int r2) { wasCopied = false; type = LIST; errorStyle = STOP; condition = BETWEEN; hasExtendedCellsValidation = false; // the options stringListGiven = false; emptyCellsAllowed = true; suppressArrow = false; showPrompt = true; showError = true; promptTitle = "\0"; errorTitle = "\0"; promptText = "\0"; errorText = "\0"; StringBuilder formulaString = new StringBuilder(); CellReferenceHelper.getCellReference(c1, r1, formulaString); formulaString.Append(':'); CellReferenceHelper.getCellReference(c2, r2, formulaString); formula1String = formulaString.ToString(); }
/** * Constructor called when creating a data validation from the API */ public DVParser(double val1, double val2, Condition c) { wasCopied = false; type = DECIMAL; errorStyle = STOP; condition = c; hasExtendedCellsValidation = false; // the options stringListGiven = false; emptyCellsAllowed = true; suppressArrow = false; showPrompt = true; showError = true; promptTitle = "\0"; errorTitle = "\0"; promptText = "\0"; errorText = "\0"; formula1String = DECIMAL_FORMAT.format(val1); if (!System.Double.IsNaN(val2)) { formula2String = DECIMAL_FORMAT.format(val2); } }
static public DVType getType(int v) { DVType found = null; for (int i = 0; i < types.Length && found == null; i++) { if (types[i].value == v) { found = types[i]; } } return(found); }
/** * Constructor called when creating a data validation from the API */ public DVParser(IList strings) { wasCopied = false; type = LIST; errorStyle = STOP; condition = BETWEEN; hasExtendedCellsValidation = false; // the options stringListGiven = true; emptyCellsAllowed = true; suppressArrow = false; showPrompt = true; showError = true; promptTitle = "\0"; errorTitle = "\0"; promptText = "\0"; errorText = "\0"; if (strings.Count == 0) { //logger.warn("no validation strings - ignoring"); } StringBuilder formulaString = new StringBuilder(); foreach (string s in strings) { if (formulaString.Length > 0) { formulaString.Append('\0'); formulaString.Append(' '); } formulaString.Append(s); } // If the formula string exceeds // the maximum validation list length, then truncate and stop there if (formulaString.Length > MAX_VALIDATION_LIST_LENGTH) { //logger.warn("Validation list exceeds maximum number of characters - truncating"); formulaString.Remove(MAX_VALIDATION_LIST_LENGTH, formulaString.Length - MAX_VALIDATION_LIST_LENGTH); } // Put the string in quotes formulaString.Insert(0, '\"'); formulaString.Append('\"'); formula1String = formulaString.ToString(); }
/** * Constructor called when creating a data validation from the API */ public DVParser(string namedRange) { // Handle the case for an empty string if (namedRange.Length == 0) { wasCopied = false; type = FORMULA; errorStyle = STOP; condition = EQUAL; hasExtendedCellsValidation = false; // the options stringListGiven = false; emptyCellsAllowed = false; suppressArrow = false; showPrompt = true; showError = true; promptTitle = "\0"; errorTitle = "\0"; promptText = "\0"; errorText = "\0"; formula1String = "\"\""; return; } wasCopied = false; type = LIST; errorStyle = STOP; condition = BETWEEN; hasExtendedCellsValidation = false; // the options stringListGiven = false; emptyCellsAllowed = true; suppressArrow = false; showPrompt = true; showError = true; promptTitle = "\0"; errorTitle = "\0"; promptText = "\0"; errorText = "\0"; formula1String = namedRange; }
/** * Constructor called when doing a cell deep copy */ public DVParser(DVParser copy) { wasCopied = true; type = copy.type; errorStyle = copy.errorStyle; condition = copy.condition; stringListGiven = copy.stringListGiven; emptyCellsAllowed = copy.emptyCellsAllowed; suppressArrow = copy.suppressArrow; showPrompt = copy.showPrompt; showError = copy.showError; promptTitle = copy.promptTitle; promptText = copy.promptText; errorTitle = copy.errorTitle; errorText = copy.errorText; hasExtendedCellsValidation = copy.extendedCellsValidation(); row1 = copy.row1; row2 = copy.row2; column1 = copy.column1; column2 = copy.column2; // Don't copy the formula parsers - just take their string equivalents if (copy.formula1String != null) { formula1String = copy.formula1String; formula2String = copy.formula2String; } else { try { formula1String = copy.formula1.getFormula(); formula2String = (copy.formula2 != null) ? copy.formula2.getFormula() : null; } catch (FormulaException e) { //logger.warn("Cannot parse validation formula: " + e.Message); } } // Don't copy the cell references - these will be added later }
/** * Constructor */ public DVParser(byte[] data, ExternalSheet es, WorkbookMethods nt, WorkbookSettings ws) { Assert.verify(nt != null); wasCopied = false; int options = IntegerHelper.getInt(data[0], data[1], data[2], data[3]); int typeVal = options & 0xf; type = DVType.getType(typeVal); int errorStyleVal = (options & 0x70) >> 4; errorStyle = ErrorStyle.getErrorStyle(errorStyleVal); int conditionVal = (options & 0xf00000) >> 20; condition = Condition.getCondition(conditionVal); stringListGiven = (options & STRING_LIST_GIVEN_MASK) != 0; emptyCellsAllowed = (options & EMPTY_CELLS_ALLOWED_MASK) != 0; suppressArrow = (options & SUPPRESS_ARROW_MASK) != 0; showPrompt = (options & SHOW_PROMPT_MASK) != 0; showError = (options & SHOW_ERROR_MASK) != 0; int pos = 4; int length = IntegerHelper.getInt(data[pos], data[pos + 1]); if (length > 0 && data[pos + 2] == 0) { promptTitle = StringHelper.getString(data, length, pos + 3, ws); pos += length + 3; } else if (length > 0) { promptTitle = StringHelper.getUnicodeString(data, length, pos + 3); pos += length * 2 + 3; } else { pos += 3; } length = IntegerHelper.getInt(data[pos], data[pos + 1]); if (length > 0 && data[pos + 2] == 0) { errorTitle = StringHelper.getString(data, length, pos + 3, ws); pos += length + 3; } else if (length > 0) { errorTitle = StringHelper.getUnicodeString(data, length, pos + 3); pos += length * 2 + 3; } else { pos += 3; } length = IntegerHelper.getInt(data[pos], data[pos + 1]); if (length > 0 && data[pos + 2] == 0) { promptText = StringHelper.getString(data, length, pos + 3, ws); pos += length + 3; } else if (length > 0) { promptText = StringHelper.getUnicodeString(data, length, pos + 3); pos += length * 2 + 3; } else { pos += 3; } length = IntegerHelper.getInt(data[pos], data[pos + 1]); if (length > 0 && data[pos + 2] == 0) { errorText = StringHelper.getString(data, length, pos + 3, ws); pos += length + 3; } else if (length > 0) { errorText = StringHelper.getUnicodeString(data, length, pos + 3); pos += length * 2 + 3; } else { pos += 3; } int formula1Length = IntegerHelper.getInt(data[pos], data[pos + 1]); pos += 4; int formula1Pos = pos; pos += formula1Length; int formula2Length = IntegerHelper.getInt(data[pos], data[pos + 1]); pos += 4; int formula2Pos = pos; pos += formula2Length; pos += 2; row1 = IntegerHelper.getInt(data[pos], data[pos + 1]); pos += 2; row2 = IntegerHelper.getInt(data[pos], data[pos + 1]); pos += 2; column1 = IntegerHelper.getInt(data[pos], data[pos + 1]); pos += 2; column2 = IntegerHelper.getInt(data[pos], data[pos + 1]); pos += 2; hasExtendedCellsValidation = (row1 == row2 && column1 == column2) ? false : true; // Do the formulas try { // First, create a temporary blank cell for any formula relative // references EmptyCell tmprt = new EmptyCell(column1, row1); if (formula1Length != 0) { byte[] tokens = new byte[formula1Length]; System.Array.Copy(data, formula1Pos, tokens, 0, formula1Length); formula1 = new FormulaParser(tokens, tmprt, es, nt, ws, ParseContext.DATA_VALIDATION); formula1.parse(); } if (formula2Length != 0) { byte[] tokens = new byte[formula2Length]; System.Array.Copy(data, formula2Pos, tokens, 0, formula2Length); formula2 = new FormulaParser(tokens, tmprt, es, nt, ws, ParseContext.DATA_VALIDATION); formula2.parse(); } } catch (FormulaException e) { //logger.warn(e.Message + " for cells " + // CellReferenceHelper.getCellReference(column1,row1) + "-" + // CellReferenceHelper.getCellReference(column2,row2)); } }
/** * Constructor called when creating a data validation from the API */ public DVParser(double val1,double val2,Condition c) { wasCopied = false; type = DECIMAL; errorStyle = STOP; condition = c; hasExtendedCellsValidation = false; // the options stringListGiven = false; emptyCellsAllowed = true; suppressArrow = false; showPrompt = true; showError = true; promptTitle = "\0"; errorTitle = "\0"; promptText = "\0"; errorText = "\0"; formula1String = DECIMAL_FORMAT.format(val1); if (!System.Double.IsNaN(val2)) formula2String = DECIMAL_FORMAT.format(val2); }
/** * Constructor called when creating a data validation from the API */ public DVParser(int c1,int r1,int c2,int r2) { wasCopied = false; type = LIST; errorStyle = STOP; condition = BETWEEN; hasExtendedCellsValidation = false; // the options stringListGiven = false; emptyCellsAllowed = true; suppressArrow = false; showPrompt = true; showError = true; promptTitle = "\0"; errorTitle = "\0"; promptText = "\0"; errorText = "\0"; StringBuilder formulaString = new StringBuilder(); CellReferenceHelper.getCellReference(c1,r1,formulaString); formulaString.Append(':'); CellReferenceHelper.getCellReference(c2,r2,formulaString); formula1String = formulaString.ToString(); }
/** * Constructor called when creating a data validation from the API */ public DVParser(IList strings) { wasCopied = false; type = LIST; errorStyle = STOP; condition = BETWEEN; hasExtendedCellsValidation = false; // the options stringListGiven = true; emptyCellsAllowed = true; suppressArrow = false; showPrompt = true; showError = true; promptTitle = "\0"; errorTitle = "\0"; promptText = "\0"; errorText = "\0"; if (strings.Count == 0) { //logger.warn("no validation strings - ignoring"); } StringBuilder formulaString = new StringBuilder(); foreach (string s in strings) { if (formulaString.Length > 0) { formulaString.Append('\0'); formulaString.Append(' '); } formulaString.Append(s); } // If the formula string exceeds // the maximum validation list length, then truncate and stop there if (formulaString.Length > MAX_VALIDATION_LIST_LENGTH) { //logger.warn("Validation list exceeds maximum number of characters - truncating"); formulaString.Remove(MAX_VALIDATION_LIST_LENGTH,formulaString.Length - MAX_VALIDATION_LIST_LENGTH); } // Put the string in quotes formulaString.Insert(0,'\"'); formulaString.Append('\"'); formula1String = formulaString.ToString(); }
/** * Constructor */ public DVParser(byte[] data, ExternalSheet es, WorkbookMethods nt, WorkbookSettings ws) { Assert.verify(nt != null); wasCopied = false; int options = IntegerHelper.getInt(data[0],data[1],data[2],data[3]); int typeVal = options & 0xf; type = DVType.getType(typeVal); int errorStyleVal = (options & 0x70) >> 4; errorStyle = ErrorStyle.getErrorStyle(errorStyleVal); int conditionVal = (options & 0xf00000) >> 20; condition = Condition.getCondition(conditionVal); stringListGiven = (options & STRING_LIST_GIVEN_MASK) != 0; emptyCellsAllowed = (options & EMPTY_CELLS_ALLOWED_MASK) != 0; suppressArrow = (options & SUPPRESS_ARROW_MASK) != 0; showPrompt = (options & SHOW_PROMPT_MASK) != 0; showError = (options & SHOW_ERROR_MASK) != 0; int pos = 4; int length = IntegerHelper.getInt(data[pos],data[pos + 1]); if (length > 0 && data[pos + 2] == 0) { promptTitle = StringHelper.getString(data,length,pos + 3,ws); pos += length + 3; } else if (length > 0) { promptTitle = StringHelper.getUnicodeString(data,length,pos + 3); pos += length * 2 + 3; } else { pos += 3; } length = IntegerHelper.getInt(data[pos],data[pos + 1]); if (length > 0 && data[pos + 2] == 0) { errorTitle = StringHelper.getString(data,length,pos + 3,ws); pos += length + 3; } else if (length > 0) { errorTitle = StringHelper.getUnicodeString(data,length,pos + 3); pos += length * 2 + 3; } else { pos += 3; } length = IntegerHelper.getInt(data[pos],data[pos + 1]); if (length > 0 && data[pos + 2] == 0) { promptText = StringHelper.getString(data,length,pos + 3,ws); pos += length + 3; } else if (length > 0) { promptText = StringHelper.getUnicodeString(data,length,pos + 3); pos += length * 2 + 3; } else { pos += 3; } length = IntegerHelper.getInt(data[pos],data[pos + 1]); if (length > 0 && data[pos + 2] == 0) { errorText = StringHelper.getString(data,length,pos + 3,ws); pos += length + 3; } else if (length > 0) { errorText = StringHelper.getUnicodeString(data,length,pos + 3); pos += length * 2 + 3; } else { pos += 3; } int formula1Length = IntegerHelper.getInt(data[pos],data[pos + 1]); pos += 4; int formula1Pos = pos; pos += formula1Length; int formula2Length = IntegerHelper.getInt(data[pos],data[pos + 1]); pos += 4; int formula2Pos = pos; pos += formula2Length; pos += 2; row1 = IntegerHelper.getInt(data[pos],data[pos + 1]); pos += 2; row2 = IntegerHelper.getInt(data[pos],data[pos + 1]); pos += 2; column1 = IntegerHelper.getInt(data[pos],data[pos + 1]); pos += 2; column2 = IntegerHelper.getInt(data[pos],data[pos + 1]); pos += 2; hasExtendedCellsValidation = (row1 == row2 && column1 == column2) ? false : true; // Do the formulas try { // First, create a temporary blank cell for any formula relative // references EmptyCell tmprt = new EmptyCell(column1,row1); if (formula1Length != 0) { byte[] tokens = new byte[formula1Length]; System.Array.Copy(data,formula1Pos,tokens,0,formula1Length); formula1 = new FormulaParser(tokens,tmprt,es,nt,ws, ParseContext.DATA_VALIDATION); formula1.parse(); } if (formula2Length != 0) { byte[] tokens = new byte[formula2Length]; System.Array.Copy(data,formula2Pos,tokens,0,formula2Length); formula2 = new FormulaParser(tokens,tmprt,es,nt,ws, ParseContext.DATA_VALIDATION); formula2.parse(); } } catch (FormulaException e) { //logger.warn(e.Message + " for cells " + // CellReferenceHelper.getCellReference(column1,row1) + "-" + // CellReferenceHelper.getCellReference(column2,row2)); } }