下面内容是关于C#导入导出数据到Excel的通用类的内容。
public class ExcelIO
{
private int _ReturnStatus;
private string _ReturnMessage;
public int ReturnStatus
{
get{return _ReturnStatus;}
}
public string ReturnMessage
{
get{return _ReturnMessage;}
}
public ExcelIO()
{
}
public DataSet ImportExcel(string fileName)
{
Excel.Application xlApp=new Excel.ApplicationClass();
if(xlApp==null)
{
_ReturnStatus = -1;
_ReturnMessage = "无法创建Excel对象,可能您的计算机未安装Excel";
return null;
}
Excel.Workbook workbook;
try
{
workbook = xlApp.Workbooks.Open(fileName,0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, 1, 0);
}
catch
{
_ReturnStatus = -1;
_ReturnMessage = "Excel文件处于打开状态,请保存关闭";
return nu