/// <summary> /// Create data serial by specified worksheet instance and data range. /// </summary> /// <param name="dataSource">Data source to read chart data from worksheet.</param> /// <param name="worksheet">Instance of worksheet that contains the data to be read.</param> /// <param name="labelAddress">The address to locate label of serial on worksheet.</param> /// <param name="addressOrName">Serial data specified by address position or range's name.</param> public WorksheetChartDataSerial(WorksheetChartDataSource dataSource, Worksheet worksheet, string labelAddress, string addressOrName) : this(dataSource, worksheet, new CellPosition(labelAddress)) { if (RangePosition.IsValidAddress(addressOrName)) { this.dataRange = new RangePosition(addressOrName); } else if (NamedRange.IsValidName(addressOrName)) { if (this.worksheet != null) { if (worksheet.TryGetNamedRange(addressOrName, out var range)) { this.dataRange = range; } else { throw new InvalidAddressException(addressOrName); } } else { throw new ReferenceObjectNotAssociatedException("Data source must associate to valid worksheet instance."); } } else { throw new InvalidAddressException(addressOrName); } }
/// <summary> /// Get range information from script value /// </summary> /// <param name="sheet">worksheet instance</param> /// <param name="arg">script object to be converted</param> /// <returns></returns> public static RangePosition GetRangeFromValue(Worksheet sheet, object arg) { if (arg is RangePosition) { return((RangePosition)arg); } else if (arg is string) { var addr = (string)arg; NamedRange namedRange; if (RangePosition.IsValidAddress(addr)) { return(new RangePosition(addr)); } else if (NamedRange.IsValidName(addr) && sheet.TryGetNamedRange(addr, out namedRange)) { return((RangePosition)namedRange); } else { throw new InvalidAddressException(addr); } } else if (arg is ReferenceRange) { return(((ReferenceRange)arg).Position); } else if (arg is RSSelectionObject) { return(sheet.SelectionRange); } else if (arg is RSRangeObject) { return(((RSRangeObject)arg).Range); } ObjectValue obj = arg as ObjectValue; if (obj == null) { return(RangePosition.Empty); } RangePosition range = RangePosition.Empty; range.Row = ScriptRunningMachine.GetIntValue(obj["row"]); range.Col = ScriptRunningMachine.GetIntValue(obj["col"]); range.Rows = ScriptRunningMachine.GetIntValue(obj["rows"]); range.Cols = ScriptRunningMachine.GetIntValue(obj["cols"]); return(range); }