jonahxuworld
2022-03-07 17:07
采纳率: 95.7%
浏览 35

C#Winform如何把我下面输出的list:result一键导出到Excel呢?

这个var result就是list
求指教!


        private void button1_Click(object sender, EventArgs e)
        {
            var dialog = new FolderBrowserDialog();
            dialog.Description = "请选择文件路径";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                var savePath = dialog.SelectedPath;

                textBox1.Text = savePath;
                var result = Directory
                    .GetFiles(savePath, "*.txt", SearchOption.AllDirectories)
                    .Select(x => $"{Path.GetFileName(x)}, 行数:{File.ReadAllLines(x).Length}")
                    .ToList();
                
                richTextBox1.Text = string.Join(Environment.NewLine, result);
            }
        }

1条回答 默认 最新

相关推荐 更多相似问题