Rich 7bcfafcc8b Move frmErrors when frmLoader is moved
Shutoff SpellCheck for StepRTB
Use using for temporary StepRTB
Use using for vlnFlexGrid
Added debug output to track StepRTBs and vlnFlexGrids in memory
Limit bottom margin to 0 or above
Dispose of roImage after it is done being used
Dispose of Figure after it is done being used.
Use GetJustRODB so that images are not loaded.
Added ErrorHandler if annotation is deleted after a search
Track create, dispose and finalize
Add static variable to control if SpellCheck is used
Use using for temporary StepRTB
Lazy Load SelectionStack
Clean-up on Dispose
Track create, dispose and finalize
Make MyCopyInfo Lazy Loaded
Use using for temporary StepRTB
Add Dispose method for TableCellEditor
Cleanup on Dispose
Only kill MSWord instances that are invisible
2012-07-13 18:34:57 +00:00

139 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using LBWordLibrary;
namespace Volian.MSWord
{
public class WordDoc
{
private static LBApplicationClass _MyWordApp;
public static LBApplicationClass MyWordApp
{
get
{
if (_MyWordApp == null)
_MyWordApp = new LBApplicationClass();
return WordDoc._MyWordApp;
}
}
private LBDocumentClass _MyWordDoc;
public LBDocumentClass MyWordDoc
{
get
{ return _MyWordDoc; }
}
private string _DocName;
public string DocName
{
get { return _DocName; }
set { _DocName = value; }
}
public WordDoc(string docName)
{
DocName = docName;
_MyWordDoc = MyWordApp.Documents.Open(_DocName, false);
}
public string Save()
{
try
{
MyWordDoc.SaveAs(DocName, LBWdSaveFormat.wdFormatDocument);
return "Successful Save";
}
catch (Exception ex)
{
return string.Format("Error during Doc save - {0}", ex.Message);
}
}
public string Save(string docName)
{
DocName = docName;
return Save();
}
public void Close()
{
MyWordDoc.Close(false);
}
public float SetLineSpacing(float linesPerInch) // if need landscape set too: , bool landscape)
{
float retval = 0;
LBSelection selection = MyWordApp.Selection;
selection.WholeStory();
retval = selection.ParagraphFormat.LineSpacing;
selection.ParagraphFormat.SpaceBefore = 0;
selection.ParagraphFormat.SpaceAfter = 0;
selection.ParagraphFormat.LineSpacingRule = LBWdLineSpacing.wdLineSpaceExactly;
selection.ParagraphFormat.LineSpacing = 72 / linesPerInch;
return retval;
}
public float Length
{
get
{
try
{
return MyWordDoc.Length;
}
catch (Exception ex)
{
Console.WriteLine("Error Getting Length, {0}", ex.Message);
}
return 0;
}
}
public static void CloseApp()
{
if(_MyWordApp != null)
{
TryToQuit();
KillWordApps();
}
}
private static void TryToQuit()
{
try
{
_MyWordApp.Quit(false);
}
catch (Exception ex)
{
Console.WriteLine("{0} - {1}", ex.GetType().Name, ex.Message);
}
_MyWordApp=null;
}
public static void KillWordApps()
{
try
{
TerminateProcesses(WordProcesses);
}
catch (Exception ex)
{
Console.WriteLine("{0} - {1}", ex.GetType().Name, ex.Message);
}
}
public static void TerminateProcesses(System.Diagnostics.Process[] wordProcesses)
{
foreach (System.Diagnostics.Process proc in wordProcesses)
{
// Determine if Word is Visible
// If it is let it run
// otherwise Kill it.
if(proc.MainWindowTitle=="")
proc.Kill();
}
_MyWordApp = null;
}
public static System.Diagnostics.Process[] WordProcesses
{
get
{
return System.Diagnostics.Process.GetProcessesByName("WINWORD");
}
}
}
}