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
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
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 it doesn't matter if I do == or .Equal when compare the strings.
please help