/// <summary> /// 获取指定区域的矩形(从0行0列按0,0开始算) /// </summary> /// <param name="p_range"></param> /// <returns></returns> public Rect GetRangeLocation(CellRange p_range) { if (p_range == null || !p_range.IsValidRange(this)) { return(new Rect()); } double top = 0; double left = 0; double width = 0; double height = 0; for (int i = 0; i < p_range.Column; i++) { left += GetActualColumnWidth(i, SheetArea.Cells); } for (int i = 0; i < p_range.ColumnCount; i++) { width += GetActualColumnWidth(i + p_range.Column, SheetArea.Cells); } for (int i = 0; i < p_range.Row; i++) { top += GetActualRowHeight(i, SheetArea.Cells); } for (int i = 0; i < p_range.RowCount; i++) { height += GetActualRowHeight(i + p_range.Row, SheetArea.Cells); } return(new Rect(left, top, width, height)); }
/// <summary> /// 当选中图表的时候,显示图表数据范围,不选中不显示。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "IsSelected") { SpreadChart chart = sender as SpreadChart; if (chart == null) { return; } Worksheet sheet = _excel.ActiveSheet; string[] Position = chart.Name.Substring(chart.Name.IndexOf("!") + 1).Split(','); if (Position.Length != 4) { return; } CellRange range = new CellRange(int.Parse(Position[0]), int.Parse(Position[1]), int.Parse(Position[2]), int.Parse(Position[3])); if (!range.IsValidRange(sheet)) { return; } _excel.DecorationRange = chart.IsSelected ? range : null; } }
void myCell_EditModeOff(object sender, EventArgs e) { if (myCell == null) { return; } CellRange SelectRange = new CellRange(myCell.ActiveSheet.ActiveRowIndex, myCell.ActiveSheet.ActiveColumnIndex, 1, 1); if (!SelectRange.IsValidRange(myCell.ActiveSheet)) { return; } Boolean Have = false; foreach (List <string> ls in chartInputData.Values) { List <string> x = new List <string>(ls[0].ToLower().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); List <string> y = new List <string>(ls[1].ToLower().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); String r = Arabic_Numerals_Convert.Excel_Word_Numerals(myCell.ActiveSheet.ActiveColumnIndex) + (myCell.ActiveSheet.ActiveRowIndex + 1).ToString(); if (x.Contains(r.ToLower()) || y.Contains(r.ToLower())) { Have = true; break; } } if (!Have) { return; } UpdateChartData(); UpdateChartImage(); }