2012-04-17
展开全部
string excelName= ExcelFileUrl();//返回Excel的路径
string fileName = AppDomain.CurrentDomain.BaseDirectory.ToString() + excelName;//保存Excle的文件路径
object missing = Missing.Value;
Microsoft.Office.Interop.Excel.Application appExcel = null;//实例Excel类
try
{
appExcel = new Microsoft.Office.Interop.Excel.Application();
appExcel.DisplayAlerts = false;//DisplayAlerts 属性设置成 False,就不会出现这种警告。
Microsoft.Office.Interop.Excel.Workbook workbook = appExcel.Workbooks.Open(fileName,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);//打开Excel
//Microsoft.Office.Interop.Excel.Workbooks workbooks = appExcel.Workbooks;//
//Microsoft.Office.Interop.Excel.Workbook workbook = workbooks.Add(missing);//工作簿
Microsoft.Office.Interop.Excel.Sheets sheets = workbook.Worksheets;//实例表格
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets[1];//第一个表格
}
catch
{}
类的传值如传的是第一个表格类型是Microsoft.Office.Interop.Excel.Worksheet 的函数
string fileName = AppDomain.CurrentDomain.BaseDirectory.ToString() + excelName;//保存Excle的文件路径
object missing = Missing.Value;
Microsoft.Office.Interop.Excel.Application appExcel = null;//实例Excel类
try
{
appExcel = new Microsoft.Office.Interop.Excel.Application();
appExcel.DisplayAlerts = false;//DisplayAlerts 属性设置成 False,就不会出现这种警告。
Microsoft.Office.Interop.Excel.Workbook workbook = appExcel.Workbooks.Open(fileName,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);//打开Excel
//Microsoft.Office.Interop.Excel.Workbooks workbooks = appExcel.Workbooks;//
//Microsoft.Office.Interop.Excel.Workbook workbook = workbooks.Add(missing);//工作簿
Microsoft.Office.Interop.Excel.Sheets sheets = workbook.Worksheets;//实例表格
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets[1];//第一个表格
}
catch
{}
类的传值如传的是第一个表格类型是Microsoft.Office.Interop.Excel.Worksheet 的函数
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你是想怎么样?是吧Excel数据读取出来显示到DataGirlView之后存到数据库还是,还是直接把Excel拿到程序里面去?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询