Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void PasswordExcel(string path,string pass,string name)
- {
- try
- {
- System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
- System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
- object misValue = System.Reflection.Missing.Value;
- var xlApp = new Excel.Application();// ApplicationClass();
- var xlWorkBook = xlApp.Workbooks.Add(misValue);
- // Excel.Application xlApp;
- //Excel.Workbook xlWorkBook;
- try
- {
- xlApp = new Excel.ApplicationClass();
- xlWorkBook = xlApp.Workbooks.Open(path, true);
- xlWorkBook.Password = pass;
- xlWorkBook.Save();
- xlWorkBook.Close(0);
- xlApp.Quit();
- }
- catch(Exception ex)
- {
- throw new Exception("Al Cargar. " + ex.Message);
- }
- releaseObject(xlWorkBook);
- releaseObject(xlApp);
- System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
- }
- catch(Exception ex)
- {
- throw ex;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement