更新时间:2022-11-02 22:08:33
您可以在保存代码之前加上:
if (File.Exists(brokenFile))
{
File .Delete(brokenFile);
}
After decrypt file, i have a new problem with save change (/silent) Excel files when close workbook, MSExcel always promts to save and replace file in every xlsx file. i really need to Silent,Quiet save quit excel work book. but, I have no idea what i miss?, Help me please, (Sorry for my Language)
Try2SilentSaveExist.rar - File Upload Script[^]
What I have tried:
Microsoft.Office.Interop.Excel.Application MSexcel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook excelPrj = null;
/*Microsoft.Office.Interop.Word.Application MSword = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.PowerPoint.Application MSpoint = new Microsoft.Office.Interop.PowerPoint.Application();
Microsoft.Office.Interop.Access.Application MSAccs = new Microsoft.Office.Interop.Access.Application();
Microsoft.Office.Interop.Word.Document wordPrj = null;
Microsoft.Office.Interop.PowerPoint.Presentation pointPrj = null;*/
Missing miss = Missing.Value;
private bool RepairFile(string brokenFile)
{
if (System.IO.Path.GetExtension(brokenFile).ToLower() == ".xlsx")
{
try
{
string OldFile = brokenFile;
MSexcel.DisplayAlerts = false;
MSexcel.Visible = false;
MSexcel.UserControl = false;
excelPrj = MSexcel.Workbooks.Open(OldFile, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, Microsoft.Office.Interop.Excel.XlCorruptLoad.xlRepairFile);
if (excelPrj != null)
{
excelPrj.Close(true);
}
return true;
}
catch { return false; }
}
else
{
/*
if (System.IO.Path.GetExtension(brokenFile).ToLower() == ".docx")
{
}*/
return true;
}
}
You could precede your saving code with this:if (File.Exists(brokenFile)) { File.Delete(brokenFile); }