public void PersistCellLocation() { if (this.cell == null) { throw new NullReferenceException("The cell location is null. You have to call FindCellLocation before"); } string location = this.Cell.Location; if (!string.IsNullOrWhiteSpace(location)) { location = location.Substring(location.IndexOf(']') + 1); foreach (CellLocation cell in DataModel.Instance.CurrentWorkbook.ViolatedCells) { Regex rgx = new Regex(@"\$|="); if (cell.ViolationType.Equals(this.violationState) && rgx.Replace(cell.Location, "").Equals(rgx.Replace(location, ""))) { this.Cell = cell; cell.Violations.Add(this); cell.SetVisibility(DataModel.Instance.CurrentWorkbook.SelectedTab); return; } } this.cell = new CellLocation(workbook, location); this.cell.ViolationType = this.violationState; this.cell.Violations.Add(this); DataModel.Instance.CurrentWorkbook.ViolatedCells.Add(this.cell); } }
public bool EqualsWithoutType(object obj) { CellLocation other = obj as CellLocation; if ((object)other == null) { return(false); } return(Letter == other.Letter && Number == other.Number && ReferenceEquals(Worksheet, other.Worksheet)); }
/// <summary> /// Determines whether the specified object is equal to the current object. /// </summary> /// <param name="obj">The object to compare with the current object.</param> /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns> public override bool Equals(object obj) { CellLocation other = obj as CellLocation; if ((object)other == null) { return(false); } return(Letter == other.Letter && Number == other.Number && ViolationType == other.ViolationType && ReferenceEquals(Worksheet, other.Worksheet)); }
private void RemovefromCellLocation() { string location = this.Cell.Location; for (int i = DataModel.Instance.CurrentWorkbook.ViolatedCells.Count - 1; i >= 0; i--) { CellLocation cell = DataModel.Instance.CurrentWorkbook.ViolatedCells[i]; Regex rgx = new Regex(@"\$|="); if (cell.ViolationType.Equals(this.violationState) && rgx.Replace(cell.Location, "").Equals(rgx.Replace(location, ""))) { cell.Violations.Remove(this); return; } } }
private void FindCellLocation(String location) { if (!string.IsNullOrWhiteSpace(location)) { location = location.Substring(location.IndexOf(']') + 1); foreach (CellLocation cell in DataModel.Instance.CurrentWorkbook.ViolatedCells) { Regex rgx = new Regex(@"\$|="); if (cell.ViolationType.Equals(this.violationState) && rgx.Replace(cell.Location, "").Equals(rgx.Replace(location, ""))) { Cell = cell; return; } } this.cell = new CellLocation(workbook, location); } }
/// <summary> /// Gets the sif cell name of a cell location in a1style /// </summary> /// <param name="wb">workbook model</param> /// <param name="a1Adress">cell location in a1 style</param> /// <returns>sif cell name</returns> public String GetSIFCellName(WorkbookModel wb, String a1Adress) { // Important: There might be more than just one name for this cell! var name = new CellLocation(wb.Workbook, a1Adress).ScenarioNames.FirstOrDefault(); if (name != null) return name.Name; else return string.Empty; //foreach (Name n in wb.Workbook.Application.Names) //{ // if (n.RefersTo as String == a1Adress // && n.Name.Contains(Properties.Settings.Default.CellNameTag)) // { // return n.Name; // } //} //return String.Empty; }
/// <summary> /// Creates a new cell in the defined workbook /// </summary> /// <param name="root"></param> /// <param name="workbook"></param> public Cell(XElement root, Workbook workbook) { Id = Convert.ToInt32(root.Attribute(XName.Get("number")).Value); Content = root.Attribute(XName.Get("content")).Value; Location = new CellLocation(workbook, root.Attribute(XName.Get("location")).Value).Location; }
private void Sheet_SelectionChange(object Sh, Range Target) { if (Target.Cells.Count == 1) { int row = Target.Cells.Row; int column = Target.Cells.Column; string location = "=" + Target.Worksheet.Name + "!" + getExcelColumnName(column) + row; CellLocation cell = new CellLocation(this.workbook, location); switch (SelectedTab) { case SharedTabs.Open: this.Violations.ToList().ForEach(vi => vi.IsCellSelected = false); (from vi in Violations where vi.Cell.EqualsWithoutType(cell) select vi).ToList().ForEach(vi => vi.IsCellSelected = true); break; case SharedTabs.Later: this.LaterViolations.ToList().ForEach(vi => vi.IsCellSelected = false); (from vi in LaterViolations where vi.Cell.EqualsWithoutType(cell) select vi).ToList().ForEach(vi => vi.IsCellSelected = true); break; case SharedTabs.Ignore: this.IgnoredViolations.ToList().ForEach(vi => vi.IsCellSelected = false); (from vi in IgnoredViolations where vi.Cell.EqualsWithoutType(cell) select vi).ToList().ForEach(vi => vi.IsCellSelected = true); break; case SharedTabs.Archive: this.SolvedViolations.ToList().ForEach(vi => vi.IsCellSelected = false); (from vi in SolvedViolations where vi.Cell.EqualsWithoutType(cell) select vi).ToList().ForEach(vi => vi.IsCellSelected = true); break; } } }
/// <summary> /// Gets the sif cell name of a cell location in a1style /// </summary> /// <param name="wb">workbook model</param> /// <param name="a1Adress">cell location in a1 style</param> /// <returns>sif cell name</returns> public String GetSIFCellName(WorkbookModel wb, String a1Adress) { // Important: There might be more than just one name for this cell! var name = new CellLocation(wb.Workbook, a1Adress).ScenarioNames.FirstOrDefault(); if (name != null) return name.Name; else return string.Empty; }