Exemplo n.º 1
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //Access vsto application
            Microsoft.Office.Interop.Excel.Application app = Globals.ThisAddIn.Application;

            //Access workbook
            Microsoft.Office.Interop.Excel.Workbook workbook = app.ActiveWorkbook;

            //Access worksheet
            Microsoft.Office.Interop.Excel.Worksheet m_sheet = workbook.Worksheets[1];

            //Access vsto worksheet
            Microsoft.Office.Tools.Excel.Worksheet sheet = Globals.Factory.GetVstoObject(m_sheet);

            //Place some text in cell A1 without wrapping
            Microsoft.Office.Interop.Excel.Range cellA1 = sheet.Cells.get_Range("A1");
            cellA1.Value = "Sample Text Unwrapped";

            //Place some text in cell A5 with wrapping
            Microsoft.Office.Interop.Excel.Range cellA5 = sheet.Cells.get_Range("A5");
            cellA5.Value    = "Sample Text Wrapped";
            cellA5.WrapText = true;

            //Save the workbook
            workbook.SaveAs("OutputVsto.xlsx");

            //Quit the application
            app.Quit();
        }
Exemplo n.º 2
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //<snippet1>
            Microsoft.Office.Interop.Excel.Worksheet nativeWorksheet =
                Globals.ThisAddIn.Application.ActiveSheet;
            if (nativeWorksheet != null)
            {
                Microsoft.Office.Tools.Excel.Worksheet vstoSheet =
                    Globals.Factory.GetVstoObject(nativeWorksheet);
            }
            //</snippet1>

            //<snippet2>
            Microsoft.Office.Interop.Excel.Workbook nativeWorkbook =
                Globals.ThisAddIn.Application.ActiveWorkbook;
            if (nativeWorkbook != null)
            {
                Microsoft.Office.Tools.Excel.Workbook vstoWorkbook =
                    Globals.Factory.GetVstoObject(nativeWorkbook);
            }
            //</snippet2>

            //<snippet3>
            Microsoft.Office.Interop.Excel.Worksheet sheet =
                Globals.ThisAddIn.Application.ActiveSheet;
            if (sheet.ListObjects.Count > 0)
            {
                Excel.ListObject listObject =
                    sheet.ListObjects[1];
                Microsoft.Office.Tools.Excel.ListObject vstoListObject =
                    Globals.Factory.GetVstoObject(listObject);
            }
            //</snippet3>
        }
Exemplo n.º 3
0
        //<snippet1>
        void ThisWorkbook_SheetActivate2(object Sh)
        {
            Microsoft.Office.Tools.Excel.Worksheet   vstoWorksheet    = null;
            Microsoft.Office.Interop.Excel.Worksheet interopWorksheet =
                Sh as Microsoft.Office.Interop.Excel.Worksheet;

            if (interopWorksheet != null && Globals.Factory.HasVstoObject(interopWorksheet))
            {
                vstoWorksheet = Globals.Factory.GetVstoObject(interopWorksheet);
            }

            if (vstoWorksheet != null)
            {
                // Do something with the VSTO worksheet here.
            }
        }
Exemplo n.º 4
0
 private void Form_ChartSize_Load(object sender, EventArgs e)
 {
     try
     {
         worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);
         chart     = Globals.ThisAddIn.Application.ActiveChart;
         textBox_ChartHeight.Text    = Convert.ToString(Math.Ceiling(chart.ChartArea.Height));
         textBox_ChartWidth.Text     = Convert.ToString(Math.Ceiling(chart.ChartArea.Width));
         textBox_PlotAreaHeight.Text = Convert.ToString(Math.Ceiling(chart.PlotArea.Height));
         textBox_PlotAreaWidth.Text  = Convert.ToString(Math.Ceiling(chart.PlotArea.Width));
     }
     catch (Exception ee)
     {
         throw new Exception(ee.ToString());
     }
 }
Exemplo n.º 5
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //Instantiate the Application object.
            Excel.Application ExcelApp = Application;
            //Add a Workbook.
            Excel.Workbook objBook = ExcelApp.Workbooks.Add(System.Reflection.Missing.Value);

            // Access a Vsto Worksheet
            Microsoft.Office.Interop.Excel.Worksheet nativeWorksheet = Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet;
            Microsoft.Office.Tools.Excel.Worksheet   sheet           = Globals.Factory.GetVstoObject(nativeWorksheet);

            //Add sample data for pie chart
            //Add headings in A1 and B1
            sheet.Cells[1, 1] = "Products";
            sheet.Cells[1, 2] = "Users";

            //Add data from A2 till B4
            sheet.Cells[2, 1] = "Aspose.Cells";
            sheet.Cells[2, 2] = 10000;
            sheet.Cells[3, 1] = "Aspose.Slides";
            sheet.Cells[3, 2] = 8000;
            sheet.Cells[4, 1] = "Aspose.Words";
            sheet.Cells[4, 2] = 12000;

            //Chart reference
            Microsoft.Office.Tools.Excel.Chart productsChart;

            //Add a Pie Chart
            productsChart           = sheet.Controls.AddChart(0, 105, 330, 200, "ProductUsers");
            productsChart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlPie;

            //Set chart title
            productsChart.HasTitle        = true;
            productsChart.ChartTitle.Text = "Users";

            //Gets the cells that define the data to be charted.
            Microsoft.Office.Interop.Excel.Range chartRange = sheet.get_Range("A2", "B4");
            productsChart.SetSourceData(chartRange, missing);

            //Access the Active workbook from Vsto sheet
            Microsoft.Office.Interop.Excel.Workbook workbook = sheet.Application.ActiveWorkbook;

            //Save the copy of workbook as OutputVsto.xlsx
            workbook.SaveCopyAs("OutputVsto.xlsx");
        }
Exemplo n.º 6
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //Access vsto application
            Microsoft.Office.Interop.Excel.Application app = Globals.ThisAddIn.Application;

            //Access workbook
            Microsoft.Office.Interop.Excel.Workbook workbook = app.ActiveWorkbook;

            //Access worksheet
            Microsoft.Office.Interop.Excel.Worksheet m_sheet = workbook.Worksheets[1];

            //Access vsto worksheet
            Microsoft.Office.Tools.Excel.Worksheet worksheet = Globals.Factory.GetVstoObject(m_sheet);

            //Access cells A1, A2, A3 , A4
            Microsoft.Office.Interop.Excel.Range cellA1 = worksheet.Range["A1"];
            Microsoft.Office.Interop.Excel.Range cellA2 = worksheet.Range["A2"];
            Microsoft.Office.Interop.Excel.Range cellA3 = worksheet.Range["A3"];
            Microsoft.Office.Interop.Excel.Range cellA4 = worksheet.Range["A4"];

            //Set integer values in cells A1, A2 and A3
            cellA1.Value = 10;
            cellA2.Value = 20;
            cellA3.Value = 30;

            //Add formula in cell A4
            cellA4.Formula = "=Sum(A1:A3)";

            //Set the font bold in cell A4
            cellA4.Font.Bold = true;

            //Set the background color to Yellow in cell A4
            cellA4.Interior.Color = Excel.XlRgbColor.rgbYellow;

            //Save the workbook
            workbook.SaveAs("OutputVsto.xlsx");

            //Quit the application
            app.Quit();
        }
Exemplo n.º 7
0
        //<Snippet5>
        void ThisWorkbook_SheetActivate1(object Sh)
        {
            Microsoft.Office.Tools.Excel.Worksheet vstoWorksheet = null;

            if (Type.ReferenceEquals(Globals.Sheet1.InnerObject, Sh))
            {
                vstoWorksheet = Globals.Sheet1.Base;
            }
            else if (Type.ReferenceEquals(Globals.Sheet2.InnerObject, Sh))
            {
                vstoWorksheet = Globals.Sheet2.Base;
            }
            else if (Type.ReferenceEquals(Globals.Sheet3.InnerObject, Sh))
            {
                vstoWorksheet = Globals.Sheet3.Base;
            }

            if (vstoWorksheet != null)
            {
                // Do something with the VSTO worksheet here.
            }
        }
Exemplo n.º 8
0
        public ColumnFrequency()
        {
            InitializeComponent();
            //hScrollBar_Parameter1.Value = 2;
            //Graphics Graphic = new Graphics();
            Bandwidth = double.Parse(textBox_Bandwidth.Text);
            //if (Form_Parater.flag == 0) return;
            //int rows = 1;
            //int cols = 1;
            //string[,] str = new string[1, 1];
            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);

            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            Max_Value = Double.MinValue;
            Min_Value = Double.MaxValue;
            for (int i = 1; i < rows; i++)
            {
                if (double.Parse(str[i, 0]) > Max_Value)
                {
                    Max_Value = double.Parse(str[i, 0]);
                }
                if (double.Parse(str[i, 0]) < Min_Value)
                {
                    Min_Value = double.Parse(str[i, 0]);
                }
            }

            int Nrows = Convert.ToInt32((Max_Value - Min_Value) / Bandwidth + 2);

            double[,] data = new double[Nrows, 1];
            int idx = 0;

            for (int i = 1; i < rows; i++)
            {
                idx          = Convert.ToInt32((double.Parse(str[i, 0]) - Min_Value) / Bandwidth);
                data[idx, 0] = data[idx, 0] + 1;
            }
            data[Nrows - 2, 0] = data[Nrows - 2, 0] + data[Nrows - 1, 0];


            double[,] x     = new double[Nrows - 1, 1];
            string[,] label = new string[Nrows - 1, 1];
            for (int i = 0; i < Nrows - 1; i++)
            {
                label[i, 0] = "[" + Convert.ToString(Math.Floor((i * Bandwidth + Min_Value) * 100) / 100) + ","
                              + Convert.ToString(Math.Floor(((i + 1) * Bandwidth + Min_Value) * 100) / 100) + ")";
                //((Excel.Range)worksheet.Cells[start_row + 1 + i, start_col + cols + 1]).Value2 = label[i];
                //((Excel.Range)worksheet.Cells[start_row + 1 + i, start_col + cols + 3]).Value2 = data[i];
                x[i, 0] = i * Bandwidth + Min_Value;
            }

            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 1]).Value2 = "X bandwidth";
            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 2]).Value2 = "X axis";
            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 3]).Value2 = "Y axis";

            Excel.Range c1    = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 1];
            Excel.Range c2    = (Excel.Range)worksheet.Cells[start_row + Nrows - 1, start_col + cols + 1];
            Excel.Range range = worksheet.get_Range(c1, c2);
            range.Value = label;

            c1          = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 2];
            c2          = (Excel.Range)worksheet.Cells[start_row + Nrows - 1, start_col + cols + 2];
            range       = worksheet.get_Range(c1, c2);
            range.Value = x;

            c1          = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 3];
            c2          = (Excel.Range)worksheet.Cells[start_row + Nrows, start_col + cols + 3];
            range       = worksheet.get_Range(c1, c2);
            range.Value = data;
            ((Excel.Range)worksheet.Cells[start_row + Nrows, start_col + cols + 3]).Value2 = "";;

            string ChartOrder = "FrequencyColumn" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(300, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            c1 = (Excel.Range)worksheet.Cells[start_row, start_col + cols + 2];
            c2 = (Excel.Range)worksheet.Cells[start_row + Nrows - 1, start_col + cols + 3];
            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);
            chart.ChartType = Excel.XlChartType.xlColumnClustered;

            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();

            if (series.Count == 2)
            {
                Excel.Series Sseries2 = series.Item(2);
                Sseries2.Delete();
            }

            Excel.Series Sseries = series.Item(1);
            c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 2];
            c2 = (Excel.Range)worksheet.Cells[start_row + Nrows - 1, start_col + cols + 2];
            Sseries.XValues = worksheet.get_Range(c1, c2);

            c1             = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 3];
            c2             = (Excel.Range)worksheet.Cells[start_row + Nrows - 1, start_col + cols + 3];
            Sseries.Values = worksheet.get_Range(c1, c2);


            Sseries.Format.Fill.Visible       = Office.MsoTriState.msoTrue;
            Sseries.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 88, 180, 13).ToArgb();
            Sseries.Format.Line.Visible       = Office.MsoTriState.msoTrue;
            Sseries.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 0, 0, 0).ToArgb();

            Excel.ChartGroup group = (Excel.ChartGroup)chart.ChartGroups(1);
            group.GapWidth = 0;


            chart.HasLegend = false;
            chart.HasTitle  = false;
            worksheet.Activate();
        }
Exemplo n.º 9
0
        public CurveLOESS()
        {
            InitializeComponent();

            //int rows = 1;
            //int cols = 1;
            //string[,] str = new string[1, 1];
            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);
            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            Y = new double[rows - 1];
            X = new double[rows - 1];
            int j;

            for (j = 1; j < rows; j++)
            {
                X[j - 1] = double.Parse(str[j, 0]);
                Y[j - 1] = double.Parse(str[j, 1]);
            }

            Span = long.Parse(textBox_Bandwidth.Text);
            double[] yLoess = new double[rows - 1];
            QLOESS(ref Y, ref X, ref yLoess, Span);

            double[,] data = new double[rows - 1, 1];
            for (j = 1; j < rows; j++)
            {
                data[j - 1, 0] = yLoess[j - 1];
            }

            ((Excel.Range)worksheet.Cells[start_row, start_col + cols]).Value2 = "Smooth Y";
            Excel.Range c1    = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols];
            Excel.Range c2    = (Excel.Range)worksheet.Cells[start_row + 1 + rows - 2, start_col + cols];
            Excel.Range range = worksheet.get_Range(c1, c2);
            range.Value = data;

            c1 = (Excel.Range)worksheet.Cells[start_row, start_col];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols];

            string ChartOrder = "CurveLOESS" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(250, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);
            chart.ChartType = Excel.XlChartType.xlXYScatter;

            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();

            Excel.Series Sseries2 = series.Item(2);
            Sseries2.Format.Line.Visible = Office.MsoTriState.msoFalse;
            Sseries2.Format.Fill.Solid();
            Sseries2.Format.Fill.Visible = Office.MsoTriState.msoCTrue;
            //Sseries2.Format.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb();
            //Sseries2.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255,229, 184,0).ToArgb();
            //Sseries2.Format.Fill.Transparency = 0.6F;

            Sseries2.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleCircle;
            Sseries2.MarkerSize  = 6;

            Excel.Series Sseries3 = series.Item(3);
            Sseries3.Format.Fill.Visible = Office.MsoTriState.msoFalse;
            Sseries3.Format.Line.Visible = Office.MsoTriState.msoTrue;
            Sseries3.MarkerStyle         = Excel.XlMarkerStyle.xlMarkerStyleNone;
            //Sseries3.Format.Line.ForeColor.RGB= System.Drawing.Color.FromArgb(255, 248, 118, 109).ToArgb();
            Sseries3.Format.Line.Weight = 1.25F;

            Excel.Series Sseries1 = series.Item(1);
            Sseries1.Delete();
        }
Exemplo n.º 10
0
        public ColumnColor()
        {
            InitializeComponent();

            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);
            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            Excel.Range c1 = (Excel.Range)worksheet.Cells[start_row, start_col];
            Excel.Range c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols - 2];

            string ChartOrder = "ColorColumn" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(250, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);
            chart.ChartType = Excel.XlChartType.xlColumnClustered;

            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();

            if (series.Count == 2)
            {
                Excel.Series Sseries2 = series.Item(2);
                Sseries2.Delete();
            }

            Excel.Series Sseries = series.Item(1);
            c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col];
            Sseries.XValues = worksheet.get_Range(c1, c2);

            c1             = (Excel.Range)worksheet.Cells[start_row + 1, start_col + 1];
            c2             = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + 1];
            Sseries.Values = worksheet.get_Range(c1, c2);

            Excel.Point point;
            int[]       HSV0 = new int[3];

            RGB0 = System.Drawing.Color.FromArgb(255, 96, 157, 202);
            System.Drawing.Color RGB1 = System.Drawing.Color.FromArgb(255, 96, 157, 202);

            Graphic.RGB2HSV(RGB0, ref HSV0);

            Max_Value = Double.MinValue;
            Min_Value = Double.MaxValue;
            for (int i = 1; i < rows; i++)
            {
                if (double.Parse(str[i, 2]) > Max_Value)
                {
                    Max_Value = double.Parse(str[i, 1]);
                }
                if (double.Parse(str[i, 2]) < Min_Value)
                {
                    Min_Value = double.Parse(str[i, 1]);
                }
            }

            int[] HSV = new int[3];
            HSV0.CopyTo(HSV, 0);
            double ratio;

            Hrange = double.Parse(textBox_Bandwidth.Text);
            for (int i = 1; i < rows; i++)
            {
                point = (Excel.Point)Sseries.Points(i);
                point.Format.Fill.Solid();
                point.Format.Fill.Visible       = Office.MsoTriState.msoCTrue;
                point.Format.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 229, 229, 229).ToArgb();

                ratio  = (double.Parse(str[i, 2]) - Min_Value) / (Max_Value - Min_Value);
                HSV[2] = HSV0[2] + Convert.ToInt32(Hrange * (ratio - 0.5));
                Graphic.HSV2RGB(ref RGB1, HSV);
                point.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, RGB1.B, RGB1.G, RGB1.R).ToArgb();
                point.Format.Fill.Transparency  = 0.0F;
            }
            //Sseries.MarkerBackgroundColor = System.Drawing.Color.FromArgb(255, 77, 175, 74).ToArgb();
            //Sseries.MarkerForegroundColor = System.Drawing.Color.FromArgb(255, 77, 175, 74).ToArgb();
            Sseries.Format.Line.Visible       = Office.MsoTriState.msoCTrue;
            Sseries.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            Sseries.Format.Line.Weight        = 0.75F;

            Excel.ChartGroup group = (Excel.ChartGroup)chart.ChartGroups(1);
            group.GapWidth = 0;

            chart.HasLegend = false;
            chart.HasTitle  = false;
            //chart.ChartTitle.Delete();
            worksheet.Activate();
        }
Exemplo n.º 11
0
        public BubbleRelationShip()
        {
            InitializeComponent();

            ratio = double.Parse(textBox_Bandwidth.Text);;

            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);

            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            int i, j;

            for (j = 1; j < cols; j++)
            {
                ((Excel.Range)worksheet.Cells[start_row + rows + 1, start_col + j]).Value2 = str[0, j];
            }

            for (j = 1; j < rows; j++)
            {
                ((Excel.Range)worksheet.Cells[start_row + rows + 1 + j, start_col]).Value2 = str[j, 0];
            }


            for (i = 1; i < rows; i++)
            {
                for (j = 1; j < cols; j++)
                {
                    ((Excel.Range)worksheet.Cells[start_row + rows + 1 + i, start_col + j]).Value2 = i;// str[i, 0];
                }
            }

            ((Excel.Range)worksheet.Cells[start_row + rows + 1 + rows, start_col]).Value2 = "Assistant1";
            for (j = 1; j < rows; j++)
            {
                ((Excel.Range)worksheet.Cells[start_row + rows + 1 + rows, start_col + j]).Value2 = 0;
            }

            ((Excel.Range)worksheet.Cells[start_row + rows + 1 + rows + 1, start_col]).Value2 = "Assistant2";
            for (j = 1; j < rows; j++)
            {
                ((Excel.Range)worksheet.Cells[start_row + rows + 1 + rows + 1, start_col + j]).Value2 = j;
            }


            Excel.Range c1 = (Excel.Range)worksheet.Cells[start_row + rows + 1, start_col];
            Excel.Range c2 = (Excel.Range)worksheet.Cells[start_row + rows + 1 + rows + 1, start_col + rows - 1];

            string ChartOrder = "BubbleRelationShip" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(250, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlRows);
            chart.ChartType = Excel.XlChartType.xlXYScatter;

            //double ratio = 21;
            //double Max_size = 0;
            Max_size = Double.MinValue;
            Min_size = Double.MaxValue;
            for (i = 1; i < rows; i++)
            {
                for (j = 1; j < cols; j++)
                {
                    if (double.Parse(str[i, j]) > Max_size)
                    {
                        Max_size = double.Parse(str[i, j]);
                    }
                    if (double.Parse(str[i, j]) < Min_size)
                    {
                        Min_size = double.Parse(str[i, j]);
                    }
                }
            }

            Max_size = Math.Sqrt(Max_size);
            Min_size = Math.Sqrt(Min_size);

            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();

            Excel.Point  point;
            Excel.Series Sseries;
            int          SquareSize;

            RGB0 = System.Drawing.Color.FromArgb(255, 248, 118, 109);
            for (i = 1; i < rows; i++)
            {
                Sseries = series.Item(i);
                Sseries.Format.Line.Visible = Office.MsoTriState.msoFalse;

                //if (comboBox_FourierMethod.SelectedItem.Equals("Circle"))
                //{
                Sseries.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleCircle;
                //}
                //else if (comboBox_FourierMethod.SelectedItem.Equals("Square"))
                //{
                //    Sseries.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleSquare;
                //}

                Sseries.MarkerBackgroundColor = System.Drawing.Color.FromArgb(255, RGB0.B, RGB0.G, RGB0.R).ToArgb();
                Sseries.MarkerForegroundColor = System.Drawing.Color.FromArgb(255, RGB0.B, RGB0.G, RGB0.R).ToArgb();

                Sseries.Format.Fill.Solid();
                Sseries.Format.Fill.Visible       = Office.MsoTriState.msoCTrue;
                Sseries.Format.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb();
                Sseries.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, RGB0.B, RGB0.G, RGB0.R).ToArgb();
                Sseries.Format.Fill.Transparency  = 0.2F;

                //Sseries.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleCircle;

                for (j = 1; j < cols; j++)
                {
                    point = (Excel.Point)Sseries.Points(j);
                    //SquareSize = (int)((double.Parse(str[i, j])-Min_size) / (Max_size-Min_size) * ratio) + 2;
                    SquareSize = (int)((Math.Sqrt(double.Parse(str[i, j]) * ratio) / Max_size) * Min_MarkerSize + 2);   // - Min_size) / (Max_size - Min_size) * ratio) + 2;
                    //SquareSize = (int)((double.Parse(str[i, j]) / (Max_size * Max_size) * ratio) + 2);// - Min_size) / (Max_size - Min_size) * ratio) + 2;

                    if (SquareSize > 72)
                    {
                        SquareSize = 72;
                    }

                    point.MarkerSize = SquareSize;
                }
            }


            Excel.Series SseriesX = series.Item(rows);
            for (j = 1; j < cols; j++)
            {
                point = (Excel.Point)SseriesX.Points(j);
                point.HasDataLabel       = true;
                point.DataLabel.Text     = str[0, j];
                point.DataLabel.Position = Excel.XlDataLabelPosition.xlLabelPositionBelow;

                point.DataLabel.Format.TextFrame2.TextRange.Characters.Font.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
                point.DataLabel.Format.TextFrame2.TextRange.Font.NameComplexScript             = "Times New Roman";
                point.DataLabel.Format.TextFrame2.TextRange.Font.NameFarEast = "Times New Roman";
                point.DataLabel.Format.TextFrame2.TextRange.Font.Name        = "Times New Roman";
                point.DataLabel.Format.TextFrame2.TextRange.Font.Size        = 10;
                point.DataLabel.Format.TextFrame2.TextRange.Font.Bold        = Office.MsoTriState.msoFalse;
            }
            SseriesX.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleNone;

            Excel.Series SseriesY = series.Item(rows + 1);
            c1 = (Excel.Range)worksheet.Cells[start_row + rows + 1 + rows, start_col + +1];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows + 1 + rows, start_col + rows - 1];
            SseriesY.XValues = worksheet.get_Range(c1, c2);

            c1 = (Excel.Range)worksheet.Cells[start_row + rows + 1 + rows + 1, start_col + 1];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows + 1 + rows + 1, start_col + rows - 1];
            SseriesY.Values      = worksheet.get_Range(c1, c2);
            SseriesY.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleNone;

            for (j = 1; j < rows; j++)
            {
                point = (Excel.Point)SseriesY.Points(j);
                point.HasDataLabel       = true;
                point.DataLabel.Text     = str[j, 0];
                point.DataLabel.Position = Excel.XlDataLabelPosition.xlLabelPositionLeft;

                point.DataLabel.Format.TextFrame2.TextRange.Characters.Font.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
                point.DataLabel.Format.TextFrame2.TextRange.Font.NameComplexScript             = "Times New Roman";
                point.DataLabel.Format.TextFrame2.TextRange.Font.NameFarEast = "Times New Roman";
                point.DataLabel.Format.TextFrame2.TextRange.Font.Name        = "Times New Roman";
                point.DataLabel.Format.TextFrame2.TextRange.Font.Size        = 10;
                point.DataLabel.Format.TextFrame2.TextRange.Font.Bold        = Office.MsoTriState.msoFalse;
            }
            //***************************************************** Style**********************************************
            chart.PlotArea.Format.Fill.Visible       = Office.MsoTriState.msoCTrue;
            chart.PlotArea.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(229, 229, 229).ToArgb();
            chart.PlotArea.Format.Fill.Transparency  = 0;

            chart.PlotArea.Format.Line.Visible = Office.MsoTriState.msoFalse;

            // ChartArea Line
            chart.ChartArea.Format.Line.Visible = Office.MsoTriState.msoFalse;

            //chart.ChartArea.Height = 340.157480315;
            //chart.ChartArea.Width = 380.5039370079;

            // Chart Type: XYScatter
            // Add GridLinesMinorMajor
            chart.SetElement(Office.MsoChartElementType.msoElementPrimaryValueGridLinesMinorMajor);
            chart.SetElement(Office.MsoChartElementType.msoElementPrimaryCategoryGridLinesMinorMajor);
            chart.SetElement(Office.MsoChartElementType.msoElementPrimaryValueAxisTitleAdjacentToAxis);
            chart.SetElement(Office.MsoChartElementType.msoElementPrimaryCategoryAxisTitleAdjacentToAxis);

            //y axis
            Excel.Axis axis = (Excel.Axis)chart.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary);

            axis.MinorUnit = 1;
            axis.MajorUnit = 1;

            axis.MajorGridlines.Format.Line.Visible       = Office.MsoTriState.msoCTrue;
            axis.MajorGridlines.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255).ToArgb();
            axis.MajorGridlines.Format.Line.Weight        = (float)0.25;
            axis.MajorGridlines.Format.Line.DashStyle     = Office.MsoLineDashStyle.msoLineSolid;

            axis.MinorGridlines.Format.Line.Visible = Office.MsoTriState.msoFalse;
            //axis.MinorGridlines.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(242, 242, 242).ToArgb();
            //axis.MinorGridlines.Format.Line.Weight = (float)0.25;
            //axis.MinorGridlines.Format.Line.DashStyle = Office.MsoLineDashStyle.msoLineSolid;

            axis.Format.Line.Visible = Office.MsoTriState.msoFalse;
            axis.HasTitle            = true;
            axis.AxisTitle.Text      = "y axis";

            axis.HasDisplayUnitLabel = false;
            //axis.TickLabels.Font.Color = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            //axis.TickLabels.Font.Name = "Times New Roman";
            //axis.TickLabels.Font.Size = 10;
            axis.TickLabelPosition = Excel.XlTickLabelPosition.xlTickLabelPositionNone;

            //axis.AxisTitle.Format.TextFrame2.TextRange.Characters.Font.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.NameComplexScript = "Times New Roman";
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.NameFarEast = "Times New Roman";
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.Name = "Times New Roman";
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.Size = 10;
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.Bold = Office.MsoTriState.msoFalse;


            //x axis
            axis = (Excel.Axis)chart.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary);

            axis.MaximumScale = cols;
            axis.MinimumScale = 0;
            //axis.AxisBetweenCategories = false;
            axis.MinorUnit = 1;
            axis.MajorUnit = 1;

            axis.MinorGridlines.Format.Line.Visible = Office.MsoTriState.msoFalse;
            //axis.MajorGridlines.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255).ToArgb();
            //axis.MajorGridlines.Format.Line.Weight = (float)1.25;
            //axis.MajorGridlines.Format.Line.DashStyle = Microsoft.Office.Core.MsoLineDashStyle.msoLineSolid;

            axis.MajorGridlines.Format.Line.Visible       = Office.MsoTriState.msoCTrue;
            axis.MajorGridlines.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255).ToArgb();
            axis.MajorGridlines.Format.Line.Weight        = (float)0.25;
            axis.MajorGridlines.Format.Line.DashStyle     = Office.MsoLineDashStyle.msoLineSolid;

            axis.Format.Line.Visible = Office.MsoTriState.msoFalse;

            axis.HasTitle       = true;
            axis.AxisTitle.Text = "x axis";


            //axis.TickLabels.Font.Color = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            //axis.TickLabels.Font.Name = "Times New Roman";
            //axis.TickLabels.Font.Size = 10;
            axis.TickLabelPosition = Excel.XlTickLabelPosition.xlTickLabelPositionNone;

            //axis.AxisTitle.Format.TextFrame2.TextRange.Characters.Font.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.NameComplexScript = "Times New Roman";
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.NameFarEast = "Times New Roman";
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.Name = "Times New Roman";
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.Size = 10;
            //axis.AxisTitle.Format.TextFrame2.TextRange.Font.Bold = Office.MsoTriState.msoFalse;

            chart.HasLegend = false;
            chart.HasTitle  = false;
            //chart.ChartTitle.Delete();
            chart.Refresh();
            //worksheet.Activate();
        }
Exemplo n.º 12
0
        /*'***************************************************************
         * 'FFT0 数组下标以0开始  FFT1 数组下标以1开始
         * 'AR() 数据实部     AI() 数据虚部
         * 'N 数据点数,为2的整数次幂
         * 'NI 变换方向 1为正变换,-1为反变换
         * '*************************************************************** */

        private void Form_Fourier_Load(object sender, EventArgs e)
        {
            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);
            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            //double[] FFTProjectionArray = new double[rows - 1];
            double[,] NewFFTProjectionArray = new double[rows - 1, 1];  //store the projection curve of FFT

            double TwoTime   = 0;
            double TwoResult = rows - 1;

            while (TwoResult > 1)
            {
                TwoResult = TwoResult / 2;
                TwoTime   = TwoTime + 1;
            }
            Nrows = Convert.ToInt32(Math.Pow(2.0, TwoTime));
            double[] AR = new double[Nrows];
            //double[] NewAR = new double[Nrows];

            for (int j = 1; j < rows; j++)
            {
                //FFTProjectionArray[j - 1] = double.Parse(str[j, 1]);
                AR[j - 1] = double.Parse(str[j, 1]);
            }

            double[] AI = new double[Nrows];
            FFT0(ref AR, ref AI, Nrows, 1);

            Span = double.Parse(textBox_Bandwidth.Text);

            comboBox_FourierMethod.Text = "Low Pass";

            for (int j = Convert.ToInt32(rows * Span) + 1; j < Nrows; j++)
            {
                AR[j] = 0;
                AI[j] = 0;
            }

            FFT0(ref AR, ref AI, Nrows, -1);
            for (int j = 1; j < rows; j++)
            {
                NewFFTProjectionArray[j - 1, 0] = AR[j - 1];
            }

            ((Excel.Range)worksheet.Cells[start_row, start_col + cols]).Value2 = "Smooth Y";
            Excel.Range c1    = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols];
            Excel.Range c2    = (Excel.Range)worksheet.Cells[start_row + 1 + rows - 2, start_col + cols];
            Excel.Range range = worksheet.get_Range(c1, c2);
            range.Value = NewFFTProjectionArray;

            //*******************************************************************************************8
            c1 = (Excel.Range)worksheet.Cells[start_row, start_col];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols];

            string ChartOrder = "CurveFourier" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(250, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);
            chart.ChartType = Excel.XlChartType.xlXYScatter;

            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();

            Excel.Series Sseries2 = series.Item(2);
            Sseries2.Format.Line.Visible = Office.MsoTriState.msoFalse;
            Sseries2.Format.Fill.Solid();
            Sseries2.Format.Fill.Visible = Office.MsoTriState.msoCTrue;
            //Sseries2.Format.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb();
            //Sseries2.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255,229, 184,0).ToArgb();
            //Sseries2.Format.Fill.Transparency = 0.6F;

            Sseries2.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleCircle;
            Sseries2.MarkerSize  = 6;

            Excel.Series Sseries3 = series.Item(3);
            Sseries3.Format.Fill.Visible = Office.MsoTriState.msoFalse;
            Sseries3.Format.Line.Visible = Office.MsoTriState.msoTrue;
            Sseries3.MarkerStyle         = Excel.XlMarkerStyle.xlMarkerStyleNone;
            //Sseries3.Format.Line.ForeColor.RGB= System.Drawing.Color.FromArgb(255, 248, 118, 109).ToArgb();
            Sseries3.Format.Line.Weight = 1.25F;

            Excel.Series Sseries1 = series.Item(1);
            Sseries1.Delete();
        }
Exemplo n.º 13
0
        public AreaThreshold()
        {
            InitializeComponent();

            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);

            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            double Max_Value = Double.MinValue;
            double Min_Value = Double.MaxValue;

            for (int i = 1; i < rows; i++)
            {
                if (double.Parse(str[i, 0]) > Max_Value)
                {
                    Max_Value = double.Parse(str[i, 1]);
                }
                if (double.Parse(str[i, 0]) < Min_Value)
                {
                    Min_Value = double.Parse(str[i, 1]);
                }
            }
            ThreholdArea           = (Max_Value + Min_Value) / 2;
            textBox_Bandwidth.Text = Convert.ToString(ThreholdArea);
            textBox_Bandwidth.Refresh();


            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 1]).Value2 = "Assiatant";

            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 2]).Value2 = "<=Threshold";
            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 3]).Value2 = ">Threshold";

            double[,] data = new double[rows - 1, 3];
            for (int i = 1; i < rows; i++)
            {
                if (double.Parse(str[i, 1]) > ThreholdArea)
                {
                    data[i - 1, 2] = double.Parse(str[i, 1]) - ThreholdArea;
                    data[i - 1, 1] = 0;
                    data[i - 1, 0] = ThreholdArea - data[i - 1, 1];
                }
                else
                {
                    data[i - 1, 2] = 0;
                    data[i - 1, 1] = ThreholdArea - double.Parse(str[i, 1]);
                    data[i - 1, 0] = ThreholdArea - data[i - 1, 1];
                }
            }

            //double Max_data = Double.MinValue;
            //double Min_data = Double.MaxValue;
            //for (int i = 1; i < rows; i++)
            //{
            //    if (data[i - 1, 0] > Max_data) Max_data = data[i - 1, 0];
            //    if (data[i - 1, 1] < Min_data) Min_data = data[i - 1, 1];
            //}

            Excel.Range c1    = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 1];
            Excel.Range c2    = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols + 3];
            Excel.Range range = worksheet.get_Range(c1, c2);
            range.Value = data;

            string ChartOrder = "AreaThreshold" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(300, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            c1 = (Excel.Range)worksheet.Cells[start_row, start_col + cols + 1];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols + 3];
            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);
            chart.ChartType = Excel.XlChartType.xlAreaStacked;

            //*****************************************Primary Axis********************************************
            Excel.SeriesCollection series   = (Excel.SeriesCollection)chart.SeriesCollection();
            Excel.Series           Sseries1 = series.Item(1);
            c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col];
            Sseries1.XValues = worksheet.get_Range(c1, c2);

            //c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 1];
            //c2 = (Excel.Range)worksheet.Cells[start_row + rows-1, start_col + cols + 1];
            //Sseries1.Values = worksheet.get_Range(c1, c2);

            //c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col];
            //c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col];
            //Sseries2.XValues = worksheet.get_Range(c1, c2);

            //c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 2];
            //c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols + 2];
            //Sseries2.Values = worksheet.get_Range(c1, c2);


            ((Excel.Range)worksheet.Cells[start_row, start_col + cols]).Value2     = "Threshold";
            ((Excel.Range)worksheet.Cells[start_row + 1, start_col + cols]).Value2 = ThreholdArea;


            //*****************************************Chart Style********************************************
            //Excel.Series Sseries1 = series.Item(1);
            Sseries1.Format.Fill.Visible = Office.MsoTriState.msoFalse;
            Sseries1.Format.Line.Visible = Office.MsoTriState.msoFalse;

            Excel.Series Sseries2 = series.Item(2);

            Sseries2.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 196, 191, 0).ToArgb();
            Sseries2.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 0, 0, 0).ToArgb();
            Sseries2.Format.Line.Weight        = 0.25F;


            Excel.Series Sseries3 = series.Item(3);
            Sseries3.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 109, 118, 248).ToArgb();
            Sseries3.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 0, 0, 0).ToArgb();
            Sseries3.Format.Line.Weight        = 0.25F;


            //************************************************************************************************
            chart.PlotArea.Format.Fill.Visible       = Office.MsoTriState.msoCTrue;
            chart.PlotArea.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(229, 229, 229).ToArgb();
            chart.PlotArea.Format.Fill.Transparency  = 0;

            chart.PlotArea.Format.Line.Visible = Office.MsoTriState.msoFalse;

            // Legend
            chart.SetElement(Office.MsoChartElementType.msoElementLegendRight);
            chart.Legend.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            chart.Legend.Format.TextFrame2.TextRange.Font.NameComplexScript  = "Times New Roman";
            chart.Legend.Format.TextFrame2.TextRange.Font.NameFarEast        = "Times New Roman";
            chart.Legend.Format.TextFrame2.TextRange.Font.Name = "Times New Roman";
            chart.Legend.Format.TextFrame2.TextRange.Font.Size = 10;

            // ChartArea Line
            chart.ChartArea.Format.Line.Visible = Office.MsoTriState.msoFalse;

            chart.ChartArea.Height = 340.157480315;
            chart.ChartArea.Width  = 380.5039370079;

            chart.SetElement(Office.MsoChartElementType.msoElementPrimaryValueGridLinesMinorMajor);
            chart.SetElement(Office.MsoChartElementType.msoElementPrimaryCategoryGridLinesMinorMajor);
            chart.SetElement(Office.MsoChartElementType.msoElementPrimaryValueAxisTitleAdjacentToAxis);
            chart.SetElement(Office.MsoChartElementType.msoElementPrimaryCategoryAxisTitleAdjacentToAxis);

            //y axis
            Excel.Axis axis = (Excel.Axis)chart.Axes(
                Excel.XlAxisType.xlValue,
                Excel.XlAxisGroup.xlPrimary);

            axis.MinorUnit = axis.MajorUnit / 2;
            axis.MajorGridlines.Format.Line.Visible       = Office.MsoTriState.msoCTrue;
            axis.MajorGridlines.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255).ToArgb();
            axis.MajorGridlines.Format.Line.Weight        = (float)1.25;
            axis.MajorGridlines.Format.Line.DashStyle     = Office.MsoLineDashStyle.msoLineSolid;

            axis.MinorGridlines.Format.Line.Visible       = Office.MsoTriState.msoCTrue;
            axis.MinorGridlines.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(242, 242, 242).ToArgb();
            axis.MinorGridlines.Format.Line.Weight        = (float)0.25;
            axis.MinorGridlines.Format.Line.DashStyle     = Office.MsoLineDashStyle.msoLineSolid;

            axis.Format.Line.Visible = Office.MsoTriState.msoFalse;
            axis.HasTitle            = true;
            axis.AxisTitle.Text      = "y axis";

            axis.TickLabels.Font.Color = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            axis.TickLabels.Font.Name  = "Times New Roman";
            axis.TickLabels.Font.Size  = 10;
            axis.TickLabelPosition     = Excel.XlTickLabelPosition.xlTickLabelPositionLow;

            axis.AxisTitle.Format.TextFrame2.TextRange.Characters.Font.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.NameComplexScript             = "Times New Roman";
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.NameFarEast = "Times New Roman";
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.Name        = "Times New Roman";
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.Size        = 10;
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.Bold        = Office.MsoTriState.msoFalse;


            //x axis
            axis = (Excel.Axis)chart.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary);
            axis.TickMarkSpacing = 3;

            axis.MajorGridlines.Format.Line.Visible       = Office.MsoTriState.msoCTrue;
            axis.MajorGridlines.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255).ToArgb();
            axis.MajorGridlines.Format.Line.Weight        = (float)1.25;
            axis.MajorGridlines.Format.Line.DashStyle     = Office.MsoLineDashStyle.msoLineSolid;

            axis.MinorGridlines.Format.Line.Visible       = Office.MsoTriState.msoCTrue;
            axis.MinorGridlines.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(242, 242, 242).ToArgb();
            axis.MinorGridlines.Format.Line.Weight        = (float)0.25;
            axis.MinorGridlines.Format.Line.DashStyle     = Office.MsoLineDashStyle.msoLineSolid;

            axis.Format.Line.Visible = Office.MsoTriState.msoFalse;

            axis.HasTitle       = true;
            axis.AxisTitle.Text = "x axis";

            axis.TickLabels.Font.Color = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            axis.TickLabels.Font.Name  = "Times New Roman";
            axis.TickLabels.Font.Size  = 10;
            axis.TickLabelPosition     = Excel.XlTickLabelPosition.xlTickLabelPositionLow;

            axis.AxisTitle.Format.TextFrame2.TextRange.Characters.Font.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(0, 0, 0).ToArgb();
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.NameComplexScript             = "Times New Roman";
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.NameFarEast = "Times New Roman";
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.Name        = "Times New Roman";
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.Size        = 10;
            axis.AxisTitle.Format.TextFrame2.TextRange.Font.Bold        = Office.MsoTriState.msoFalse;
            // Change plot area ForeColor

            chart.HasLegend = false;
            chart.HasTitle  = false;

            chart.Refresh();
            //worksheet.Activate();
            flag = 1;
        }
Exemplo n.º 14
0
        public Form_Color_Matrix()
        {
            InitializeComponent();
            height = int.Parse(textBox_height.Text);
            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);

            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            int width = (int)Math.Ceiling(Convert.ToDouble(rows) / Convert.ToDouble(height));

            int[,] data = new int[height, width];
            int[] temp = new int[width];
            // for (int i = 0; i < height; i++)
            // {
            //temp = new int[width];
            //  for (int j = 0; j < width; j++)
            //   {
            //      // temp[j] = 1;
            //       data[i, j] = 1;
            //       ((range)worksheet.Cells[start_row + rows + 1 + i , start_col + j ]).Value2 = 1;
            //   }
            //Sseries = series.NewSeries();
            //Sseries.Values = temp;

            // }

            range c1 = (range)worksheet.Cells[start_row + rows + 1, start_col];
            range c2 = (range)worksheet.Cells[start_row + rows + 1 + height - 1, start_col + width - 1];

            string ChartOrder = "chart" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(250, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            //chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);
            chart.ChartType = Excel.XlChartType.xlColumnStacked100;

            Excel.ChartGroup group = (Excel.ChartGroup)chart.ChartGroups(1);
            group.GapWidth = 0;

            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();
            Excel.Series           Sseries;

            Excel.Point point;
            int         RGB_B, RGB_G, RGB_R;

            for (int i = 0; i < height; i++)
            {
                temp = new int[width];
                for (int j = 0; j < width; j++)
                {
                    temp[j]    = 1;
                    data[i, j] = 1;
                }
                Sseries        = series.NewSeries();
                Sseries.Values = temp;
            }

            for (int i = 1; i <= height; i++)
            {
                Sseries = series.Item(i);
                for (int j = 1; j <= width; j++)
                {
                    {
                        point = (Excel.Point)Sseries.Points(j);
                        point.Format.Fill.Solid();
                        point.Format.Fill.Visible       = Office.MsoTriState.msoCTrue;
                        point.Format.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 229, 229, 229).ToArgb();

                        int index = (i - 1) * width + j;
                        if (index < rows)
                        {
                            RGB_B = Convert.ToInt32(double.Parse(str[index, cols - 1])); if (RGB_B < 0)
                            {
                                RGB_B = 0;
                            }
                            if (RGB_B > 255)
                            {
                                RGB_B = 255;
                            }
                            RGB_G = Convert.ToInt32(double.Parse(str[index, cols - 2])); if (RGB_G < 0)
                            {
                                RGB_G = 0;
                            }
                            if (RGB_G > 255)
                            {
                                RGB_G = 255;
                            }
                            RGB_R = Convert.ToInt32(double.Parse(str[index, cols - 3])); if (RGB_R < 0)
                            {
                                RGB_R = 0;
                            }
                            if (RGB_R > 255)
                            {
                                RGB_R = 255;
                            }
                            point.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, RGB_B, RGB_G, RGB_R).ToArgb();
                            point.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 0, 0, 0).ToArgb();
                        }
                        else
                        {
                            point.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb();
                            point.Format.Line.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb();
                        }
                    }
                }
            }
        }
Exemplo n.º 15
0
        public DensityScatter()
        {
            InitializeComponent();

            //hScrollBar_Parameter1.Value = 2;
            //Graphics Graphic = new Graphics();
            Bandwidth = double.Parse(textBox_Bandwidth.Text);
            //if (Form_Parater.flag == 0) return;
            //int rows = 1;
            //int cols = 1;
            //string[,] str = new string[1, 1];
            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);

            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            int i;

            ((Excel.Range)worksheet.Cells[start_row, start_col + cols]).Value2     = "X-axis Value";
            ((Excel.Range)worksheet.Cells[start_row, start_col + cols + 1]).Value2 = "Y-axis Value";

            double Pdensity = Bandwidth * 100;
            double Maxtemp  = 1000;

            double[,] data = new double[rows, 2];
            for (i = 1; i < rows; i++)
            {
                data[i - 1, 0] = Math.Floor(double.Parse(str[i, 0]) * Maxtemp / Pdensity) * Pdensity / Maxtemp;
                data[i - 1, 1] = Math.Floor(double.Parse(str[i, 1]) * Maxtemp / Pdensity) * Pdensity / Maxtemp;
                //((Excel.Range)worksheet.Cells[start_row + i, start_col + cols]).Value2 = Math.Floor(double.Parse(str[i, 0]) * Maxtemp / Pdensity) * Pdensity / Maxtemp;
                //((Excel.Range)worksheet.Cells[start_row + i, start_col + cols + 1]).Value2 = Math.Floor(double.Parse(str[i, 1]) * Maxtemp / Pdensity) * Pdensity / Maxtemp;
            }

            Excel.Range c1    = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols];
            Excel.Range c2    = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols + cols - 1];
            Excel.Range range = worksheet.get_Range(c1, c2);
            range.Value = data;

            string ChartOrder = "DensityScatter" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(250, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            c1 = (Excel.Range)worksheet.Cells[start_row, start_col + cols];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols + cols - 1];
            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);
            chart.ChartType = Excel.XlChartType.xlXYScatter;

            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();

            if (series.Count == 2)
            {
                Excel.Series Sseries2 = series.Item(2);
                Sseries2.Delete();
            }

            Excel.Series Sseries = series.Item(1);
            c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols];
            Sseries.XValues = worksheet.get_Range(c1, c2);

            c1             = (Excel.Range)worksheet.Cells[start_row + 1, start_col + cols + 1];
            c2             = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + cols + 1];
            Sseries.Values = worksheet.get_Range(c1, c2);

            Sseries.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleCircle;
            //Sseries.Format.Line.Visible = Office.MsoTriState.msoFalse;

            Sseries.MarkerSize            = 5;
            Sseries.MarkerBackgroundColor = System.Drawing.Color.FromArgb(255, 109, 118, 248).ToArgb();
            Sseries.MarkerForegroundColor = System.Drawing.Color.FromArgb(255, 109, 118, 248).ToArgb();
            //Sseries.Format.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;

            Sseries.Format.Fill.Solid();
            Sseries.Format.Fill.Visible       = Office.MsoTriState.msoCTrue;
            Sseries.Format.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb();
            Sseries.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 109, 118, 248).ToArgb();
            Sseries.Format.Fill.Transparency  = 0.9F;

            worksheet.Activate();
        }
Exemplo n.º 16
0
        public BubbleSquare()
        {
            InitializeComponent();
            ratio = double.Parse(textBox_Bandwidth.Text);
            Graphic.RangeData(ref str, ref rows, ref cols);

            worksheet = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);

            Excel.Range activecells = Globals.ThisAddIn.Application.ActiveCell;
            start_col = activecells.Column;
            start_row = activecells.Row;

            Excel.Range c1 = (Excel.Range)worksheet.Cells[start_row, start_col];
            Excel.Range c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + 1];

            string ChartOrder = "SquareBubble" + Convert.ToString(Nchart);

            chart  = worksheet.Controls.AddChart(250, 50, 450, 400, ChartOrder);
            Nchart = Nchart + 1;

            chart.SetSourceData(worksheet.get_Range(c1, c2), Excel.XlRowCol.xlColumns);

            chart.ChartType = Excel.XlChartType.xlXYScatter;

            Excel.SeriesCollection series = (Excel.SeriesCollection)chart.SeriesCollection();

            if (series.Count == 2)
            {
                Excel.Series Sseries2 = series.Item(2);
                Sseries2.Delete();
            }

            Excel.Series Sseries = series.Item(1);
            c1 = (Excel.Range)worksheet.Cells[start_row + 1, start_col];
            c2 = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col];
            Sseries.XValues = worksheet.get_Range(c1, c2);

            c1             = (Excel.Range)worksheet.Cells[start_row + 1, start_col + 1];
            c2             = (Excel.Range)worksheet.Cells[start_row + rows - 1, start_col + 1];
            Sseries.Values = worksheet.get_Range(c1, c2);

            Excel.Point point;
            //double ratio = 42;
            int SquareSize;

            //((Excel.Range)worksheet.Cells[Graphic.start_row, Graphic.start_col + 3]).Value2 = "Square Size";

            Max_size = Double.MinValue;
            Min_size = Double.MaxValue;
            int i;

            for (i = 1; i < rows; i++)
            {
                if (double.Parse(str[i, 2]) > Max_size)
                {
                    Max_size = double.Parse(str[i, 2]);
                }
                if (double.Parse(str[i, 2]) < Min_size)
                {
                    Min_size = double.Parse(str[i, 2]);
                }
            }

            Max_size = Math.Sqrt(Max_size);
            Min_size = Math.Sqrt(Min_size);
            //int[,] PointSize = new int[Graphic.rows - 1, 1];
            for (i = 1; i < rows; i++)
            {
                point = (Excel.Point)Sseries.Points(i);
                //SquareSize = (int)((Math.Sqrt(double.Parse(str[i, 2])) - Min_size));// / (Max_size-Min_size) * ratio) + 2;
                SquareSize = (int)((Math.Sqrt(double.Parse(str[i, 2])) / Max_size * ratio) + 2);
                //PointSize[i - 1, 0] = SquareSize;
                //((Excel.Range)worksheet.Cells[Graphic.start_row + i, Graphic.start_col + 3]).Value2 = SquareSize;
                point.MarkerSize = SquareSize;
            }


            Sseries.MarkerBackgroundColor = System.Drawing.Color.FromArgb(255, 77, 175, 74).ToArgb();
            Sseries.MarkerForegroundColor = System.Drawing.Color.FromArgb(255, 77, 175, 74).ToArgb();

            Sseries.Format.Fill.Solid();
            Sseries.Format.Fill.Visible       = Office.MsoTriState.msoCTrue;
            Sseries.Format.Fill.BackColor.RGB = System.Drawing.Color.FromArgb(255, 229, 229, 229).ToArgb();
            Sseries.Format.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(255, 77, 175, 74).ToArgb();
            Sseries.Format.Fill.Transparency  = 0.3F;

            Sseries.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleSquare;

            //Rggplot2();
            chart.HasLegend = false;
            chart.HasTitle  = false;
            //chart.ChartTitle.Delete();
            worksheet.Activate();
        }