internal static void SetCellFromString(ExcelFile Workbook, int r, int c, string p, string[] DateFormats) { if (Workbook.VirtualMode) { int XF = FlxConsts.DefaultFormatId; CellValue cv = new CellValue(Workbook.ActiveSheet, r, c, Workbook.ConvertString(new TRichString(p), ref XF, DateFormats), -1); if (cv.Value is DateTime) { cv.Value = TExcelTypes.ConvertToAllowedObject(cv.Value, Workbook.OptionsDates1904); } cv.XF = XF; Workbook.OnVirtualCellRead(Workbook, new VirtualCellReadEventArgs(cv)); } else { Workbook.SetCellFromString(r, c, p, DateFormats); } }
internal static readonly TCellComparer Instance = new TCellComparer(); //STATIC* #region IComparer Members public int Compare(object x, object y) { x = TExcelTypes.ConvertToAllowedObject(x, TBaseParsedToken.Dates1904); y = TExcelTypes.ConvertToAllowedObject(y, TBaseParsedToken.Dates1904); //null values go always at the bottom. (in ascending or descending order) if (x == null) { if (y == null) { return(0); } return(1); } if (y == null) { return(-1); } if (x is TFlxFormulaErrorValue) { if (y is TFlxFormulaErrorValue) { return(((int)x).CompareTo((int)y)); } return(1); } if (y is TFlxFormulaErrorValue) { return(-1); } object Result = TBaseParsedToken.CompareValues(x, y); if (Result is int) { return((int)Result); } return(0); }
internal TSearchOrReplace(bool aDates1904, object aSearchItem, bool aCaseInsensitive, bool aSearchInFormulas, bool aWholeCellContents) { SearchItem = TExcelTypes.ConvertToAllowedObject(aSearchItem, aDates1904); SearchStr = aSearchItem as String; FCaseInsensitive = aCaseInsensitive; if (aCaseInsensitive) { FStringComparison = StringComparison.CurrentCultureIgnoreCase; } else { FStringComparison = StringComparison.CurrentCulture; } FSearchInFormulas = aSearchInFormulas; FWholeCellContents = aWholeCellContents; if (SearchItem != null) { SearchToStr = aSearchItem.ToString(); UpperSearchItem = SearchToStr.ToUpper(CultureInfo.CurrentCulture); } }
internal static void Write(TextWriter OutString, ExcelFile Workbook, TXlsCellRange Range, int[] ColumnWidths, int CharactersForFirstColumn, bool ExportHiddenRowsOrColumns, bool ExportTextOutsideCells) { if (Range == null) { Range = new TXlsCellRange(1, 1, Workbook.RowCount, Workbook.GetColCount(Workbook.ActiveSheet, false)); } for (int r = Range.Top; r <= Range.Bottom; r++) { if (!ExportHiddenRowsOrColumns && Workbook.GetRowHidden(r)) { continue; } int cIndex = 0; double FirstColWidth = Workbook.GetColWidth(Range.Left); string Remaining = string.Empty; int AcumColLen = 0; bool InMergedCell = false; THFlxAlignment MergedAlign = THFlxAlignment.general; TCellType MergedType = TCellType.Unknown; int OrigColLen = 0; for (int c = Range.Left; c <= Range.Right; c++) { if (!ExportHiddenRowsOrColumns && Workbook.GetColHidden(c)) { continue; } string s = Workbook.GetStringFromCell(r, c).ToString(); TFlxFormat fmt = null; if (ExportTextOutsideCells) { fmt = Workbook.GetCellVisibleFormatDef(r, c); } if (string.IsNullOrEmpty(s)) { s = Remaining; } int ColLen = 0; if (ColumnWidths == null) { if (CharactersForFirstColumn <= 0) { ColLen = s.Length; } else if (FirstColWidth <= 0) { ColLen = 0; } else { ColLen = (int)Math.Round((double)CharactersForFirstColumn * Workbook.GetColWidth(c) / FirstColWidth); } } else { if (cIndex >= ColumnWidths.Length) { break; } ColLen = ColumnWidths[cIndex]; } cIndex++; if (InMergedCell) { OrigColLen += ColLen; } else { OrigColLen = ColLen; } if (s.Length == 0) { AcumColLen += ColLen; continue; } THFlxAlignment HAlign = THFlxAlignment.left; TCellType CellType; if (InMergedCell) { HAlign = MergedAlign; CellType = MergedType; } else { Object CellVal = Workbook.GetCellValue(r, c); TFormula fmla = CellVal as TFormula; if (fmla != null) { CellVal = fmla.Result; } CellType = TExcelTypes.ObjectToCellType(CellVal); if (ExportTextOutsideCells && fmt != null && Remaining.Length == 0) { HAlign = GetDataAlign(CellType, fmt); } } if (HAlign == THFlxAlignment.left) { OutString.Write(new string(' ', AcumColLen)); } else { TXlsCellRange mr = Workbook.CellMergedBounds(r, c); InMergedCell = mr.Right > c; if (mr.Right > c) { AcumColLen += ColLen; if (c == mr.Left) { Remaining = s; MergedAlign = HAlign; MergedType = CellType; } continue; } if (mr.Right > mr.Left) { s = Remaining; Remaining = string.Empty; } MergedAlign = THFlxAlignment.left; MergedType = TCellType.Unknown; InMergedCell = false; ColLen += AcumColLen; } AcumColLen = 0; if (s.Length > ColLen) { if (ExportTextOutsideCells && HAlign == THFlxAlignment.right) { if (CellType == TCellType.Number) { OutString.Write(new string('#', ColLen)); } else { OutString.Write(s.Substring(s.Length - ColLen)); } } else { OutString.Write(s.Substring(0, ColLen)); } if (ExportTextOutsideCells && HAlign != THFlxAlignment.right) { Remaining = s.Substring(ColLen); } } else { int Pad = ColLen - s.Length; if (ExportTextOutsideCells && Remaining.Length == 0) { Pad = TextAlign(OutString, HAlign, s.Length, ColLen, OrigColLen); } OutString.Write(s); OutString.Write(new string(' ', Pad)); Remaining = string.Empty; } } if (ExportTextOutsideCells && Remaining.Length > 0) { OutString.Write(Remaining); } Remaining = string.Empty; OutString.Write(TCompactFramework.NewLine); } }