Sign in to follow this  
Skibula

[.net] how to export my array to Excel file

Recommended Posts

hey all, my question for today is :-) ? how can i export my array into excel file lets say i got array of points so x,y arr[0] point (1,3) arr[1] point (2,4) (its just an exemple) how can i export this array into excel file i want to get something like that [IMG]http://i31.tinypic.com/2a81d87.jpg[/IMG] http://tinypic.com/r/2a81d87/3 the idea is that the user will change information on the array (stuff that i need to do) then i can export it to excel so i can use that excel file for more stuff im using C# on windows forms

Share this post


Link to post
Share on other sites
You have to write a csv file. CSV files are text files with a very simple structure. Each line represents one row and each column is separated with ','. Your file would look like

,x,y
arr[0],1,3
arr[1],2,4

Btw. your files has to end with '.csv'.

--
Ashaman

Share this post


Link to post
Share on other sites
A CSV file just has rows of data stored in lines, with a comma delimiting (between) each field.

using (var CsvWriter = new StreamWriter("filename.csv")) {
// Write the first line of the CSV file (this contains the column headers):
CsvWriter.WriteLine(",x,y");
// Write the data lines to the CSV file:
for (int i = 0; i < arr.Length; ++i) {
CsvWriter.WriteLine("arr[{0}],{1},{2}", i, arr[i].X, arr[i].Y);
}
}

Share this post


Link to post
Share on other sites
ok thanks alot i will try that

so i guess i use stream reader to read from csv file

how i can read array of points in that way

i mean

how i know when to stop to read?
when its the X and when its Y

so hard :-(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this