C# 在 Excel 中打开 csv 字符串而不保存字符串
我有一个 csv 格式的字符串,我希望只需在 Excel 中打开该字符串,而无需先保存文件。
这可能吗?我查看了 Interop,但找不到我需要的具体方法。
谢谢。
I have a string in csv format, that I wish to simply open in Excel, without first having to save the file.
Is this possible? I've had a look at Interop but I cannot find the specific method that I need.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您首先将 csv 字符串转换为二维数组,则可以将其传递给一系列单元格。
这段代码是我凭空写出来的,所以我希望没问题,但我想你已经明白了。
如果您想在 Excel 文件中包含标题,只需从 A2(而不是 A1)开始范围即可。
If you convert your csv-string to a 2-dimensional array first, you can pass it to a range of cells.
This code is written out of my mind, so I hope It's ok, but I think you get the picture.
If you like to include a header in your excel-file, just start the range from A2 instaed of A1.
是的,只需手动复制这些值即可。您可以在此处找到示例。
调整该示例以获得一个非常短的示例来帮助您入门(请注意,该示例并不完整,您需要阅读完整的示例以了解如何正确执行操作):
但假设它是 csv 中的一系列值字符串,只需对其执行
String.Split
,然后使用数组填充工作表中的Range
,只需查看文章中的示例以了解详细信息。Yes, just copy the values over manually. You can find a sample here.
Adapting that sample to get a very short sample to get you started (please note, this sample is not complete and you need to read the complete sample to see how to do things properly):
But assuming that it's a range of values in the csv string, just do a
String.Split
on it and then use the array to populate aRange
in the sheet, just check out the sample in the article for details.