/// <summary> /// Add a chart to the current worksheet. /// </summary> /// <param name="chart">An <see cref="T:Dt.Xls.Chart.IExcelChart" /> instance describe a chart settings.</param> /// <exception cref="T:System.NotSupportedException"></exception> public void SetSheetChart(IExcelChart chart) { if (chart == null) { throw new ArgumentNullException("chart"); } if (string.IsNullOrWhiteSpace(chart.Name)) { throw new NotSupportedException(ResourceHelper.GetResourceString("EmptyChartNameError")); } using (List <IExcelChart> .Enumerator enumerator = this.ExcelCharts.GetEnumerator()) { while (enumerator.MoveNext()) { if (enumerator.Current.Name == chart.Name) { throw new NotSupportedException(ResourceHelper.GetResourceString("CurrentWorksheetHasSameChartError")); } } } if (chart != null) { this.ExcelCharts.Add(chart); } }
public void SetExcelChart(int sheetIndex, IExcelChart chart) { if (chart != null) { this._workbook.Worksheets[sheetIndex].SetSheetChart(chart); } }
/// <summary> /// Adds the chart. /// </summary> /// <param name="chartType">Type of the chart.</param> /// <param name="chartName">Name of the chart.</param> /// <param name="fromRow">From row.</param> /// <param name="fromColumn">From column.</param> /// <param name="toRow">To row.</param> /// <param name="toColumn">To column.</param> /// <returns></returns> /// <exception cref="T:System.NotSupportedException"></exception> /// <exception cref="T:System.ArgumentOutOfRangeException">fromRow</exception> public IExcelChart AddChart(ExcelChartType chartType, string chartName, int fromRow, int fromColumn, int toRow, int toColumn) { if (string.IsNullOrWhiteSpace(chartName)) { throw new NotSupportedException(ResourceHelper.GetResourceString("EmptyChartNameError")); } using (List <IExcelChart> .Enumerator enumerator = this.ExcelCharts.GetEnumerator()) { while (enumerator.MoveNext()) { if (enumerator.Current.Name == chartName) { throw new NotSupportedException(ResourceHelper.GetResourceString("CurrentWorksheetHasSameChartError")); } } } if (fromRow < 0) { throw new ArgumentOutOfRangeException("fromRow"); } if (toRow >= this.RowCount) { throw new ArgumentOutOfRangeException("toRow"); } if (fromColumn < 0) { throw new ArgumentOutOfRangeException("fromColumn"); } if (toColumn >= this.ColumnCount) { throw new ArgumentOutOfRangeException("toColumn"); } IExcelChart chart = ChartFactory.GetChart(chartType); chart.Anchor = new TwoCellAnchor(fromRow, fromColumn, toRow, toColumn); chart.Name = chartName; this.ExcelCharts.Add(chart); return(chart); }