C#中的Excel互操作:打开并显示CSV文件 [英] C# Excel Interop: Opening and Showing CSV file

查看:905
本文介绍了C#中的Excel互操作:打开并显示CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在写一个包装器对Excel互操作,我希望能够在Excel中打开一个CSV文件,并将其展示给用户。我已经得到了基础知识,但是当我设置为true可见和Excel显示出来,所有列都挤进第一,和分离逗号都出现了。

Hey I'm writing a wrapper for the excel interop, I want to be able to open a csv file in excel and show it to the user. I've got the basics down, but when i set visible to true and excel shows up, all columns are jammed into the first, and the separating commas are showing.

这里是我的帮手。

    public MyExcel(string filePath, bool readOnly)
    {
        _app = new Excel.Application();

        _workbooks = _app.Workbooks;

        _workbook = _workbooks.Open(_filepath, 0, _readOnly, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", !_readOnly, false, 0, true, true, true);
    }

    public void Show()
    {
        _app.Visible = true;
    }

有什么建议?

当我用打开文件双击Excel中正确地处理一切。

When i open the file by double clicking Excel processes everything properly.

推荐答案

您将需要使用 OpenText公司方法,而不是打开,如果您希望Excel解析定界符。详细说明: http://msdn.microsoft.com/en-us/库/ bb223513%28V = office.12%29.aspx

You will need to use the OpenText method, instead of Open, if you want Excel to parse for delimiters. Details: http://msdn.microsoft.com/en-us/library/bb223513%28v=office.12%29.aspx

在C#中的一个例子:的 http://msdn.microsoft.com/en-us/library/c9838808.aspx

An example in C#: http://msdn.microsoft.com/en-us/library/c9838808.aspx

这篇关于C#中的Excel互操作:打开并显示CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆