C#Excel Interop:打开和显示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.
如果您希望Excel解析分隔符,您需要使用 OpenText
方法,而不是打开
。详细信息: http://msdn.microsoft.com /en-us/library/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