How to display in label

How to display the content inside the Excel into a Label

Page 1 of 1

1 Replies - 1229 Views - Last Post: 16 September 2009 - 12:02 AM Rate Topic: -----

#1 dunk_6  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 43
  • Joined: 03-August 09

How to display in label

Posted 15 September 2009 - 07:35 PM

Hi all,

I know it seem's easy, but i dont know why i cannot find any example or tutorials on how to display data from excel into a label or text box from internet.

This program will read from excel and display the content inside to a label and read to text file. I can manage to do write into text file only left on how to display into a label.

any references or solution might be useful adn very thankful...thanx all.

Here codes for the references:
//***create connection using axcel
			string sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
						Data Source=F:\\pass.xls;Extended Properties=
						""Excel 8.0;HDR=YES;""";

			OleDbConnection objConn = new OleDbConnection(sConnectionString);

			objConn.Open();

			OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$]", objConn);

			OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();

		   objAdapter1.SelectCommand = objCmdSelect;

			DataSet objDataset1 = new DataSet();
		   objAdapter1.Fill(objDataset1);

			//write into text file
			StreamWriter tw = File.AppendText("C:\\test.txt");
			OleDbDataReader reader = objCmdSelect.ExecuteReader();
			while (reader.Read())
			{
				tw.Write(reader["id"].ToString());
				tw.Write(", " + reader["pass"].ToString());			   
			}
			tw.WriteLine(DateTime.Now);
			tw.WriteLine("---------------------------------");
			tw.Close();
			reader.Close();
			objConn.Close(); 
		}


Is This A Good Question/Topic? 0
  • +

Replies To: How to display in label

#2 wyj_China  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 15-September 09

Re: How to display in label

Posted 16 September 2009 - 12:02 AM

Add using COM Microsoft excel library

read data from excel

Microsoft.Office.Interop.Excel.ApplicationClass MyExcel;
Microsoft.Office.Interop.Excel.Workbooks MyBooks;//表总数
Microsoft.Office.Interop.Excel.Workbook KCBBook;//表文件
Microsoft.Office.Interop.Excel.Worksheet KCBSheet;//表单
Microsoft.Office.Interop.Excel.Range KCBRange;//表单区域

MyExcel = new Microsoft.Office.Interop.Excel.ApplicationClass();
MyExcel.Visible = true;
if (MyExcel == null)
{
MessageBox.Show("EXCEL无法启动!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
MyBooks.Open("file path", MyValue, MyValue, MyValue, MyValue, MyValue, MyValue, MyValue, MyValue, MyValue, MyValue, MyValue, MyValue, MyValue, MyValue);
MyBooks = MyExcel.Workbooks;
KCBBook = MyBooks.get_Item(1);//得到打开的第一个库存表文件
KCBSheet = (Microsoft.Office.Interop.Excel.Worksheet)KCBBook.Worksheets[2];//得到文件的第2个表单
KCBRange = (Microsoft.Office.Interop.Excel.Range)KCBSheet.get_Range("A1","A1");

this.textBox.text=KCBRange.Value2.ToString();

This post has been edited by wyj_China: 16 September 2009 - 12:07 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1