开发者

C# Excel Interop: Opening and Showing CSV file

开发者 https://www.devze.com 2023-02-04 13:48 出处:网络
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 exc

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.

here's my helper.

    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;
    }

any suggestions?

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


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

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


It is MUCH easier than that if all you want to do is open the file...

 Process proc = new Process();
 proc.StartInfo = new ProcessStartInfo("excel.exe", "output.csv");
 proc.Start();
0

精彩评论

暂无评论...
验证码 换一张
取 消