C#如何打开一个Excel表并对其进行修改
答案:2 悬赏:60 手机版
解决时间 2021-03-28 06:22
- 提问者网友:川水往事
- 2021-03-27 16:33
C#如何打开一个Excel表并对其进行修改
最佳答案
- 五星知识达人网友:痴妹与他
- 2021-03-27 17:58
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 的函数
全部回答
- 1楼网友:迟山
- 2021-03-27 18:39
你是想怎么样?是吧Excel数据读取出来显示到DataGirlView之后存到数据库还是,还是直接把Excel拿到程序里面去?
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯