在 C# 中创建表并写入表

发布于 2024-08-22 14:08:41 字数 338 浏览 3 评论 0原文

我有一个返回结果的函数,这是结果:

3.98901669117011   vm

0.138912911874081   nvm

2.30800830234368  hg

1.13724811900026  ms

2.33557467785177   ls

90.0912392977601  none

我希望单词位于表格的顶部,数字位于行中,侧面是一些字符串,这是一个示例:

Table example

如何在 C# 中创建一个表并写入我编写的内容?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半暖夏伤 2024-08-29 14:08:41

如果您需要在 Excel 中打开导出的文件,只需保存 CSV 文件。第一行将包含列名称,其余行将是数据行。

以下代码将编写一个可以在 Excel 中打开的 CSV 文件。它看起来就像你的图片一样。

// 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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文