public void ApplyDataLabels(XlDataLabelsType type) { object[] parameter = new object[10]; parameter[0] = type; parameter[1] = Missing.Value; parameter[2] = Missing.Value; parameter[3] = Missing.Value; parameter[4] = Missing.Value; parameter[5] = Missing.Value; parameter[6] = Missing.Value; parameter[7] = Missing.Value; parameter[8] = Missing.Value; parameter[9] = Missing.Value; InstanceType.InvokeMember("ApplyDataLabels", BindingFlags.InvokeMethod | BindingFlags.OptionalParamBinding, null, ComReference, parameter, XlLateBindingApiSettings.XlThreadCulture); }
protected void DrawChart(XlChartType ChartType) { // Variable declaration object misValue = System.Reflection.Missing.Value; ExcelObj.Range chartRange = null; try { this.Validate(); // split the cell range for the work sheet range string cell1 = strCellRange.Split(':')[0]; string cell2 = strCellRange.Split(':')[1]; base.InitWorkSheet(); if (base.SheetIndex > 0 && base.xlWorkSheet != null) { ExcelObj.ChartObjects xlCharts = (ExcelObj.ChartObjects)base.xlWorkSheet.ChartObjects(Type.Missing); try { // Define the cell range to the work sheet chartRange = xlWorkSheet.get_Range(cell1, cell2); } catch (Exception) { base.ClearObject(); throw new Exception("Invalid Range"); } // fix chart position by left,top,width,height ExcelObj.ChartObject chartObj = (ExcelObj.ChartObject)xlCharts.Add(dblChartLeft, dblChartTop, dblChartWidth, dblChartHeight); // Define char object ExcelObj._Chart chart = chartObj.Chart; // assign the datasource for the chart chart.SetSourceData(chartRange, misValue); // set the chart type. chart.ChartType = ChartType; // Ledgend show / hide chart.HasLegend = this.Options.ShowLedgend; // assign the chart title based on empty if (!string.IsNullOrEmpty(strChartTitle)) { chart.HasTitle = true; chart.ChartTitle.Text = strChartTitle; } else { chart.HasTitle = false; } XlDataLabelsType XlDataLabelsType = (XlDataLabelsType)this.Options.DataLabelsType; XlDataLabelsType XlLedgendKey = (XlDataLabelsType)this.Options.LedgendKey; // assign the data lable properties chart.ApplyDataLabels(XlDataLabelsType, XlLedgendKey, this.Options.AutoText, this.Options.HasLeaderLines, this.Options.ShowSeriesName, this.Options.ShowCategoryName, this.Options.ShowValue, this.Options.ShowPercentage, this.Options.ShowBubbleSize, this.Options.Separator); if (this.strImagecopy != null && !string.IsNullOrEmpty(this.strImagecopy)) { string strExten = new FileInfo(this.strImagecopy).Extension; strExten = strExten.Replace(".", ""); chart.Export(this.strImagecopy, strExten.ToUpper(), misValue); } base.SaveWorkBook(true); } } catch (ValidationException Vex) { base.ClearObject(); throw Vex; } catch (Exception ex) { base.ClearObject(); throw new Exception("DrawChart : " + ex.Message); } }
public void ApplyDataLabels(XlDataLabelsType type) { object[] paramArray = new object[1]; paramArray[0] = type; InstanceType.InvokeMember("ApplyDataLabels", BindingFlags.InvokeMethod | BindingFlags.OptionalParamBinding, null, ComReference, paramArray, XlLateBindingApiSettings.XlThreadCulture); }
/// <summary>将数据标签应用到图表中的所有系列。 /// </summary> /// <param name="Type">要应用的数据标签的类型。</param> /// <param name="LegendKey">如果为 True,则在数据点旁边显示图例项标示。默认值为 False。</param> /// <param name="AutoText">如果对象根据内容自动生成相应的文字,则为 True。</param> /// <param name="HasLeaderLines">对于 Chart 和 Series 对象,如果数据系列有引导线,则为 True。</param> /// <param name="ShowSeriesName">传递布尔值以启用或禁用数据标签的系列名称。</param> /// <param name="ShowCategoryName">传递布尔值以启用或禁用数据标签的分类名称。</param> /// <param name="ShowValue">传递布尔值以启用或禁用数据标签的值。</param> /// <param name="ShowPercentage">传递布尔值以启用或禁用数据标签的百分比。</param> /// <param name="ShowBubbleSize">传递布尔值以启用或禁用数据标签的气泡大小。</param> /// <param name="Separator">数据标签的分隔符。</param> public void ApplyDataLabels(XlDataLabelsType Type = XlDataLabelsType.xlDataLabelsShowValue, bool? LegendKey = null, bool? AutoText = null, bool? HasLeaderLines = null, bool? ShowSeriesName = null, bool? ShowCategoryName = null, bool? ShowValue = null, bool? ShowPercentage = null, bool? ShowBubbleSize = null, string Separator = null) { _objaParameters = new object[10] { Type, LegendKey == null ? System.Type.Missing : LegendKey, AutoText == null ? System.Type.Missing : AutoText, HasLeaderLines == null ? System.Type.Missing : HasLeaderLines, ShowSeriesName == null ? System.Type.Missing : ShowSeriesName, ShowCategoryName == null ? System.Type.Missing : ShowCategoryName, ShowValue == null ? System.Type.Missing : ShowValue, ShowPercentage == null ? System.Type.Missing : ShowPercentage, ShowBubbleSize == null ? System.Type.Missing : ShowBubbleSize, Separator == null ? System.Type.Missing : Separator }; _objChart.GetType().InvokeMember("ApplyDataLabels", BindingFlags.InvokeMethod, null, _objChart, _objaParameters); }