gpt4 book ai didi

c# - 如何使用 C# 在 excel/csv 中格式化标题

转载 作者:可可西里 更新时间:2023-11-01 08:13:47 27 4
gpt4 key购买 nike

我的代码会生成这样的excel文档

|id  | Name  | Address  | company_Name | Destination|
|----|-------|----------|--------------|------------|
|##1 | xxx | xxxx | xxx | xxxxx |

但是我想要这样...

-----------------------------------------------------
| Personal Information | Working INFO |
-----------------------------------------------------
|id | Name | Address | company_Name | Destination|
|----|-------|----------|--------------|------------|
|##1 | xxx | xxxx | xxx | xxxxx |
-----------------------------------------------------

我从 API 获取数据,然后使用 SaveFileDialog

保存它
SaveFileDialog dialog = new SaveFileDialog();
dialog.Title = "Save file as...";
dialog.Filter = "Text files (*.csv)|*.csv";
dialog.RestoreDirectory = true;

if (dialog.ShowDialog() == DialogResult.OK)
{
System.IO.StreamWriter writer = new System.IO.StreamWriter(dialog.FileName); //open the file for writing.
writer.Write(report); //write the current date to the file. change this with your date or something.
writer.Close(); //remember to close the file again.
writer.Dispose(); //remember to dispose it from the memory.

program.ShowInformationMessage("File Save successfully");
}

没有问题。

我想把标题做成类似内联的东西。

最佳答案

...
System.IO.StreamWriter writer = new System.IO.StreamWriter(dialog.FileName); //open the file for writing.
writer.Write("Personal Information" + delimiter + delimiter + "Working INFO" + delimiter);
writer.Write(report); //write the current date to the file. change this with your date or something.
...

Csv 格式不支持合并单元格,但您仍然可以像上面描述的那样排列标题行。只需将分隔符替换为您的单元格分隔符即可。

关于c# - 如何使用 C# 在 excel/csv 中格式化标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19312485/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com