Added logic so that MSWord 2010 and beyond uses the internal export to PDF function.

Added logic to handle errors when a document is closed.  The code will attempt to do a close 10 times.  If it fails ten times, it will document the exception and continue.
If an exception occurs when an MSWord section is being saved, a message will be displayed that will document the error.
This commit is contained in:
Rich
2013-09-18 16:42:30 +00:00
parent 54db0e1e81
commit 3e1d22674c
3 changed files with 35 additions and 6 deletions

View File

@@ -778,7 +778,7 @@ namespace VEPROMS.CSLA.Library
//_MyLog.WarnFormat("PNG Name = {0}, size = {1}", fi.Name, fi.Length);
filecount++;
RectangleF plotRect = CreatePlot(pngFile, xyplot, 600F, FormForPlotGraphics);
float xAdjust = (float)-sect.MyDocStyle.Layout.LeftMargin;
float yAdjust = selxy.Font.Size;
LBShape shape = myDoc.Shapes.AddPicture(pngFile, x + xAdjust + plotRect.X, yAdjust + y - yTop + plotRect.Y, selxy.Range);
@@ -790,7 +790,7 @@ namespace VEPROMS.CSLA.Library
}
LBSelection sel = MyApp.Selection;
sel.WholeStory();
if(statusChange != null) statusChange(VolianStatusType.Initialize, sel.End, "Refreshing ROs");
if (statusChange != null) statusChange(VolianStatusType.Initialize, sel.End, "Refreshing ROs");
sel = hasRos ? FindRO() : null;
int roCount = 0;
// force Print of MS Word Attachment to Final without revisions and comments
@@ -920,7 +920,7 @@ namespace VEPROMS.CSLA.Library
sel.Range.Font.Color = (LBWdColor)WordColor(OverrideColor == System.Drawing.Color.Transparent ? System.Drawing.Color.Black : OverrideColor);
sect.MSWordPageCount = myDoc.Length;
fileName = CreatePDF(fileName, openPdf);
MyApp.ActiveDocument.Close(false);
CloseDocument();
if (CloseWordWhenDone)
{
CloseAppAfterWait();
@@ -929,6 +929,31 @@ namespace VEPROMS.CSLA.Library
return fileName;
}
}
private static void CloseDocument()
{
int attempts = 0;
while (++attempts < 11)
{
if (TryToClose(attempts)) return;
WaitMS(1000);
}
}
private static bool TryToClose(int attempts)
{
try
{
throw(new Exception("Oops!");
MyApp.ActiveDocument.Close(false);
return true;
}
catch (Exception ex)
{
_MyLog.WarnFormat("{0} - {1}, Attempt {2}", ex.GetType().Name, ex.Message, attempts);
if (attempts >= 10)
_MyLog.Error("Failed to close 10 times.", ex);
return false;
}
}
private static string FindEmbeddedText(string p, ref string resXyPlot)
{
StringBuilder sb = new StringBuilder(); // contains embedded text