-
March 20th, 2012, 06:51 AM
#1
how to open .csv file
hi ,this is jagadeesh kumar ,in my project i have to open existing .csv file using c# and how cani add another sheet to that file . please help me.
thank you in advance
-
March 20th, 2012, 08:38 AM
#2
Re: how to open .csv file
Originally Posted by jagadeeshv
hi ,this is jagadeesh kumar ,in my project i have to open existing .csv file using c# and how cani add another sheet to that file . please help me.
thank you in advance
Simple use the Excel classes by adding them to the project. Which one depends on what excel file it should create e.g. Excel 2003 or 2007
The open command can open the file and then save it as a separate xls or xlsx file. Then close Workbook and quit ecel application Thats all
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
March 20th, 2012, 10:45 PM
#3
Re: how to open .csv file
CSV stands for comma seperated values. A record is stored on each row with fields seperated by commas. So if you had a CSV file representing students with three fields - name, age, grade - then you could get a file that looks like:
Code:
Bob,19,92.5
Sally,20,96.3
Joe,20,44.5
You could read them with something like this
Code:
System.IO.StreamReader r = new StreamReader(path);
while( !r.EndOfStream )
{
string line = r.ReadLine(); //Read the line
string[] fields = line.Split(','); //Split the line into fields whenever a comma is encountered
//Parse fields into appropriate datatypes
string name = fields[0];
int age = Int32.Parse(fields[1]);
double grade = Double.Parse(fields[2]);
//Do something with these
}
Beware, some CSV files use quotes around fields. Usually this is done to allow commas to be stored in the fields. A slightly more complicated parsing routine would be needed.
Sheets are a property of excel (.xls or .xlsx files), not of CSV files. The closest you could come would be to write another CSV file.
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
-
March 20th, 2012, 11:34 PM
#4
Re: how to open .csv file
And, you have to replace the file in each case
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|