public static void CloseWord(MySettings settings)
{
if (System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application") != null)
{
try
{
Object oMissing = System.Reflection.Missing.Value;
//True and false objects
Object oTrue = true;
Object oFalse = false;
Microsoft.Office.Interop.Word.Application oWordApp = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
int i = 0;
foreach (Microsoft.Office.Interop.Word.Document document in oWordApp.Documents)
{
i++;
string num = i.ToString();
Object oSaveAsFileWord = General.GetAppString("UserDocuments") + GlobalData.GetStudentInfo()[0].ToString().Trim() + "_" + GlobalData.GetUserName() + settings.FileExtension;
oWordApp.ActiveDocument.SaveAs(ref oSaveAsFileWord, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
object doNotSaveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
oWordApp.ActiveDocument.Close(ref doNotSaveChanges, ref oMissing, ref oMissing);
}
oWordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
}
catch
{
}
}
}
public static void CloseExcel(MySettings settings)
{
try
{
Excel.Workbook xlwkbook;
string workbookPath = General.GetAppString("UserDocuments") + GlobalData.GetStudentInfo()[0].ToString().Trim() + "_" + GlobalData.GetUserName() + settings.FileExtension;
xlwkbook = (Excel.Workbook)System.Runtime.InteropServices.Marshal.BindToMoniker(workbookPath);
xlwkbook.Save();
xlwkbook.Application.Quit();
}
catch
{
return;
}
}
public static void ClosePowerPoint(MySettings settings)
{
try
{
Microsoft.Office.Interop.PowerPoint.Application PowerApp = (Microsoft.Office.Interop.PowerPoint.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Powerpoint.Application");
PowerApp.ActivePresentation.Save();
int num = PowerApp.Windows.Count;
PowerApp.Quit();
}
catch
{
return;
}
}
No comments:
Post a Comment