覆盖Excel文件夹中没有消息
我有以下问题:
我从微软的SQLpipe理表中读取一个表格,并希望每天将这个表格导出到具有相同excel-name的文件夹中,这意味着覆盖。
SqlConnection cnn; string connectionString = null; string sql = null; string data = null; int i, j = 0; Excel._Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); connectionString = "server=zumtesten;database=LogEMD;user=user123;password=user201611;"; cnn = new SqlConnection(connectionString); cnn.Open(); sql = "SELECT * FROM Flop"; SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn); DataSet ds = new DataSet(); dscmd.Fill(ds); for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) { for (j = 0; j <= ds.Tables[0].Columns.Count - 1; j++) { data = ds.Tables[0].Rows[i].ItemArray[j].ToString(); xlWorkSheet.Cells[i + 1, j + 1] = data; } } xlApp.DisplayAlerts = false; xlWorkBook.SaveAs(@"Y:\\Favoriten\\Flop_N7.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp);
我已经使用Display.Alerts = false,但MessageBox仍然显示,有人可以帮助我吗? 非常感谢!
首先简单地删除文件:
if (File.Exists(@"Y:\\Favoriten\\Flop_N7.xls")) { File.Delete(@"Y:\\Favoriten\\Flop_N7.xls"); }