Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Link office to visual studio c sharp

Status
Not open for further replies.

Ilia Gildin

Junior Member level 3
Joined
Sep 27, 2014
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
184
hello
I wrote the following code to read excel data
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel; 
namespace uu
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Excel.Application xlApp;
            Excel.Workbook xlWorkBook;
            Excel.Worksheet xlWorkSheet;
            Excel.Range range;
            object misValue = System.Reflection.Missing.Value;
            int i;
            string j;
            int r;
            int c;
            xlApp = new Excel.Application();
            xlWorkBook = xlApp.Workbooks.Open("d:\\tt.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
            range = xlWorkSheet.UsedRange;
            r = range.Rows.Count;
            c = range.Columns.Count;
            for (i = 1; i<r; i =i+1)
            {
                if ((xlWorkSheet.Cells[r, 1].Text.Equals(textBox1.Text)) && (xlWorkSheet.Cells[r, 6].Text.Equals(textBox2.Text)))
               {
                    textBox3.Text = xlWorkSheet.Cells[r, 4].Text;
                    textBox4.Text = xlWorkSheet.Cells[r, 7].Text;
                }
            }  

        }

   
        private void Form1_Load(object sender, EventArgs e)
        {
  
            
        }
    }
}
and as it gets to the loop it stuck. I did tests and it reads the my excel data table correctly
and it doesn't matter if I do == or .Equal when compare the strings.
please help
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top