Example #1
0
        public void getColumnInt(ExcelEdit ed)
        {
            Excel.Worksheet worksheet = (Excel.Worksheet)ed.GetSheet("sheet1");  //get worksheet

            int rows    = worksheet.UsedRange.Rows.Count;                        //get count of rows  of worksheet
            int columns = worksheet.UsedRange.Columns.Count;                     //get count of columns of worksheet

            Console.WriteLine("which column");
            int column = Convert.ToInt16(Console.ReadLine());
            int m      = 0;

            // read datas by column
            for (int i = 2; i <= rows; i++)
            {
                int    temp;
                string a = (worksheet.Cells[i, column]).Text.ToString();
                temp = Convert.ToInt32(a);
                ColumnDB.Add(a);
                trainX1.Add(temp);
                m++;
            }

            //  Console.WriteLine("{0}", rows);

            Console.ReadLine();
        }
Example #2
0
        private void button2_Click(object sender, EventArgs e)         //get the value of training set
        {
            // Console.WriteLine("Running...");
            ExcelEdit ed = new ExcelEdit();

            ed.Open("E:\\C#代码\\knnprogram\\result1.xlsx");                      //open a excel file
            Excel.Worksheet worksheet = (Excel.Worksheet)ed.GetSheet("sheet1"); //choose the sheet
            ed.getTestnum(ed);                                                  //get training set data
            MessageBox.Show("ok!");
            temp = 1;
        }
Example #3
0
        public Form1()
        {
            InitializeComponent();
            button1.Enabled = false;
            ExcelEdit ed = new ExcelEdit();

            ed.Open("E:\\C#代码\\knnprogram\\result1.xlsx");                      //open a excel file
            Excel.Worksheet worksheet = (Excel.Worksheet)ed.GetSheet("sheet1"); //choose the sheet
            ed.getTestnum(ed);
            len             = worksheet.UsedRange.Rows.Count;
            trainX1         = ed.trainX1;
            trainX2         = ed.trainX2;
            trainX3         = ed.trainX3;
            trainX4         = ed.trainX4;
            trainX5         = ed.trainX5;
            trainY1         = ed.trainY1;
            trainY2         = ed.trainY2;
            trainY3         = ed.trainY3;
            button1.Enabled = true;
        }
Example #4
0
        public void getTestnum(ExcelEdit ed)                                    //获取测试集数据
        {
            Excel.Worksheet worksheet = (Excel.Worksheet)ed.GetSheet("sheet1"); //get worksheet

            int rows    = worksheet.UsedRange.Rows.Count;                       //get count of rows  of worksheet
            int columns = worksheet.UsedRange.Columns.Count;                    //get count of columns of worksheet



            //read by rows
            for (int i = 2; i <= rows; i++)    //read column 1 data
            {
                int    temp;
                string a = (worksheet.Cells[i, 1]).Text.ToString();
                temp = Convert.ToInt32(a);
                ColumnDB.Add(a);
                trainX1.Add(temp);
            }

            for (int i = 2; i <= rows; i++)    //column 2
            {
                int    temp;
                string a = (worksheet.Cells[i, 2]).Text.ToString();
                temp = Convert.ToInt32(a);
                ColumnDB.Add(a);
                trainX2.Add(temp);
            }

            for (int i = 2; i <= rows; i++)    //column 3
            {
                int    temp;
                string a = (worksheet.Cells[i, 3]).Text.ToString();
                temp = Convert.ToInt32(a);
                ColumnDB.Add(a);
                trainX3.Add(temp);
            }

            for (int i = 2; i <= rows; i++)    //column 4
            {
                double temp;
                string a = (worksheet.Cells[i, 4]).Text.ToString();
                temp = Convert.ToDouble(a);
                ColumnDB.Add(a);
                trainX4.Add(temp);
            }

            for (int i = 2; i <= rows; i++)    //column 5
            {
                double temp;
                string a = (worksheet.Cells[i, 5]).Text.ToString();
                temp = Convert.ToDouble(a);
                ColumnDB.Add(a);
                trainX5.Add(temp);
            }

            for (int i = 2; i <= rows; i++)    //column 6
            {
                double temp;
                string a = (worksheet.Cells[i, 6]).Text.ToString();
                trainY1.Add(Convert.ToDouble(a));
            }

            for (int i = 2; i <= rows; i++)    //column 7
            {
                double temp;
                string a = (worksheet.Cells[i, 7]).Text.ToString();
                trainY2.Add(Convert.ToDouble(a));
            }

            for (int i = 2; i <= rows; i++)    //column 8
            {
                double temp;
                string a = (worksheet.Cells[i, 8]).Text.ToString();
                trainY3.Add(Convert.ToDouble(a));
            }
        }