internal override void Execute(ExcelFile Workbook, TWaitingCoords Coords, TBand Band) { int t, l, b, r; GetBounds(Coords, out t, out l, out b, out r); int fr = Math.Min(t, b); int fc = Math.Min(l, r); int lr = Math.Max(t, b); int lc = Math.Max(l, r); TValueAndXF val = new TValueAndXF(); val.Workbook = Workbook; XFDef.Evaluate(0, 0, 0, 0, val); TConfigFormat fmt = FormatList.GetValue(FlxConvert.ToString(val.Value)); if (fmt.ApplyFmt == null) { Workbook.SetCellFormat(fr, fc, lr, lc, fmt.XF); } else { Workbook.SetCellFormat(fr, fc, lr, lc, Workbook.GetFormat(fmt.XF), fmt.ApplyFmt, fmt.ExteriorBorders); } }
private static string ReadCachedValueTxt(object obj, int MaxStringConstantLen) { if (obj is double) { return(TFormulaMessages.FloatToString((double)obj)); } if (obj is string) { string s = fts(TFormulaToken.fmStr) + GetString(FlxConvert.ToString(obj), MaxStringConstantLen) + fts(TFormulaToken.fmStr); return(s); } if (obj is bool) { return(GetBoolText((bool)obj)); } if (obj is TFlxFormulaErrorValue) { return(GetErrorText((TFlxFormulaErrorValue)obj)); } XlsMessages.ThrowException(XlsErr.ErrBadToken, FlxConvert.ToString(obj)); return(String.Empty); }
internal override bool OnFound(ExcelFile xls, object oldval, int row, int col) { TFormula oldFmla = oldval as TFormula; if (!FSearchInFormulas && oldFmla != null) { return(false); //do not replace if it is a formula. } if (oldval == null) { return(false); } TRichString OldStr = oldval as TRichString; if (OldStr == null) { OldStr = new TRichString(FlxConvert.ToString(oldval)); } TRichString newStr = OldStr.Replace(SearchToStr, NewValue.ToString(), FCaseInsensitive); if (newStr != null && newStr.Value != null && newStr.Length > 0 && newStr.Value.StartsWith(TFormulaMessages.TokenString(TFormulaToken.fmStartFormula))) { TFormulaSpan Span = oldFmla != null ? oldFmla.Span : new TFormulaSpan(); xls.SetCellValue(row, col, new TFormula(newStr.Value, null, Span)); } else { if (oldFmla != null && !oldFmla.Span.IsOneCell) { return(false); //can't replace a shared formula with simple text. } xls.SetCellFromString(row, col, newStr); } ReplaceCount++; return(false); }
protected void CalcBounds(TOneCellValue aRange) { TValueAndXF val = new TValueAndXF(); val.Workbook = aRange.Workbook; aRange.Evaluate(0, 0, 0, 0, val); TXlsNamedRange XlsRange = val.Workbook.GetNamedRange(FlxConvert.ToString(val.Value), -1, val.Workbook.ActiveSheet); if (XlsRange == null) { XlsRange = val.Workbook.GetNamedRange(FlxConvert.ToString(val.Value), -1, 0); } if (XlsRange != null) { FTop = XlsRange.Top; FLeft = XlsRange.Left; Bottom = XlsRange.Bottom; Right = XlsRange.Right; Sheet1 = XlsRange.SheetIndex; Sheet2 = XlsRange.SheetIndex; RowAbs1 = false; ColAbs1 = false; RowAbs2 = false; ColAbs2 = false; return; } string[] Addresses = FlxConvert.ToString(val.Value).Split(TFormulaMessages.TokenChar(TFormulaToken.fmRangeSep)); if (Addresses == null || (Addresses.Length != 2 && Addresses.Length != 1)) { FlxMessages.ThrowException(FlxErr.ErrInvalidRef, FlxConvert.ToString(val.Value)); } TCellAddress FirstCell = new TCellAddress(Addresses[0]); if (FirstCell.Sheet == null || FirstCell.Sheet.Length == 0) { Sheet1 = -1; } else { Sheet1 = aRange.Workbook.GetSheetIndex(FirstCell.Sheet); } FTop = FirstCell.Row; FLeft = FirstCell.Col; RowAbs1 = FirstCell.RowAbsolute; ColAbs1 = FirstCell.ColAbsolute; if (Addresses.Length > 1) { FirstCell = new TCellAddress(Addresses[1]); } if (FirstCell.Sheet == null || FirstCell.Sheet.Length == 0) { Sheet2 = Sheet1; } else { Sheet2 = aRange.Workbook.GetSheetIndex(FirstCell.Sheet); } Bottom = FirstCell.Row; Right = FirstCell.Col; RowAbs2 = FirstCell.RowAbsolute; ColAbs2 = FirstCell.ColAbsolute; }
public string W() { StringBuilder sb = new StringBuilder(); sb.Append(TPdfTokens.GetString(TPdfToken.OpenArray)); TWKeyList a = new TWKeyList(FList.Keys); a.Sort(); if (a.Count <= 0) { sb.Append(TPdfTokens.GetString(TPdfToken.CloseArray)); return(sb.ToString()); } int LastW = Convert.ToInt32(FList[a[0]], CultureInfo.InvariantCulture); int LastI = 0; int LastKey = Convert.ToInt32(a[0]); bool ContinueKey = false; bool ArrayOpened = false; for (int i = 1; i <= a.Count; i++) { char key = i == a.Count? (char)a[i - 1]: (char)a[i]; int w = Convert.ToInt32(FList[key]); if (w != LastW || i == a.Count) { if (LastI + 1 < i) { if (ArrayOpened) { sb.Append(TPdfTokens.GetString(TPdfToken.CloseArray) + TPdfTokens.NewLine); } ArrayOpened = false; if (LastW != FDW) { int z = 1; if (i == a.Count) { z = 0; } sb.Append(FlxConvert.ToString(Convert.ToInt32(LastKey)) + " " + FlxConvert.ToString(Convert.ToInt32(key - z) + " ")); sb.Append(LastW + TPdfTokens.NewLine); } } else { if (!ContinueKey) { if (ArrayOpened) { sb.Append(TPdfTokens.GetString(TPdfToken.CloseArray) + TPdfTokens.NewLine); } ArrayOpened = false; sb.Append(Convert.ToInt32(LastKey) + " " + TPdfTokens.GetString(TPdfToken.OpenArray)); ArrayOpened = true; } else { sb.Append(" "); } sb.Append(LastW); } ContinueKey = LastKey + 1 == key; LastKey = key; LastI = i; LastW = w; } } if (ArrayOpened) { sb.Append(TPdfTokens.GetString(TPdfToken.CloseArray) + TPdfTokens.NewLine); } sb.Append(TPdfTokens.GetString(TPdfToken.CloseArray)); return(sb.ToString()); }