Maybe execute workbook1.Save() after Protect (before Close) too.
How to avoid pop up while close the Excel file
I am trying to unprotect and protect excel sheet.
i am able to unprotect sheet. but, finally after all processing done, protect sheet not working.
before closing workbook1.Close(); ==> It will throw popup to save changes. ==> How to avoid this
==> want avoid to popup when close.....????
what could be the problem. below is the code.
string XLpath = "C:\Documents\excel1.xlsx";
static Excel.Application application1 = null;
static Excel.Workbook workbook1 = null;
SaveToXL(dt, XLpworkbookpwd);
CalcFile();
public void SaveToXL(System.Data.DataTable dt, string XLwbkpwd)
{
xlApp = new Excel.Application();
XLWBook1 = xlApp.Workbooks.Open(XLpath);
foreach (Excel.Worksheet wsht_ex in XLWBook1.Worksheets)
{
//unprotect excel sheet with password before saving
wsht_ex.Unprotect(XLwbkpwd);
}
XLWBook1.Save();
XLWBook1.Close();
xlApp.Quit(); // Quit Excel Application
}
public void CalcFile(string sheetName, string XLwbkpwd)
{
try
{
WriteToXL();
}
catch (Exception ex)
{
}
finally
{
workbook1.Save(); //data saved after calculation
workbook1.Worksheets[sheetName].Protect(XLwbkpwd); **// Sheet protecting here**
**//throw popup to save your changes - Need to Avoid popup to save**
![70503-image.png][2]
workbook1.Close(); **// code hanging here.**
application1.Quit();
}
}