文件夾中我有以下問題:覆蓋Excel中沒有消息
我讀從Microsoft SQL管理表,並希望將此表導出日常生活與同一個Excel名稱的文件夾,這意味着覆蓋。
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仍然顯示,有人可以幫助我嗎?非常感謝!
如果你在寫用於顯示消息框的代碼? – VVN
@VVN我想象這個警告框來自Excel本身。 – Nicarus
是的,它自動到達 – Meng