C#操作Excel
try
{
Excel.ApplicationClass Myexcel=new Excel.ApplicationClass();
if(Myexcel==null)
{
MessageBox.Show( "EXCEL无法启动! ", "信息提示 ",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
Myexcel.Visible = false;
Myexcel.UserControl = false;
Excel.Workbooks Myworkbooks=Myexcel.Workbooks;
Excel.Workbook Myworkbook=Myworkbooks.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.Worksheet Myworksheet=(Excel.Worksheet)Myworkbook.Worksheets[1];
Myworkbook.Close(null,null,null);
Myexcel.Workbooks.Close();
Myexcel.Application.Quit();
Myexcel.Quit();
}
catch(Exception Err)
{
MessageBox.Show( "调用EXCEL程序时出现错误! "+Err.Message, "信息提示 ",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
请问一下,上面的代码中怎么取得单元格的值?
退出时总是弹出对话框提示是否保存?
open方法后面的参数都是什么意思 ?
小弟在此先谢过!!!!
------解决方案--------------------单元格取得
Excel.Range range = currentWorkSheet.get_Range(Myworksheet.Cells[1,1], Myworksheet.Cells[2,2]);
退出时总是弹出对话框提示不保存?
Myexcel.DisplayAlerts = false;
open方法后面的参数
可以不填,所以这里用Type.Missing来表示省略。
------解决方案--------------------单元格取得
Excel.Range range = Myworksheet.get_Range(Myworksheet.Cells[1,1], Myworksheet.Cells[2,2]);
上面更正。