c# - Delaying Excel Events with CalculationState -
it understanding can check if excel still calculating (i.e. refreshing query) using calculation state. added in line syntax ensure workbook not saved until queries had been refreshed in workbook (i created test workbook 1 query , saving before 1 refresh). did set incorrectly, or did mis-understand purpose of calculation state?
public form_main() { initializecomponent(); backgroundworker1.workerreportsprogress = true; backgroundworker1.dowork += new doworkeventhandler(backgroundworker1_dowork); backgroundworker1_progresschanged += new progresschangedeventhandler(backgroundworker1_progresschanged); } private void btnopenrefreshsave_click() { backgroundworker1_runworkerasync(); } private void backgroundworker1_dowork(object sender, doworkeventargs e) { excel.application exapp; excel._workbook exbook; excel._worksheet exsheet; exbook = (excel._workbook)(exapp.workbooks.open("c:\\book1.xlsx")); exsheet = (excel._worksheet)(exbook.activesheet); //this line of code times takes while exbook.refreshall(); //end of trouble line if (exapp.calculationstate == excel.xlcalculationstate.xldone) { exbook.saveas("c:\\updated_book1.xlsx"); } } private void backgroundworker1_progresschanged(object sender, progresschangedeventargs e) { }
calculationstate refers status of excel calculation engine (pending, calculating, done) rather queries, not integrated part of calculation engine, (except running query dirty cells , hence trigger calculation).
Comments
Post a Comment