从控制台生成/ CSV开放

编程入门 行业动态 更新时间:2024-10-23 20:26:09
本文介绍了从控制台生成/ CSV开放 - 文件格式错误错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我写了使用一个控制台应用程序逗号分隔的文件,比使用过程中打开该文件。这是倾销查询结果导入Excel的一个快速和肮脏的方式。

I am writing out a comma separated file using a console app, and than using Process to open the file. It's a quick and dirty way of dumping results of a query into excel.

一会儿这个工作得很好,但最近我开始您试图打开'blah.csv的文件,是在一个不同的格式通过文件扩展名指定。

for a while this worked fine, but lately i started getting "The file you are trying to open 'blah.csv', is in a different format than specified by the file extension".

和比点击是后

Excel检测到blah.csv是SYLK文件中,但不能加载它。或者该文件有错误或它不是一个SYLK文件格式。单击确定以尝试不同的格式打开文件。

按确定,打开它,并显示正常。

Pressing OK opens it, and displays correctly.

我看到这个在网络世界与添加内容处置头了一些解决方案,但由于我使用过程中打开它,我可以不适用该修复。

I see some solutions for this in web world with adding content-disposition header, but since i am using a Process to open it, i can't apply that fix.

我的代码来打开文件:

ProcessStartInfo info = new ProcessStartInfo(); info.FileName = filePath; info.UseShellExecute = true; Process.Start(info);

如果我打开记事本+ +文件,并显示所有字符,它只是显示与CR LF正规CSV行结束。

if i open the file in Notepad++ and show all chars, it just shows as regular CSV with CR LF line endings.

经过一番调查后,它看起来像标题行触发错误。如果我简单的写标题前的空行,错误消失。标题是这样的:

after some investigation, it looks like the headings line is triggering the error. If i simply write a empty line before the headings, the error goes away. the headings look like this:

标题1,heading2,heading3 CRLF

heading1,heading2,heading3 CRLF

推荐答案

看看这里: support.microsoft/kb/323626

似乎有ID作为标题行的前两个字符是问题 - 从Excel在我看来,漂亮的怪异行为。

it seems having ID as the first two chars on the header row is the issue - pretty bizarre behaviour from Excel in my opinion.

更多推荐

从控制台生成/ CSV开放

本文发布于:2023-10-27 16:00:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533857.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制台   CSV

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!