Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Sheets sheets;
Microsoft.Office.Interop.Excel.Workbook workbook = null;
object oMissiong = System.Reflection.Missing.Value;
try
{
workbook = app.Workbooks.Open(strExcelFileName, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong);
sheets = workbook.Worksheets;
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);//读取第一张表
if (worksheet == null)
return;
//删除整行 第一种方法
//Microsoft.Office.Interop.Excel.Range range;
//range = worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, 26]);
//range.Delete(Microsoft.Office.Interop.Excel.XlDeleteShiftDirection.xlShiftUp);
////删除整行 第二种方法
Microsoft.Office.Interop.Excel.Range range = (Microsoft.Office.Interop.Excel.Range)worksheet.Rows[1, oMissiong];
range.Delete(Microsoft.Office.Interop.Excel.XlDirection.xlDown);
workbook.Save();
}
catch(Exception ex)
{
ClientClass.SetStatusBar("ModifyDtAllExcel 异常" + ex.ToString(), 0);
}
finally
{
//关闭Excel应用
if (workbook != null) workbook.Close(Type.Missing, Type.Missing, Type.Missing);
if (app.Workbooks != null) app.Workbooks.Close();
if (app != null) app.Quit();
sheets = null;
workbook = null;
app = null;
}
GC.Collect();