views:

139

answers:

1

i have a function that return a results, here is the results:

3.98901669117011   vm

0.138912911874081   nvm

2.30800830234368  hg

1.13724811900026  ms

2.33557467785177   ls

90.0912392977601  none

I want the words to be in the top of the table, and the numbers in the rows, and in the sides some string, here is an example:

Table example

how can i create a table in c# and write to it what i wrote? tanks!

A: 

If you need to open the exported file in Excel, you could simply save a CSV file. The first line would have the column names the rest of the lines would be the data rows.

The following code will write a CSV file that can be opened in Excel. It will look just like your image.

// I've hard coded the file contents for simplicity. 
// You'll have to generate this in your code.
string csv = 
@", nvm, hg, ms, ls, none
fun1, 12, 22, 44, 5, 77
fun2, 2, 1, 77, 45, 23
fun3, 44, 11, 12, 22, 31";

File.WriteAllText("c:\test.csv", csv);
jrummell
i can create an xls file but how can i write to the right column\row?i have title in the top of the table and in the side, and in the middle the information..
I've updated my example to include the first 3 columns from your image (for brevity). Each line is a row and each comma separated value is a column value in that row. Hopefully that makes sense.
jrummell
it's not working!!i tried this:StreamWriter sw = new StreamWriter(@"C:\cc.csv",true); sw.Write("testing");but the file stays empty.
I would use File.WriteAllText("c:\test.txt", "testing content"). Its much simpler that dealing with StreamWriter (http://msdn.microsoft.com/en-us/library/ms143375.aspx).
jrummell
it works, but it writting to the same place, and i can't use a comma here to pass the next collumn.
If you're writing one line at a time, then you could use File.AppendAllText (http://msdn.microsoft.com/en-us/library/ms143356.aspx). It may be worth while to look over the other static File methods too: http://msdn.microsoft.com/en-us/library/system.io.file_methods.aspx
jrummell
i just want to write the parameters to the right square!how can i acces a square??
I'm assuming by square you mean table cell. I would not recommend trying to write once cell at a time. Just create one string with one row per line and then save that string to the file.
jrummell
and how can i do it?i need each parameter to be in the right cell.how the string need to lool like, and how can i write it to the file?
I updated my example to match your image exactly. Hope this helps.
jrummell
it works!tanks!!!