如何关闭 - 不保存Excel / xlsm工作簿,具有自定义功能,从C# [英] How to close-without-save an Excel /xlsm workbook, w/ a custom function, from C#
问题描述
当我尝试直接关闭(不保存)时,我得到一个保存提示。我怀疑这是因为Excel在打开时解释自动重新计算,因为创建一个变化,即使没有实际的数字或公式上的变化。我还设置了 Excel.Application.Calculation = Excel.XlCalculation.xlCalculationManual
。如何防止保存提示出现,只需关闭 - 不保存?
使用Excel对象时,请确保关闭工作簿:
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(Yourworkbook);
xlWorkSheet =(Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
....做你的东西
xlWorkBook.Close(false,misValue,misValue);
xlApp.Quit();
关闭方法中的false表示不保存更改。
I have an Excel workbook with a custom non-time-dependent cell function that I am opening from a C# WindowsForms application using Interop.Excel. I read four values from it, perform no explicit changes/calculations, then close it from C#.
When I try to directly close (without saving), I get a save prompt. I suspect this is because Excel is interpreting auto-recalculation on open as creating a change, even though nothing actually numerically or formulaically changes. I also set Excel.Application.Calculation = Excel.XlCalculation.xlCalculationManual
. How do I prevent the save prompt from appearing and just close-without-save?
When you use the Excel objects, be sure to close the workbook like this:
Excel.Application xlApp ;
Excel.Workbook xlWorkBook ;
Excel.Worksheet xlWorkSheet ;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add("Yourworkbook");
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
....do your stuff
xlWorkBook.Close(false, misValue, misValue);
xlApp.Quit();
The false in the close method indicates don't save changes.
这篇关于如何关闭 - 不保存Excel / xlsm工作簿,具有自定义功能,从C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!