/// <summary> /// To Display a Chart in the Panel Object /// </summary> /// <param name="objExcelChart">Chart to be Opened</param> /// <param name="ctrlCollPane">Panel Object to be Displayed</param> /// <returns>Returns Boolean Value the Method Succeded</returns> public bool ExcelChartRead(Excel.Chart objExcelChart, Panel ctrlCollPane) { Image imgChart = null; try { objExcelChart.Export(@"C:\TempGif.gif", "GIF", true); imgChart = new Image(); imgChart.ImageUrl = @"C:\TempGif.gif"; ctrlCollPane.Controls.Add(imgChart); imgChart.Dispose(); } catch (Exception expFileError) { Response.Write(expFileError.ToString()); return(false); } finally { if (imgChart != null) { imgChart.Dispose(); } } return(true); }
/// <summary> /// 开始绘制开挖剖面图的Chart对象 /// </summary> /// <returns>进行绘图的Chart对象的高度值,以磅为单位,可以用来确定Excel Application的高度值</returns> /// <remarks>绘图时,标高值与Excel中的Y坐标值的对应关系: /// 在程序中,定义了eleTop变量(以米为单位)与F_sngTopRef变量(以磅为单位), /// 它们指示的是此基坑区域中,地下室顶板的标高值与其在Excel绘图中对应的Y坐标值</remarks> private Microsoft.Office.Interop.Excel.Chart DrawChart(Microsoft.Office.Interop.Excel.Worksheet DrawingSheet, List <clsData_ProcessRegionData> SelectedRegion) { Microsoft.Office.Interop.Excel.Application DrawingApp = DrawingSheet.Application; DrawingApp.ScreenUpdating = false; DrawingApp.Caption = "开挖标高图"; //---------------- 创建一个新的,进行绘图的Chart对象 ------------------------------- Excel.Chart DrawingChart = default(Excel.Chart); DrawingChart = DrawingSheet.Shapes.AddChart(Top: 0, Left: 0).Chart; string TemplatePath = System.IO.Path.Combine(System.Convert.ToString(My.Settings.Default.Path_Template), Constants.FolderOrFileName.File_Template.Chart_Elevation); DrawingChart.Parent.Activate(); DrawingChart.ApplyChartTemplate(TemplatePath); this.F_Textbox_Info = DrawingChart.Shapes.Item(1).TextFrame2; DrawingChart.ChartTitle.Text = "开挖标高图"; // Microsoft.Office.Interop.Excel.SeriesCollection src = DrawingChart.SeriesCollection(); for (short i = 0; i <= 1 - src.Count; i++) //确保Chart中至少有两个数据系列 { src.NewSeries(); } // ----------------------- 设置绘图及Excel窗口的尺寸 ---------------------------- double ChartHeight = 400; double InsideLeft = 60; double InsideRight = 20; double LeastWidth_Chart = 500; double LeastWidth_Column = 100; // double ChartWidth = LeastWidth_Chart; double insideWidth = LeastWidth_Chart - InsideLeft - InsideRight; // ChartWidth = GetChartWidth(DrawingChart, SelectedRegion.Count, LeastWidth_Chart, LeastWidth_Column, InsideLeft + InsideRight, ref insideWidth); ChartSize Size_Chart_App = new ChartSize(ChartHeight, ChartWidth, 26, 9); ExcelFunction.SetLocation_Size(Size_Chart_App, DrawingChart, DrawingChart.Application, true); //With DrawingChart.PlotArea // .InsideLeft = InsideLeft // .InsideWidth = insideWidth //End With // -------------------------------------------------- return(DrawingChart); }
public static void Main() { Excel.Application ex = new Excel.Application(); ex.Visible = true; Excel.Workbook wb = ex.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet); Excel.Range rg = ex.ActiveCell; rg.set_Item(1, 1, "Competência"); rg.set_Item(1, 2, "Nota"); rg.set_Item(2, 1, "C++"); rg.set_Item(2, 2, "5"); rg.set_Item(3, 1, "UML"); rg.set_Item(3, 2, "6"); rg.set_Item(4, 1, "OOP"); rg.set_Item(4, 2, "5"); rg.set_Item(5, 1, "DB"); rg.set_Item(5, 2, "9"); rg.set_Item(6, 1, ".NET"); rg.set_Item(6, 2, "4"); rg.set_Item(7, 1, "XML"); rg.set_Item(7, 2, "4"); rg.AutoFormat(Excel.XlRangeAutoFormat.xlRangeAutoFormatClassic3, true, true, true, true, true, true); Excel.Chart ch = (Excel.Chart)ex.Charts.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing); ch.ChartType = Excel.XlChartType.xlRadarFilled; Excel.Worksheet ws = (Excel.Worksheet)ex.Worksheets["Plan1"]; Excel.Range lrg = ws.get_Range("A1", "B7"); ch.SetSourceData(lrg, Excel.XlRowCol.xlColumns); ch.Location(Excel.XlChartLocation.xlLocationAsObject, "Plan1"); ex.ActiveChart.HasLegend = false; ex.ActiveChart.HasTitle = true; ex.ActiveChart.ChartTitle.Text = "Gráfico de Competência"; Console.Write("Pressionar ENTER para sair do EXCEL"); Console.ReadLine(); ex.Quit(); }
/// <summary> /// Displaying a given Excel WorkSheet /// </summary> /// <param name="strFileName">The Filename to be selected</param> /// <param name="strSheetRChartName">The Sheet or Chart Name to be Displayed</param> /// <param name="bReadOnly">Specifies the File should be open in Read only mode, /// If it is true then the File will be open ReadOnly</param> /// <param name="lblErrorText">If any Error Occurs should be Displayed</param> /// <param name="bIsChart">Specifies whether it is a Chart</param> /// <returns>Returns Boolean Value the Method Succeded</returns> public bool DisplayExcelSheet(string strFileName, string strSheetRChartName, bool bReadOnly, Label lblErrorText, bool bIsChart) { appOP.DisplayAlerts = false; Excel.Workbook workbook = null; Excel.Worksheet worksheet = null; Excel.Chart chart = null; try { if (!bReadOnly) { // Write Mode Open //workbook = appOP.Workbooks.Open(strFileName, 2, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, true, 0, true, 1, 0); // For Optimal Opening workbook = appOP.Workbooks.Open(strFileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); } else { // Read Mode Open //workbook = appOP.Workbooks.Open(strFileName, 2, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, true, 0, true, 1, 0); // For Optimal Opening workbook = appOP.Workbooks.Open(strFileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); } // Reading of Excel File if (bIsChart) { chart = (Excel.Chart)workbook.Charts[strSheetRChartName]; } else { worksheet = (Excel.Worksheet)workbook.Sheets[strSheetRChartName]; } // Reading the File Information Codes goes Here if (bIsChart) { if (chart == null) { lblErrorText.Text = strSheetRChartName + " Chart is Not Available"; } else { ExcelChartRead(chart, this.pnlBottPane); } } else { if (worksheet == null) { lblErrorText.Text = strSheetRChartName + " Sheet is Available"; } else { this.pnlBottPane.Controls.Add(ExcelSheetRead(worksheet, lblErrText)); } } if (!bReadOnly) { // Write Mode Close workbook.Save(); workbook = null; } else { // Read Mode Close workbook.Close(false, false, Type.Missing); workbook = null; } } catch (Exception expInterop) { lblErrText.Text = expInterop.ToString(); return(false); } finally { if (workbook != null) { if (!bReadOnly) { // Write Mode Close workbook.Save(); workbook = null; } else { // Read Mode Close workbook.Close(false, false, Type.Missing); workbook = null; } } appOP.DisplayAlerts = true; } return(true); }
public void generateChart(int dataCnt) { //Q CHART Excel.Range chartRange; Excel.ChartObjects xlCharts = (Excel.ChartObjects)qVal.ChartObjects(Type.Missing); Excel.ChartObject myChart = xlCharts.Add(10, 80, 800, 500); Excel.Chart chartPage = myChart.Chart; string range = string.Format("B{0}", dataCnt - 1); string range2 = string.Format("C{0}", dataCnt - 1); chartRange = qVal.get_Range("A1", range); chartPage.SetSourceData(Source: chartRange); chartPage.ChartType = Excel.XlChartType.xlXYScatter; chartPage.HasTitle = true; chartPage.ChartTitle.Text = "Q-Value vs. Time"; chartPage.HasLegend = false; Excel.Axis xaxis = chartPage.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary); xaxis.HasTitle = true; xaxis.TickLabels.NumberFormat = "[h]:mm:ss;@"; xaxis.AxisTitle.Text = "Time"; Excel.Axis yaxis = chartPage.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary); yaxis.HasTitle = true; yaxis.AxisTitle.Text = "Q-Value"; //CENTER FREQ CHART Excel.ChartObjects xlCharts1 = (Excel.ChartObjects)centFreq.ChartObjects(Type.Missing); Excel.ChartObject myChart1 = xlCharts1.Add(10, 80, 800, 500); Excel.Chart chartPage1 = myChart1.Chart; chartRange = centFreq.get_Range("A1", range); chartPage1.SetSourceData(Source: chartRange); chartPage1.ChartType = Excel.XlChartType.xlXYScatter; chartPage1.HasTitle = true; chartPage1.ChartTitle.Text = "Center Frequency vs. Time"; chartPage1.HasLegend = false; Excel.Axis xaxis1 = chartPage1.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary); xaxis1.HasTitle = true; xaxis1.TickLabels.NumberFormat = "[h]:mm:ss;@"; xaxis1.AxisTitle.Text = "Time"; Excel.Axis yaxis1 = chartPage1.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary); yaxis1.HasTitle = true; yaxis1.AxisTitle.Text = "Center Frequency (Hz)"; //ROOM TEMP CHART Excel.ChartObjects xlCharts2 = (Excel.ChartObjects)roomTemp.ChartObjects(Type.Missing); Excel.ChartObject myChart2 = xlCharts2.Add(10, 80, 800, 500); Excel.Chart chartPage2 = myChart2.Chart; chartRange = roomTemp.get_Range("A1", range); chartPage2.SetSourceData(Source: chartRange); chartPage2.ChartType = Excel.XlChartType.xlXYScatter; chartPage2.HasTitle = true; chartPage2.ChartTitle.Text = "Room Temp vs. Time"; chartPage2.HasLegend = false; Excel.Axis xaxis2 = chartPage2.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary); xaxis2.HasTitle = true; xaxis2.TickLabels.NumberFormat = "[h]:mm:ss;@"; xaxis2.AxisTitle.Text = "Time"; Excel.Axis yaxis2 = chartPage2.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary); yaxis2.HasTitle = true; yaxis2.AxisTitle.Text = "Room Temperature (C)"; //CAVITY TEMP CHART Excel.ChartObjects xlCharts3 = (Excel.ChartObjects)cavityTemp.ChartObjects(Type.Missing); Excel.ChartObject myChart3 = xlCharts3.Add(10, 80, 800, 500); Excel.Chart chartPage3 = myChart3.Chart; chartRange = cavityTemp.get_Range("A1", range); chartPage3.SetSourceData(Source: chartRange); chartPage3.ChartType = Excel.XlChartType.xlXYScatter; chartPage3.HasTitle = true; chartPage3.ChartTitle.Text = "Cavity Temp vs. Time"; chartPage3.HasLegend = false; Excel.Axis xaxis3 = chartPage3.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary); xaxis3.HasTitle = true; xaxis3.TickLabels.NumberFormat = "[h]:mm:ss;@"; xaxis3.AxisTitle.Text = "Time"; Excel.Axis yaxis3 = chartPage3.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary); yaxis3.HasTitle = true; yaxis3.AxisTitle.Text = "Cavity Temperature (C)"; //Matlab SVD Q Excel.ChartObjects xlCharts4 = (Excel.ChartObjects)Q_L.ChartObjects(Type.Missing); Excel.ChartObject myChart4 = xlCharts4.Add(10, 80, 800, 500); Excel.Chart chartPage4 = myChart4.Chart; chartRange = Q_L.get_Range("A1", range); chartPage4.SetSourceData(Source: chartRange); chartPage4.ChartType = Excel.XlChartType.xlXYScatter; chartPage4.HasTitle = true; chartPage4.ChartTitle.Text = "Q Loaded vs. Time"; chartPage4.HasLegend = false; Excel.Axis xaxis4 = chartPage4.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary); xaxis4.HasTitle = true; xaxis4.TickLabels.NumberFormat = "[h]:mm:ss;@"; xaxis4.AxisTitle.Text = "Time"; Excel.Axis yaxis4 = chartPage4.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary); yaxis4.HasTitle = true; yaxis4.AxisTitle.Text = "Q Value"; //Matlab SVD Q minus Network Analyzer Excel.ChartObjects xlCharts5 = (Excel.ChartObjects)svd_na.ChartObjects(Type.Missing); Excel.ChartObject myChart5 = xlCharts5.Add(10, 80, 800, 500); Excel.Chart chartPage5 = myChart5.Chart; chartRange = svd_na.get_Range("A1", range2); chartPage5.SetSourceData(Source: chartRange); chartPage5.ChartType = Excel.XlChartType.xlXYScatter; chartPage5.HasTitle = true; chartPage5.ChartTitle.Text = "SVD Q and NA Q vs. Time"; chartPage5.HasLegend = true; Excel.Series series1 = chartPage5.SeriesCollection(1); series1.Name = "NA Q"; Excel.Series series2 = chartPage5.SeriesCollection(2); series2.Name = "SVD Q"; Excel.Axis xaxis5 = chartPage5.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary); xaxis5.HasTitle = true; xaxis5.TickLabels.NumberFormat = "[h]:mm:ss;@"; xaxis5.AxisTitle.Text = "Time"; Excel.Axis yaxis5 = chartPage5.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary); yaxis5.HasTitle = true; yaxis5.AxisTitle.Text = "Q Value"; //Unloaded Q //Matlab SVD Q minus Network Analyzer Excel.ChartObjects xlCharts6 = (Excel.ChartObjects)Q_UL.ChartObjects(Type.Missing); Excel.ChartObject myChart6 = xlCharts6.Add(10, 80, 800, 500); Excel.Chart chartPage6 = myChart6.Chart; chartRange = Q_UL.get_Range("A1", range); chartPage6.SetSourceData(Source: chartRange); chartPage6.ChartType = Excel.XlChartType.xlXYScatter; chartPage6.HasTitle = true; chartPage6.ChartTitle.Text = "Unloaded Q vs. Time"; chartPage6.HasLegend = false; Excel.Axis xaxis6 = chartPage6.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary); xaxis6.HasTitle = true; xaxis6.TickLabels.NumberFormat = "[h]:mm:ss;@"; xaxis6.AxisTitle.Text = "Time"; Excel.Axis yaxis6 = chartPage6.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary); yaxis6.HasTitle = true; yaxis6.AxisTitle.Text = "Unloaded Q"; //SVD Center Frequency //Matlab SVD Q minus Network Analyzer Excel.ChartObjects xlCharts7 = (Excel.ChartObjects)f_center.ChartObjects(Type.Missing); Excel.ChartObject myChart7 = xlCharts7.Add(10, 80, 800, 500); Excel.Chart chartPage7 = myChart7.Chart; chartRange = f_center.get_Range("A1", range); chartPage7.SetSourceData(Source: chartRange); chartPage7.ChartType = Excel.XlChartType.xlXYScatter; chartPage7.HasTitle = true; chartPage7.ChartTitle.Text = "SVD Center Frequency vs. Time"; chartPage7.HasLegend = false; Excel.Axis xaxis7 = chartPage7.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary); xaxis7.HasTitle = true; xaxis7.TickLabels.NumberFormat = "[h]:mm:ss;@"; xaxis7.AxisTitle.Text = "Time"; Excel.Axis yaxis7 = chartPage7.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary); yaxis7.HasTitle = true; yaxis7.AxisTitle.Text = "SVD Center Frequency (GHz)"; //SVD S21 Excel.ChartObjects xlCharts8 = (Excel.ChartObjects)s21.ChartObjects(Type.Missing); Excel.ChartObject myChart8 = xlCharts8.Add(10, 80, 800, 500); Excel.Chart chartPage8 = myChart8.Chart; chartRange = s21.get_Range("A1", range); chartPage8.SetSourceData(Source: chartRange); chartPage8.ChartType = Excel.XlChartType.xlXYScatter; chartPage8.HasTitle = true; chartPage8.ChartTitle.Text = "SVD S21 vs. Time"; chartPage8.HasLegend = false; Excel.Axis xaxis8 = chartPage8.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary); xaxis8.HasTitle = true; xaxis8.TickLabels.NumberFormat = "[h]:mm:ss;@"; xaxis8.AxisTitle.Text = "Time"; Excel.Axis yaxis8 = chartPage8.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary); yaxis8.HasTitle = true; yaxis8.AxisTitle.Text = "S21 (W)"; //SVD vs NA center freq Excel.ChartObjects xlCharts9 = (Excel.ChartObjects)svd_na_center.ChartObjects(Type.Missing); Excel.ChartObject myChart9 = xlCharts9.Add(10, 80, 800, 500); Excel.Chart chartPage9 = myChart9.Chart; chartRange = svd_na_center.get_Range("A1", range2); chartPage9.SetSourceData(Source: chartRange); chartPage9.ChartType = Excel.XlChartType.xlXYScatter; chartPage9.HasTitle = true; chartPage9.ChartTitle.Text = "SVD and NA Center Frequency vs. Time"; chartPage9.HasLegend = true; Excel.Series series3 = chartPage9.SeriesCollection(1); series3.Name = "NA Center Frequency"; Excel.Series series4 = chartPage9.SeriesCollection(2); series4.Name = "SVD Center Frequency"; Excel.Axis xaxis9 = chartPage9.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary); xaxis9.HasTitle = true; xaxis9.TickLabels.NumberFormat = "[h]:mm:ss;@"; xaxis9.AxisTitle.Text = "Time"; Excel.Axis yaxis9 = chartPage9.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary); yaxis9.HasTitle = true; yaxis9.AxisTitle.Text = "Center Frequency (GHz)"; }