Send data from Excel to Notepad!

Send data from Excel to Notepad using a C# program.....

Page 1 of 1

0 Replies - 2116 Views - Last Post: 19 January 2010 - 02:27 AM Rate Topic: -----

#1 coldfire101  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-January 10

Send data from Excel to Notepad!

Posted 19 January 2010 - 02:27 AM

Hi,

I need to write a program to send data from a particular excel sheet in a workbook to a notepad. Say,I've an xl sheet with the following columns: "Name,Age,Salary" with values "john,24,1000" respectievely,Now I need a C# program to read the xl sheet and write the values onto the Notepad (in Tab separated format) as follows: John 24 1000.
I need to write all the columns in the xl sheet into the notepad as follows.

Before I ask any help,let me make it clear that I'm a beginner to this stuff,and while I have done some programs dealing with the likes of 'fibonnacci' & 'prime numbers',they were all part of the curriculum and I've learnt all of em by Rote methodology..... Please help me regarding the above program.I have tried to do it myself and here's what I have till now...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Excel;
using System.io;


namespace datt
{
	class Program
	{
		static void Main(string[] args)
		{
			DataSet ds = new DataSet;
			DataTable dt = new DataTable "table1";
			DataColumn dc_col1 = new DataColumn("trigger term")
			DataColumn dc_col2 = new DataColumn("news1")
			DataColumn dc_col3 = new DataColumn("news1url")
			DataColumn dc_col4 = new DataColumn("news2")
			DataColumn dc_col5 = new DataColumn("news2url")
			dt.Columns.add(dc_col1);
			dt.Columns.add(dc_col2);
			dt.Columns.add(dc_col3);
			dt.Columns.add(dc_col4);
			dt.Columns.add(dc_col5);
			while
			{
				dr.read()
				dr.next();

				DataRow newrow = dt.newrow;
				dt.rows.add(newrow);
			} 
			ds.tables.add(dt);

				FileStream f1 = new FileStream("C:\List_Answer_Production\AU_States_V1.xls",FileMode.Create);
				ds.WriteXml(f1);
				f1.close();
				byte b[] = File.ReadAllBytes("C:\List_Answer_Production\AU_States_V1.xls");
				FileStream f1 = new FileStream("C:\List_Answer_Production\Austates.txt",FileMode.Create);
				f2.WriteAllBytes(b);
				f2.close();

					

			
		}
	}
}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1