81 lines
1.7 KiB
C#
81 lines
1.7 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 void SetLineSpacing(float linesPerInch) // if need landscape set too: , bool landscape)
|
|
{
|
|
LBSelection selection = MyWordApp.Selection;
|
|
selection.WholeStory();
|
|
selection.ParagraphFormat.SpaceBefore = 0;
|
|
selection.ParagraphFormat.SpaceAfter = 0;
|
|
selection.ParagraphFormat.LineSpacingRule = LBWdLineSpacing.wdLineSpaceExactly;
|
|
selection.ParagraphFormat.LineSpacing = 72 / linesPerInch;
|
|
}
|
|
public float Length
|
|
{
|
|
get { return MyWordDoc.Length; }
|
|
}
|
|
public static void CloseApp()
|
|
{
|
|
if(_MyWordApp != null)
|
|
{
|
|
_MyWordApp.Quit(false);
|
|
_MyWordApp=null;
|
|
}
|
|
}
|
|
}
|
|
}
|