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
Printable View
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 :D
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:
You could read them with something like thisCode:Bob,19,92.5
Sally,20,96.3
Joe,20,44.5
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.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
}
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.
And, you have to replace the file in each case