我想使用mvc5将数据保存在Excel工作表中,但是每次它replace文件,而我想添加上一个

如何在Excel表格中追加数据? 我保存它,但它取代了文件。 我想添加,而不是删除以前的数据。

[HttpPost] public ActionResult excel(Student st) { Excel.Application app = new Excel.Application(); Excel.Workbook myworkbook = app.Workbooks.Add(System.Reflection.Missing.Value); // Excel.Worksheet mysheet = myworkbook.ActiveSheet ; ///////write header in excel mysheet.Cells[1, 1] = "ID"; mysheet.Cells[1, 2] = "Name"; mysheet.Cells[1, 3] = "Email"; mysheet.Cells[1, 4] = "Age"; mysheet.Cells[1, 5] = "PassWord"; mysheet.Cells[1, 6] = "Confirm"; int row = 2; //putting received data from create action in excel sheet. mysheet.Cells[row, 1] = st.ID; mysheet.Cells[row, 2] = st.Name; mysheet.Cells[row, 3] = st.E_Mail; mysheet.Cells[row, 4] = st.Age; mysheet.Cells[row, 5] = st.PassWord; mysheet.Cells[row, 6] = st.Confirm; // save the data myworkbook.SaveAs("f:\\myfirstexcelmvc.xls"); myworkbook.Close(); Marshal.ReleaseComObject(myworkbook); app.Quit(); Marshal.FinalReleaseComObject(app); }