private static void freeGraphObjects(Graph.Chart vchart0, Graph.DataSheet vsheet0, Graph.Application vapp0) { vapp0.Quit(); GC.SuppressFinalize(vsheet0); GC.SuppressFinalize(vapp0); GC.SuppressFinalize(vchart0); }
//private void CreateImage() //{ // //Create image in slide // string innerChartFilePath = Server.MapPath("logo/venish.jpg"); // float width = 100; // float height = 100; // slide.Shapes.AddPicture(innerChartFilePath, C.MsoTriState.msoFalseore, Microsoft.Office.Core.MsoTriState.msoTrue, 10, slide.Shapes[2].Top, width, height); //} /// <summary> /// Create chart /// </summary> private void CreateChart() { TextRange textRange = slide.Shapes[1].TextFrame.TextRange; textRange.Text = "My Chart"; textRange.Font.Name = fontName; textRange.Font.Size = 24; Graph.Chart objChart = (Graph.Chart)slide.Shapes.AddOLEObject(150, 150, 480, 320, "MSGraph.Chart.8", "", MsoTriState.msoFalse, "", 0, "", MsoTriState.msoFalse).OLEFormat.Object; objChart.ChartType = Graph.XlChartType.xl3DPie; objChart.Legend.Position = Graph.XlLegendPosition.xlLegendPositionBottom; objChart.HasTitle = true; objChart.ChartTitle.Text = "Sales for Black Programming & Assoc."; }
public void CreatStrainResultDocument(IEnumerable <StrainDatasView> datas) { //数据源排序 var datasByOrder = datas.OrderBy(m => m.PointsNumber).ThenByDescending(m => m.Time); var groupDatas = datasByOrder.GroupBy(m => m.PointsNumber); //创建一个document,并给其加载模板 _Application oWord; _Document oDoc; oWord = new Microsoft.Office.Interop.Word.Application(); object templateName = System.Web.HttpContext.Current.Server.MapPath("~/Files/Template/应变查询结果模板.dotx"); oDoc = oWord.Documents.Add(templateName, ref oMissing, ref oMissing, ref oMissing); oWord.Visible = false;//当前office状态 //给标题赋值 object bookMark = TitleBookmark; Bookmark bm = oDoc.Bookmarks.get_Item(ref bookMark); bm.Range.Text = GetTitleText(groupDatas); oWord.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; //新建表格 Table strainTable; object strainTableBookmark = StrainTableBookmark; Microsoft.Office.Interop.Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref strainTableBookmark).Range; int RowsNumber = datas.Select(m => m.PointsNumber).ToArray().Length; strainTable = oDoc.Tables.Add(wrdRng, RowsNumber + 1, TableColumnsNumber, ref oMissing, ref oMissing); //设置表头信息 strainTable.Cell(1, 1).Range.Text = "序号"; strainTable.Cell(1, 2).Range.Text = "测点编号"; strainTable.Cell(1, 3).Range.Text = "测点位置"; strainTable.Cell(1, 4).Range.Text = "应变值"; strainTable.Cell(1, 5).Range.Text = "监测时间"; strainTable.Cell(1, 6).Range.Text = "温度"; //表格赋值 var testPoint = datasByOrder.Select(m => m.PointsNumber).ToArray(); var strainValue = datasByOrder.Select(m => m.Strain).ToArray(); var monitorTime = datasByOrder.Select(m => m.Time).ToArray(); var temperature = datasByOrder.Select(m => m.Temperature).ToArray(); for (int r = 2; r < RowsNumber + 2; r++) { strainTable.Cell(r, 1).Range.Text = (r - 1).ToString(); strainTable.Cell(r, 2).Range.Text = testPoint[r - 2]; strainTable.Cell(r, 3).Range.Text = null; strainTable.Cell(r, 4).Range.Text = strainValue[r - 2].ToString(); strainTable.Cell(r, 5).Range.Text = monitorTime[r - 2].ToString(); strainTable.Cell(r, 6).Range.Text = temperature[r - 2].ToString(); } //设置表格及内容格式 strainTable.Range.ParagraphFormat.SpaceAfter = 0; strainTable.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; strainTable.Rows.Alignment = WdRowAlignment.wdAlignRowCenter; for (int i = 1; i <= RowsNumber + 1; i++) { for (int j = 1; j <= TableColumnsNumber; j++) { strainTable.Cell(i, j).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter; } } //设置表格字体 strainTable.Rows[1].Range.Font.Bold = 1; strainTable.Rows[1].Range.Font.Name = "宋体"; strainTable.Rows[1].Range.Font.Size = float.Parse("12"); //设置表格边框 strainTable.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleDouble; strainTable.Borders.OutsideColor = WdColor.wdColorBlack; strainTable.Borders.OutsideLineWidth = WdLineWidth.wdLineWidth075pt; strainTable.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle; strainTable.Rows.Height = 20f; strainTable.Columns.Width = 70f; //创建应变查询结果统计值的表格 //--- 待实现 -- //绘制曲线图 InlineShape oShape; object oClassType = "MSGraph.Chart.8"; object statistictableBookmark = StatisticTableBookmark; Microsoft.Office.Interop.Word.Range owrdRng = oDoc.Bookmarks.get_Item(ref statistictableBookmark).Range; oShape = owrdRng.InlineShapes.AddOLEObject(ref oClassType, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); Microsoft.Office.Interop.Graph.Chart objChart = (Microsoft.Office.Interop.Graph.Chart)oShape.OLEFormat.Object; Microsoft.Office.Interop.Graph.Application oChartApp = objChart.Application; objChart.ChartType = XlChartType.xlXYScatterSmooth; objChart.Height = 300f; objChart.Width = 600f; objChart.HasTitle = true; objChart.ChartTitle.Text = "应变曲线图"; objChart.ChartTitle.Font.Size = 10; objChart.PlotArea.Interior.Color = Color.White; Microsoft.Office.Interop.Graph.Axis axis = (Microsoft.Office.Interop.Graph.Axis)objChart.Axes(1, 1); axis.HasTitle = true; // 设置X轴的标题(X轴表示什么) axis.AxisTitle.Text = "监测时间"; axis.AxisTitle.Font.Size = 10; Microsoft.Office.Interop.Graph.Axis ayis = (Microsoft.Office.Interop.Graph.Axis)objChart.Axes(2, 1); ayis.HasTitle = true; // 设置X轴的标题(X轴表示什么) ayis.AxisTitle.Text = "应变值"; ayis.AxisTitle.Font.Size = 10; axis.CategoryType = Microsoft.Office.Interop.Graph.XlCategoryType.xlTimeScale; //给曲线赋值 DataSheet dataSheet; dataSheet = objChart.Application.DataSheet; dataSheet.Columns.Clear(); dataSheet.Rows.Clear(); int rowNumber = 0; foreach (var item in groupDatas) { for (int j = 0; j < item.ToArray().Length; j++) { dataSheet.Cells[1, j + 2] = item.Select(m => m.Time).ToArray()[j]; dataSheet.Cells[rowNumber + 2, j + 2] = item.Select(m => m.Strain).ToArray()[j]; dataSheet.Cells[rowNumber + 2, 1] = item.Key; } rowNumber++; } try { oDoc.Save(); } catch { } }
public static void IncludeOthers(string path) { //Build Slide #2: //Add text to the slide title, format the text. Also add a chart to the //slide and change the chart type to a 3D pie chart. objSlide = objSlides.Add(objSlides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly); objTextRng = objSlide.Shapes[1].TextFrame.TextRange; objTextRng.Text = "My Chart"; objTextRng.Font.Name = "Comic Sans MS"; objTextRng.Font.Size = 48; objChart = (Graph.Chart)objSlide.Shapes.AddOLEObject(150, 150, 480, 320, "MSGraph.Chart.8", "", MsoTriState.msoFalse, "", 0, "", MsoTriState.msoFalse).OLEFormat.Object; objChart.ChartType = Graph.XlChartType.xl3DPie; objChart.Legend.Position = Graph.XlLegendPosition.xlLegendPositionBottom; objChart.HasTitle = true; objChart.ChartTitle.Text = "Here it is..."; //Build Slide #3: //Change the background color of this slide only. Add a text effect to the slide //and apply various color schemes and shadows to the text effect. objSlide = objSlides.Add(objSlides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutBlank); objSlide.FollowMasterBackground = MsoTriState.msoFalse; objShapes = objSlide.Shapes; objShape = objShapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect27, "The End", "Impact", 96, MsoTriState.msoFalse, MsoTriState.msoFalse, 230, 200); //Save the presentation to disk objPres.SaveAs(path, PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Microsoft.Office.Core.MsoTriState.msoFalse); //Modify the slide show transition settings for all 3 slides in //the presentation. int[] SlideIdx = new int[3]; for (int k = 0; k < 3; k++) SlideIdx[k] = k + 1; objSldRng = objSlides.Range(SlideIdx); objSST = objSldRng.SlideShowTransition; objSST.AdvanceOnTime = MsoTriState.msoTrue; objSST.AdvanceTime = 3; objSST.EntryEffect = PowerPoint.PpEntryEffect.ppEffectBoxOut; //Prevent Office Assistant from displaying alert messages: // bAssistantOn = objApp.Assistant.On; // objApp.Assistant.On = false; //Run the Slide show from slides 1 thru 3. objSSS = objPres.SlideShowSettings; objSSS.StartingSlide = 1; objSSS.EndingSlide = 3; objSSS.Run(); //Wait for the slide show to end. objSSWs = objApp.SlideShowWindows; while (objSSWs.Count >= 1) System.Threading.Thread.Sleep(100); ////Reenable Office Assisant, if it was on: //if (bAssistantOn) //{ // objApp.Assistant.On = true; // objApp.Assistant.Visible = false; //} //Close the presentation without saving changes and quit PowerPoint. // objPres.Close(); // objApp.Quit(); }
private void ThisAddIn_Startup(object sender, EventArgs e) { _helper = new Helper(); List <SlideModel> model = _helper.Comparator("258,259", 3); //PowerPoint.Presentation ppt = this.Application.Presentations.Add(); this.Application.Visible = Core.MsoTriState.msoTrue; //Create ppt document PowerPoint.Presentation ppt = this.Application.Presentations.Add(); //Add a blank slide PowerPoint.Slide slide = ppt.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank); //Add chart //PowerPoint.Shape shape = slide.Shapes.AddChart(Microsoft.Office.Core.XlChartType.xlBarStacked, 100, 100, 500, 300); Graph.Chart objChart = (Graph.Chart)slide.Shapes.AddOLEObject(150, 150, 480, 320, "MSGraph.Chart.5", "", Core.MsoTriState.msoFalse, "", 0, "", Core.MsoTriState.msoFalse).OLEFormat.Object; /* * //Get the chart * PowerPoint.Chart chart = slide.Shapes[1].Chart; * chart.ChartData.Workbook.Application.Visible = false; * //Create instance from excel workbook to work with chart data * PowerPoint.ChartData chartData = chart.ChartData; * Microsoft.Office.Interop.Excel.Workbook dataWorkbook = (Microsoft.Office.Interop.Excel.Workbook)chartData.Workbook; * * //Get the worksheet of chart * Microsoft.Office.Interop.Excel.Worksheet dataSheet = dataWorkbook.Worksheets[1]; * * //Set the range of chart * Microsoft.Office.Interop.Excel.Range range = dataSheet.Cells.get_Range("A1", "B5"); * * //Set the data * Microsoft.Office.Interop.Excel.ListObject table = dataSheet.ListObjects["Table1"]; * table.Resize(range); * ((Microsoft.Office.Interop.Excel.Range)(dataSheet.Cells.get_Range("A2"))).Value = "January"; * ((Microsoft.Office.Interop.Excel.Range)(dataSheet.Cells.get_Range("A3"))).Value = "February"; * ((Microsoft.Office.Interop.Excel.Range)(dataSheet.Cells.get_Range("A4"))).Value = "March"; * ((Microsoft.Office.Interop.Excel.Range)(dataSheet.Cells.get_Range("A5"))).Value = "April"; * ((Microsoft.Office.Interop.Excel.Range)(dataSheet.Cells.get_Range("B2"))).Value = 5; * ((Microsoft.Office.Interop.Excel.Range)(dataSheet.Cells.get_Range("B3"))).Value = 15; * ((Microsoft.Office.Interop.Excel.Range)(dataSheet.Cells.get_Range("B4"))).Value = 16; * ((Microsoft.Office.Interop.Excel.Range)(dataSheet.Cells.get_Range("B5"))).Value = 40; */ //Set the title of the chart // chart.ChartTitle.Text = "Monthly Sales Report"; //Save the file // ppt.SaveAs("AddedChart.pptx"); //foreach (var item in model) //{ ////Add a blank slide //PowerPoint.Slide slide = ppt.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank); ////Add chart //PowerPoint.Shape shape = slide.Shapes.AddChart(Microsoft.Office.Core.XlChartType.xlBarClustered, 100, 100, 500, 300); // //Get the chart // PowerPoint.Chart chart = slide.Shapes[1].Chart; ////Create instance from excel workbook to work with chart data //PowerPoint.ChartData chartData = chart.ChartData; //Microsoft.Office.Interop.Excel.Workbook dataWorkbook = (Microsoft.Office.Interop.Excel.Workbook)chartData.Workbook; ////Get the worksheet of chart //Microsoft.Office.Interop.Excel.Worksheet dataSheet = dataWorkbook.Worksheets[1]; // //dataSheet.EnableSelection = Microsoft.Office.Interop.Excel.XlEnableSelection.xlNoSelection; // //Set the range of chart // dataSheet = (Microsoft.Office.Interop.Excel.Worksheet)dataWorkbook.Worksheets.get_Item(1); //} //PowerPoint.Application app = new PowerPoint.Application(); //app.Visible = Core.MsoTriState.msoTrue; // Sure, let's watch the magic as it happens. //PowerPoint.Presentation pres = app.Presentations.Add(); //PowerPoint._Slide objSlide = pres.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly); //PowerPoint.TextRange textRange = objSlide.Shapes[1].TextFrame.TextRange; //textRange.Text = "My Chart"; //textRange.Font.Name = "Comic Sans MS"; // Oh yeah I did //textRange.Font.Size = 24; //Graph.Chart objChart = (Graph.Chart)objSlide.Shapes.AddOLEObject(150, 150, 480, 320, // "MSGraph.Chart.8", "", Core.MsoTriState.msoFalse, "", 0, "", // Core.MsoTriState.msoFalse).OLEFormat.Object; //objChart.ChartType = Graph.XlChartType.xlBarStacked; //objChart.Legend.Position = Graph.XlLegendPosition.xlLegendPositionBottom; //objChart.HasTitle = true; //objChart.ChartTitle.Text = "Sales for Black Programming & Assoc."; // I'm a regular comedian // PowerPoint.Presentation ppt = this.Application.Presentations.Add(); //Add a blank slide // PowerPoint.Slide slide = ppt.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank); //Add chart // PowerPoint.Shape shape = slide.Shapes.AddChart(Microsoft.Office.Core.XlChartType.xlBarClustered, 100, 100, 500, 300); //Get the chart // PowerPoint.Chart chart = slide.Shapes[1].Chart; //Create instance from excel workbook to work with chart data // PowerPoint.ChartData chartData = chart.ChartData; // Microsoft.Office.Interop.Excel.Workbook dataWorkbook = (Microsoft.Office.Interop.Excel.Workbook)chartData.Workbook; //Get the worksheet of chart // Microsoft.Office.Interop.Excel.Worksheet dataSheet = dataWorkbook.Worksheets[1]; //dataSheet.EnableSelection = Microsoft.Office.Interop.Excel.XlEnableSelection.xlNoSelection; //Set the range of chart // dataSheet = (Microsoft.Office.Interop.Excel.Worksheet)dataWorkbook.Worksheets.get_Item(1); // next 2 lines for split pane in Excel: //dataSheet.Application.ActiveWindow.SplitRow = 2; // dataSheet.Application.ActiveWindow.FreezePanes = true; //dataSheet.Cells[1, 1] = "Now open the"; //dataSheet.Cells[2, 1] = "Excel Options window"; //Microsoft.Office.Interop.Excel.Range range = dataSheet.Cells.get_Range("A2", "B5"); ////Set the data //Microsoft.Office.Interop.Excel.ListObject table = dataSheet.ListObjects["Table1"]; //table.Resize(range); //((Microsoft.Office.Interop.Excel.Range)(dataSheet.Cells.get_Range("A2"))).Value = "January"; //((Microsoft.Office.Interop.Excel.Range)(dataSheet.Cells.get_Range("A3"))).Value = "February"; //((Microsoft.Office.Interop.Excel.Range)(dataSheet.Cells.get_Range("A4"))).Value = "March"; //((Microsoft.Office.Interop.Excel.Range)(dataSheet.Cells.get_Range("A5"))).Value = "April"; //((Microsoft.Office.Interop.Excel.Range)(dataSheet.Cells.get_Range("B2"))).Value = 100; //((Microsoft.Office.Interop.Excel.Range)(dataSheet.Cells.get_Range("B3"))).Value = 250; //((Microsoft.Office.Interop.Excel.Range)(dataSheet.Cells.get_Range("B4"))).Value = 300; //((Microsoft.Office.Interop.Excel.Range)(dataSheet.Cells.get_Range("B5"))).Value = 400; //Set the title of the chart // chart.ChartTitle.Text = "Monthly Sales Report"; }
public void add_chart(ref List<question> questions, ref int question_no, ref int choices_no1,ref ColorDialog colordialog1, ref int data_format, ref Color[] bar_colors, ref FontDialog fontdialog1) { if (questions[question_no].show_chart == true) { objChart = objSlide.Shapes[2].OLEFormat.Object; Graph.SeriesCollection ss = objChart.SeriesCollection(); Graph.Points kj; kj = ss.Item(1).Points(); Graph.Axes kk; kk = objChart.Axes(); questions[question_no].datasheet = objChart.Application.DataSheet; /* datasheet.Cells[1, 3] = "ali"; datasheet.Cells[1, 4] = "ali"; datasheet.Cells[1, 5] = "ali"; datasheet.Cells[2, 4] = kk.Count; */ objChart.ApplyDataLabels(); for (int i = 2; i <= choices_no1 + 1; i++) { questions[question_no].datasheet.Cells[1, i] = i - 1; // kj.Item(i - 1).Interior.Color = } float total = 0; for (int i = 2; i <= choices_no1 + 1; i++) { total = (total + questions[question_no].values[i - 2]); } if (data_format == 2) { for (int i = 2; i <= choices_no1 + 1; i++) { Graph.DataLabel label = ss.Item(1).DataLabels(i - 1); questions[question_no].datasheet.Cells[2, i] = questions[question_no].values[i - 2]; kj.Item(i - 1).Interior.Color = bar_colors[i - 2]; } objShape2 = objSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 435, 480, 120, 70); objShape2.TextEffect.Text = "Total" + " " + total.ToString(); objShape2.TextEffect.FontName = "Comic Sans MS"; objShape2.TextEffect.FontSize = 15; objShape2.TextEffect.FontBold = MsoTriState.msoTrue; } else if (data_format == 1) { for (int i = 2; i <= choices_no1 + 1; i++) { Graph.DataLabel label = ss.Item(1).DataLabels(i - 1); questions[question_no].datasheet.Cells[2, i] = (((questions[question_no].values[i - 2]) / total) * 100) + "%"; kj.Item(i - 1).Interior.Color = bar_colors[i - 2]; } } else if (data_format == 3) { for (int i = 2; i <= choices_no1 + 1; i++) { questions[question_no].datasheet.Cells[2, i] = questions[question_no].values[i - 2]; Graph.DataLabel label = ss.Item(1).DataLabels(i - 1); label.Text = (((questions[question_no].values[i - 2]) / total) * 100).ToString("F") + "%" + "[" + questions[question_no].values[i - 2].ToString() + "]"; kj.Item(i - 1).Interior.Color = bar_colors[i - 2]; label.Font.Size = 15; } objShape2 = objSlide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 435, 480, 120, 70); objShape2.TextEffect.Text = "Total" + " " + total.ToString(); objShape2.TextEffect.FontName = "Comic Sans MS"; objShape2.TextEffect.FontSize = 15; objShape2.TextEffect.FontBold = MsoTriState.msoTrue; } objChart.Refresh(); objChart.Application.Update(); } }
public void add_chart1(ref List<Team> teams,ref List<Team> teams1 ) { objChart1 = objslide1.Shapes[1].OLEFormat.Object; objChart = objSlide.Shapes[1].OLEFormat.Object; Graph.SeriesCollection ss = objChart.SeriesCollection(); kj = ss.Item(1).Points(); // sc.Item(1).Values = 5; // questions[question_no].datasheet = objChart.Application.DataSheet; /* datasheet.Cells[1, 3] = "ali"; datasheet.Cells[1, 4] = "ali"; datasheet.Cells[1, 5] = "ali"; datasheet.Cells[2, 4] = kk.Count; */ //objChart.ApplyDataLabels(); datasheet= objChart.Application.DataSheet; //float total = 0; //for (int i = 2; i <= choices_no1 + 1; i++) //{ // total = (total + questions[question_no].values[i - 2]); //} objChart.ApplyDataLabels(); for (int i = 2; (16 - i) >= 0; i++) { datasheet.Cells[1, i] = teams[16 - i].KeyPad; // kj.Item(i - 1).Interior.Color = } for (int i = 2; (16-i) >=0 ; i++) { // Graph.DataLabel label = ss.Item(1).DataLabels(i - 1); datasheet.Cells[2, i] = teams[16-i].points; kj.Item(i - 1).Interior.Color = teams[16-i].bc; } Graph.Axes chart1 = objChart.Axes(); objchart2 = objSlide.Shapes[2].OLEFormat.Object; Graph.Axes chart2 = objchart2.Axes(); ss = objchart2.SeriesCollection(); kj = ss.Item(1).Points(); // sc.Item(1).Values = 5; // questions[question_no].datasheet = objChart.Application.DataSheet; /* datasheet.Cells[1, 3] = "ali"; datasheet.Cells[1, 4] = "ali"; datasheet.Cells[1, 5] = "ali"; datasheet.Cells[2, 4] = kk.Count; */ //objChart.ApplyDataLabels(); datasheet3 = objchart2.Application.DataSheet; //float total = 0; //for (int i = 2; i <= choices_no1 + 1; i++) //{ // total = (total + questions[question_no].values[i - 2]); //} objchart2.ApplyDataLabels(); for (int i = 2; (31-i) >14; i++) { datasheet3.Cells[1, i] = teams[31-i].KeyPad; // kj.Item(i - 1).Interior.Color = } for (int i = 2; (31 - i) >14; i++) { // Graph.DataLabel label = ss.Item(1).DataLabels(i - 1); datasheet3.Cells[2, i] = teams[31 - i].points; kj.Item(i - 1).Interior.Color = teams[31 - i].bc; } //second slide objChart1 =objslide1.Shapes[1].OLEFormat.Object; ss = objChart1.SeriesCollection(); // sc.Item(1).Values = 5; // questions[question_no].datasheet = objChart.Application.DataSheet; /* datasheet.Cells[1, 3] = "ali"; datasheet.Cells[1, 4] = "ali"; datasheet.Cells[1, 5] = "ali"; datasheet.Cells[2, 4] = kk.Count; */ //objChart.ApplyDataLabels(); datasheet1 = objChart1.Application.DataSheet; //float total = 0; //for (int i = 2; i <= choices_no1 + 1; i++) //{ // total = (total + questions[question_no].values[i - 2]); //} objChart1.ApplyDataLabels(); for (int i = 2; (i - 2) < teams1.Count; i++) { datasheet1.Cells[1, i] = teams1[i - 2].KeyPad; // kj.Item(i - 1).Interior.Color = } for (int i = 2; (i - 2) < teams1.Count; i++) { // Graph.DataLabel label = ss.Item(1).DataLabels(i - 1); datasheet1.Cells[2, i] = teams1[i - 2].time; kj = ss.Item(1).Points(); kj.Item(i - 1).Interior.Color = teams1[i - 2].bc; } }
private static void initGraphParams(Word.Application wordapp, Word.Document worddoc, out Graph.Chart vchart0, out Graph.DataSheet vsheet0, out Graph.Application vapp0, int gn = 0) { Word.Range rng0; Word.OLEFormat oleF0; rng0 = wordapp.Selection.Range; if (gn == 0) { rng0.Collapse(Direction: Word.WdCollapseDirection.wdCollapseEnd); rng0.InsertAfter("\r"); rng0.Collapse(Direction: Word.WdCollapseDirection.wdCollapseEnd);//rng0.Collapse( Direction:0); } oleF0 = worddoc.InlineShapes.AddOLEObject(ClassType: "MSGraph.Chart.8", Range: rng0).OLEFormat; oleF0.DoVerb(); vchart0 = oleF0.Object; vapp0 = vchart0.Application; vsheet0 = vapp0.DataSheet; vsheet0.Cells.Clear(); vsheet0.Cells.Clear(); }
private void SetChart(string formatStr, string Name, object value, Bookmark tempBookmark) { try { if (value != null) { XlChartType xlChartType = XlChartType.xlColumnClustered; if (formatStr != null) { if (!(formatStr == "CHARTLINE")) { if (formatStr == "CHARTPIE") { xlChartType = XlChartType.xl3DPieExploded; } } else { xlChartType = XlChartType.xlLine; } } System.Data.DataTable dataTable = value as System.Data.DataTable; object obj = "MSGraph.Chart.8"; Microsoft.Office.Interop.Word.Range range = tempBookmark.Range; InlineShape inlineShape = range.InlineShapes.AddOLEObject(ref obj, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing); if (tempBookmark.Range.Cells.Count == 1) { inlineShape.Width = tempBookmark.Range.Cells[1].Width - 20f; inlineShape.Height = tempBookmark.Range.Cells[1].Height; } object @object = inlineShape.OLEFormat.Object; object obj2 = @object.GetType().InvokeMember("Application", System.Reflection.BindingFlags.GetProperty, null, @object, null); object[] args = new object[] { 4 }; @object.GetType().InvokeMember("ChartType", System.Reflection.BindingFlags.SetProperty, null, @object, args); Microsoft.Office.Interop.Graph.Chart chart = (Microsoft.Office.Interop.Graph.Chart)inlineShape.OLEFormat.Object; chart.ChartType = xlChartType; chart.HasTitle = true; chart.ChartTitle.Text = dataTable.TableName; chart.PlotArea.Interior.Color = Color.White; if (!string.IsNullOrEmpty(dataTable.TableName)) { chart.ChartTitle.Font.Size = 12; } DataSheet dataSheet = chart.Application.DataSheet; dataSheet.Columns.Clear(); dataSheet.Rows.Clear(); foreach (DataColumn dataColumn in dataTable.Columns) { dataSheet.Cells[1, dataTable.Columns.IndexOf(dataColumn) + 1] = dataColumn.ColumnName; } foreach (DataRow dataRow in dataTable.Rows) { foreach (DataColumn dataColumn in dataTable.Columns) { if (dataRow[dataColumn] == System.DBNull.Value) { dataRow[dataColumn] = ""; } dataSheet.Cells[dataTable.Rows.IndexOf(dataRow) + 2, dataTable.Columns.IndexOf(dataColumn) + 1] = dataRow[dataColumn]; } } if (xlChartType != XlChartType.xl3DPieExploded) { chart.Legend.Position = Microsoft.Office.Interop.Graph.XlLegendPosition.xlLegendPositionTop; for (int i = 1; i <= dataTable.Rows.Count; i++) { Microsoft.Office.Interop.Graph.Series series = (Microsoft.Office.Interop.Graph.Series)chart.SeriesCollection(i); series.HasDataLabels = true; Color chartColor = this.GetChartColor(i); if (chartColor != Color.Empty) { series.Interior.Color = chartColor; } else { series.Interior.ColorIndex = 15 + i; } } } else { chart.HasLegend = false; Microsoft.Office.Interop.Graph.Series series = (Microsoft.Office.Interop.Graph.Series)chart.SeriesCollection(1); series.HasDataLabels = true; series.HasLeaderLines = true; } chart.Application.Update(); obj2.GetType().InvokeMember("Update", System.Reflection.BindingFlags.InvokeMethod, null, obj2, null); obj2.GetType().InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, obj2, null); } } catch (System.Exception ex) { throw new System.Exception("图表[" + tempBookmark.Name + "]数据加载出错:" + ex.Message); } }