本文介绍了如何在没有提示dalog的情况下保存和更改excel.files的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 解密文件后,我在关闭工作簿时遇到保存更改(/ silent)Excel文件的新问题,MSExcel总是承诺在每个xlsx文件中保存和替换文件。我真的需要Silent,Quiet save quit excel工作簿。但是,我不知道我想念的是什么?请帮帮我,(抱歉我的语言) Try2SilentSaveExist.rar - 文件上传脚本 [ ^ ] 我的尝试: 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。应用(); 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。关闭( true ); } 返回 true ; } catch { return 假; } } 其他 { / * if(System.IO.Path.GetExtension(brokenFile).ToLower()==。dococ) {} * / return true ; } } 解决方案 您可以在保存代码之前加上: 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);} 这篇关于如何在没有提示dalog的情况下保存和更改excel.files的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-15 13:38