try
...{ string filename;
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "請選擇將導出的Excel文件存放路徑";
sfd.Filter="Excel文檔(*.xls)|*.xls";
//sfd.OpenFile();
sfd.ShowDialog();
if (sfd.FileName != "")
...{
if(sfd.FileName.LastIndexOf(".xls")<=0)
...{
sfd.FileName=sfd.FileName+".xls";
}
filename=sfd.FileName;
if(System.IO.File.Exists(filename))
...{
System.IO.File.Delete(filename);
}
Excel.ApplicationClass xlApp = new Excel.ApplicationClass();
if (xlApp == null)