Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. private void PasswordExcel(string path,string pass,string name)
  2. {
  3. try
  4. {
  5. System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
  6. System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
  7. object misValue = System.Reflection.Missing.Value;
  8. var xlApp = new Excel.Application();// ApplicationClass();
  9. var xlWorkBook = xlApp.Workbooks.Add(misValue);
  10. // Excel.Application xlApp;
  11. //Excel.Workbook xlWorkBook;
  12. try
  13. {
  14. xlApp = new Excel.ApplicationClass();
  15. xlWorkBook = xlApp.Workbooks.Open(path, true);
  16. xlWorkBook.Password = pass;
  17. xlWorkBook.Save();
  18. xlWorkBook.Close(0);
  19. xlApp.Quit();
  20. }
  21. catch(Exception ex)
  22. {
  23. throw new Exception("Al Cargar. " + ex.Message);
  24. }
  25. releaseObject(xlWorkBook);
  26. releaseObject(xlApp);
  27. System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
  28. }
  29. catch(Exception ex)
  30. {
  31. throw ex;
  32. }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement