In depth understanding of the C Word class library
- 2020-05-12 03:11:30
- OfStack
The code is as follows:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop.Word;
using System.IO;
using System.Web;
using System.Data;
using System.Reflection;
using Microsoft.Win32;
using System.Text.RegularExpressions;
using System.Net;
namespace OfficeOperate
{
public class WordOperate
{
#region Dynamically generated Word Document and populate the data
/**//// <summary>
/// Dynamically generated Word Document and populate the data
/// </summary>
/// <returns> Returns custom information </returns>
public static string CreateWordFile()
{
string message = "";
try
{
Object oMissing = System.Reflection.Missing.Value;
string dir = System.Web.HttpContext.Current.Server.MapPath( "" );// First add in the class library using System.web A reference to the
if( !Directory.Exists( dir + "//file" ) )
{
Directory.CreateDirectory( dir + "//file" ); // Create the directory where the files are located
}
string name = DateTime.Now.ToLongDateString() + ".doc";
object filename = dir + "//file//" + name; // File save path
// create Word The document
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add( ref oMissing, ref oMissing, ref oMissing, ref oMissing );
/**///// Add the header method 1 :
//WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;
//WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;
//WordApp.ActiveWindow.ActivePane.Selection.InsertAfter( " Wuxi quanzhentong technology co. LTD " );// The header content
// Add the header method 2 :
if( WordApp.ActiveWindow.ActivePane.View.Type == Microsoft.Office.Interop.Word.WdViewType.wdNormalView || WordApp.ActiveWindow.ActivePane.View.Type == Microsoft.Office.Interop.Word.WdViewType.wdOutlineView )
{
WordApp.ActiveWindow.ActivePane.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdPrintView;
}
WordApp.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader;
string sHeader = " The header content ";
WordApp.Selection.HeaderFooter.LinkToPrevious = false;
WordApp.Selection.HeaderFooter.Range.Text = sHeader;
WordApp.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;
//WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;// Right align
WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;// Left aligned
WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;// Pops out of the header Settings
WordApp.Selection.ParagraphFormat.LineSpacing = 15f;// Sets the line spacing of the document
// Move focus and wrap
object count = 14;
object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;// in 1 line ;
WordApp.Selection.MoveDown( ref WdLine, ref count, ref oMissing );// Move the focus
WordApp.Selection.TypeParagraph();// Insert a paragraph
// Create a table in the document
Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add( WordApp.Selection.Range, 12, 3, ref oMissing, ref oMissing );
// Set the table style
newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleThickThinLargeGap;
newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
newTable.Columns[1].Width = 100f;
newTable.Columns[2].Width = 220f;
newTable.Columns[3].Width = 105f;
// Fill in the table
newTable.Cell( 1, 1 ).Range.Text = " Product details table ";
newTable.Cell( 1, 1 ).Range.Bold = 2;// Set the font in the cell to bold
// Merge cell
newTable.Cell( 1, 1 ).Merge( newTable.Cell( 1, 3 ) );
WordApp.Selection.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;// Vertical center
WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;// Horizontal center
// Fill in the table
newTable.Cell( 2, 1 ).Range.Text = " Basic product information ";
newTable.Cell( 2, 1 ).Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorDarkBlue;// Sets the font color in the cell
// Merge cell
newTable.Cell( 2, 1 ).Merge( newTable.Cell( 2, 3 ) );
WordApp.Selection.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
// Fill in the table
newTable.Cell( 3, 1 ).Range.Text = " Brand name: ";
newTable.Cell( 3, 2 ).Range.Text = "BrandName";
// Vertically merge the cells
newTable.Cell( 3, 3 ).Select();// The selected 1 line
object moveUnit = Microsoft.Office.Interop.Word.WdUnits.wdLine;
object moveCount = 5;
object moveExtend = Microsoft.Office.Interop.Word.WdMovementType.wdExtend;
WordApp.Selection.MoveDown( ref moveUnit, ref moveCount, ref moveExtend );
WordApp.Selection.Cells.Merge();
// Insert the picture
if( File.Exists( System.Web.HttpContext.Current.Server.MapPath( "images//picture.jpg" ) ) )
{
string FileName = System.Web.HttpContext.Current.Server.MapPath( "images//picture.jpg" );// The path of the image
object LinkToFile = false;
object SaveWithDocument = true;
object Anchor = WordDoc.Application.Selection.Range;
WordDoc.Application.ActiveDocument.InlineShapes.AddPicture( FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor );
WordDoc.Application.ActiveDocument.InlineShapes[1].Width = 100f;// Image width
WordDoc.Application.ActiveDocument.InlineShapes[1].Height = 100f;// Picture height
}
// Set the image to 4 Weeks surround type
Microsoft.Office.Interop.Word.Shape s = WordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape();
s.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapSquare;
newTable.Cell( 12, 1 ).Range.Text = " Product specific attributes ";
newTable.Cell( 12, 1 ).Merge( newTable.Cell( 12, 3 ) );
// Add rows to the table
WordDoc.Content.Tables[1].Rows.Add( ref oMissing );
WordDoc.Paragraphs.Last.Range.Text = " Document creation time: " + DateTime.Now.ToString();// "Signature"
WordDoc.Paragraphs.Last.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
// file
WordDoc.SaveAs( ref filename, 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 );
WordDoc.Close( ref oMissing, ref oMissing, ref oMissing );
WordApp.Quit( ref oMissing, ref oMissing, ref oMissing );
message = name + " Document generation successful ";
}
catch
{
message = " File export exception! ";
}
return message;
}
#endregion
#region Create and open 1 empty word Edit the document
/**//// <summary>
/// Create and open 1 empty word Edit the document
/// </summary>
public static void OpenNewWordFileToEdit()
{
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application WordApp;
Microsoft.Office.Interop.Word.Document WordDoc;
WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
WordApp.Visible = true;
WordDoc = WordApp.Documents.Add( ref oMissing, ref oMissing, ref oMissing, ref oMissing );
}
#endregion
#region create word The document
/**//// <summary>
/// create word The document
/// </summary>
/// <returns></returns>
public static string createWord()
{
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Document WordDoc;
string strContent = "";
object strFileName = System.Web.HttpContext.Current.Server.MapPath( "test.doc " );
if( System.IO.File.Exists( (string)strFileName ) )
System.IO.File.Delete( (string)strFileName );
Object oMissing = System.Reflection.Missing.Value;
WordDoc = WordApp.Documents.Add( ref oMissing, ref oMissing, ref oMissing, ref oMissing );
#region Writes the read-get data from the database to word In the file
strContent = " hello /n/n/r ";
WordDoc.Paragraphs.Last.Range.Text = strContent;
strContent = " This is the test procedure ";
WordDoc.Paragraphs.Last.Range.Text = strContent;
#endregion
// will WordDoc The content of the document object is saved as DOC The document
WordDoc.SaveAs( ref strFileName, 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 );
// Shut down WordDoc The document object
WordDoc.Close( ref oMissing, ref oMissing, ref oMissing );
// Shut down WordApp Component object
WordApp.Quit( ref oMissing, ref oMissing, ref oMissing );
string message = strFileName + "/r/n " + " Creating a successful ";
return message;
}
#endregion
#region the Word Document as Html file
/**//// <summary>
/// the Word Document as Html file
/// </summary>
/// <param name="strFileName"> To convert Word The document </param>
public static void WordToHtml( string strFileName )
{
string saveFileName = strFileName + DateTime.Now.ToString( "yyyy-MM-dd-HH-mm-ss" ) + ".html";
WordToHtml( strFileName, saveFileName );
}
/**//// <summary>
/// the Word Document as Html file
/// </summary>
/// <param name="strFileName"> To convert Word The document </param>
/// <param name="strSaveFileName"> The concrete to be generated Html page </param>
public static void WordToHtml( string strFileName, string strSaveFileName )
{
Microsoft.Office.Interop.Word.ApplicationClass WordApp;
Microsoft.Office.Interop.Word.Document WordDoc;
Object oMissing = System.Reflection.Missing.Value;
WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
object fileName = strFileName;
WordDoc = WordApp.Documents.Open( ref fileName,
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 );
Type wordType = WordApp.GetType();
// Open the file
Type docsType = WordApp.Documents.GetType();
// Convert the format and save as
Type docType = WordDoc.GetType();
object saveFileName = strSaveFileName;
docType.InvokeMember( "SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, WordDoc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML } );
#region Other formats:
/**//**/
/**////wdFormatHTML
///wdFormatDocument
///wdFormatDOSText
///wdFormatDOSTextLineBreaks
///wdFormatEncodedText
///wdFormatRTF
///wdFormatTemplate
///wdFormatText
///wdFormatTextLineBreaks
///wdFormatUnicodeText
//-------------------------------------------------------------------------- // docType.InvokeMember( "SaveAs", System.Reflection.BindingFlags.InvokeMethod,
// null, WordDoc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatHTML} );
// exit Word
//wordType.InvokeMember( "Quit", System.Reflection.BindingFlags.InvokeMethod,
// null, WordApp, null );
#endregion
WordDoc.Close( ref oMissing, ref oMissing, ref oMissing );
WordApp.Quit( ref oMissing, ref oMissing, ref oMissing );
}
#endregion
#region Import the template
/**//// <summary>
/// Import the template
/// </summary>
/// <param name="filePath"> Template document path </param>
public static void ImportTemplate( string filePath )
{
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application WordApp;
Microsoft.Office.Interop.Word.Document WordDoc;
WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
WordApp.Visible = true;
object fileName = filePath;
WordDoc = WordApp.Documents.Add( ref fileName, ref oMissing, ref oMissing, ref oMissing );
}
#endregion
#region word Add a new table in
/**//// <summary>
/// word Add a new table in
/// </summary>
public static void AddTable()
{
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application WordApp;
Microsoft.Office.Interop.Word.Document WordDoc;
WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
WordApp.Visible = true;
WordDoc = WordApp.Documents.Add( ref oMissing, ref oMissing, ref oMissing, ref oMissing );
object start = 0;
object end = 0;
Microsoft.Office.Interop.Word.Range tableLocation = WordDoc.Range( ref start, ref end );
WordDoc.Tables.Add( tableLocation, 3, 4, ref oMissing, ref oMissing );//3 line 4 Column of the table
}
#endregion
#region Insert a new row into the table
/**//// <summary>
/// Insert a new one into the table 1 line
/// </summary>
public static void AddRow()
{
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application WordApp;
Microsoft.Office.Interop.Word.Document WordDoc;
WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
WordApp.Visible = true;
WordDoc = WordApp.Documents.Add( ref oMissing, ref oMissing, ref oMissing, ref oMissing );
object start = 0;
object end = 0;
Microsoft.Office.Interop.Word.Range tableLocation = WordDoc.Range( ref start, ref end );
WordDoc.Tables.Add( tableLocation, 3, 4, ref oMissing, ref oMissing );
Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables[1];
object beforeRow = newTable.Rows[1];
newTable.Rows.Add( ref beforeRow );
}
#endregion
#region Split cell
/**//// <summary>
/// Merge cell
/// </summary>
public static void CombinationCell()
{
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application WordApp;
Microsoft.Office.Interop.Word.Document WordDoc;
WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
WordApp.Visible = true;
WordDoc = WordApp.Documents.Add( ref oMissing, ref oMissing, ref oMissing, ref oMissing );
object start = 0;
object end = 0;
Microsoft.Office.Interop.Word.Range tableLocation = WordDoc.Range( ref start, ref end );
WordDoc.Tables.Add( tableLocation, 3, 4, ref oMissing, ref oMissing );
Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables[1];
object beforeRow = newTable.Rows[1];
newTable.Rows.Add( ref beforeRow );
Microsoft.Office.Interop.Word.Cell cell = newTable.Cell( 2, 1 );//2 line 1 columns 2 line 2 As a 1 since
cell.Merge( newTable.Cell( 2, 2 ) );
//cell.Merge( newTable.Cell( 1, 3 ) );
}
#endregion
#region Split cell
/**//// <summary>
/// Split cell
/// </summary>
public static void SeparateCell()
{
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application WordApp;
Microsoft.Office.Interop.Word.Document WordDoc;
WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
WordApp.Visible = true;
WordDoc = WordApp.Documents.Add( ref oMissing, ref oMissing, ref oMissing, ref oMissing );
object start = 0;
object end = 0;
Microsoft.Office.Interop.Word.Range tableLocation = WordDoc.Range( ref start, ref end );
WordDoc.Tables.Add( tableLocation, 3, 4, ref oMissing, ref oMissing );
Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables[1];
object beforeRow = newTable.Rows[1];
newTable.Rows.Add( ref beforeRow );
Microsoft.Office.Interop.Word.Cell cell = newTable.Cell( 1, 1 );
cell.Merge( newTable.Cell( 1, 2 ) );
object Rownum = 2;
object Columnnum = 2;
cell.Split( ref Rownum, ref Columnnum );
}
#endregion
#region The insertion is controlled by paragraphs Insert a paragraph at the beginning of the document.
/**//// <summary>
/// The insertion is controlled by paragraphs Insert a paragraph at the beginning of the document.
/// </summary>
public static void Insert()
{
object oMissing = System.Reflection.Missing.Value;
//object oEndOfDoc = "//endofdoc"; /**//* /endofdoc is a predefined bookmark */
//Start Word and create a new document.
Microsoft.Office.Interop.Word.Application WordApp;
Microsoft.Office.Interop.Word.Document WordDoc;
WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
WordApp.Visible = true;
WordDoc = WordApp.Documents.Add( ref oMissing, ref oMissing, ref oMissing, ref oMissing );
//Insert a paragraph at the beginning of the document.
Microsoft.Office.Interop.Word.Paragraph oPara1;
oPara1 = WordDoc.Content.Paragraphs.Add( ref oMissing );
oPara1.Range.Text = "Heading 1";
oPara1.Range.Font.Bold = 1;
oPara1.Format.SpaceAfter = 24; //24 pt spacing after paragraph.
oPara1.Range.InsertParagraphAfter();
}
#endregion
#region word Document Settings and gets cursor position
/**//// <summary>
/// word Document Settings and gets cursor position
/// </summary>
public static void WordSet()
{
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application WordApp;
Microsoft.Office.Interop.Word.Document WordDoc;
WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
#region Document formatting
WordApp.ActiveDocument.PageSetup.LineNumbering.Active = 0;// Line number
WordApp.ActiveDocument.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientPortrait;// Page orientation
WordApp.ActiveDocument.PageSetup.TopMargin = WordApp.CentimetersToPoints( float.Parse( "2.54" ) );// On the margins
WordApp.ActiveDocument.PageSetup.BottomMargin = WordApp.CentimetersToPoints( float.Parse( "2.54" ) );// On the next page margins
WordApp.ActiveDocument.PageSetup.LeftMargin = WordApp.CentimetersToPoints( float.Parse( "3.17" ) );// The left margins
WordApp.ActiveDocument.PageSetup.RightMargin = WordApp.CentimetersToPoints( float.Parse( "3.17" ) );// Right margins
WordApp.ActiveDocument.PageSetup.Gutter = WordApp.CentimetersToPoints( float.Parse( "0" ) );// Binding line position
WordApp.ActiveDocument.PageSetup.HeaderDistance = WordApp.CentimetersToPoints( float.Parse( "1.5" ) );// The header
WordApp.ActiveDocument.PageSetup.FooterDistance = WordApp.CentimetersToPoints( float.Parse( "1.75" ) );// The footer
WordApp.ActiveDocument.PageSetup.PageWidth = WordApp.CentimetersToPoints( float.Parse( "21" ) );// The paper width
WordApp.ActiveDocument.PageSetup.PageHeight = WordApp.CentimetersToPoints( float.Parse( "29.7" ) );// The paper height
WordApp.ActiveDocument.PageSetup.FirstPageTray = Microsoft.Office.Interop.Word.WdPaperTray.wdPrinterDefaultBin;// Paper source
WordApp.ActiveDocument.PageSetup.OtherPagesTray = Microsoft.Office.Interop.Word.WdPaperTray.wdPrinterDefaultBin;// Paper source
WordApp.ActiveDocument.PageSetup.SectionStart = Microsoft.Office.Interop.Word.WdSectionStart.wdSectionNewPage;// Start of section: new page
WordApp.ActiveDocument.PageSetup.OddAndEvenPagesHeaderFooter = 0;// Header, footer - Odd and even pages are different
WordApp.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = 0;// Header, footer - Different home page
WordApp.ActiveDocument.PageSetup.VerticalAlignment = Microsoft.Office.Interop.Word.WdVerticalAlignment.wdAlignVerticalTop;// Vertical page alignment
WordApp.ActiveDocument.PageSetup.SuppressEndnotes = 0;// Do not hide endnotes
WordApp.ActiveDocument.PageSetup.MirrorMargins = 0;// Do not set the inside and outside margins of the home page
WordApp.ActiveDocument.PageSetup.TwoPagesOnOne = false;// Non-duplex printing
WordApp.ActiveDocument.PageSetup.BookFoldPrinting = false;// Manual double-sided front printing is not set
WordApp.ActiveDocument.PageSetup.BookFoldRevPrinting = false;// Manual double-sided back printing is not set
WordApp.ActiveDocument.PageSetup.BookFoldPrintingSheets = 1;// Print the default number of copies
WordApp.ActiveDocument.PageSetup.GutterPos = Microsoft.Office.Interop.Word.WdGutterStyle.wdGutterPosLeft;// The binding line is on the left
WordApp.ActiveDocument.PageSetup.LinesPage = 40;// Default page line count
WordApp.ActiveDocument.PageSetup.LayoutMode = Microsoft.Office.Interop.Word.WdLayoutMode.wdLayoutModeLineGrid;// The layout mode is "specify row grid only"
#endregion
#region Paragraph formatting
WordApp.Selection.ParagraphFormat.LeftIndent = WordApp.CentimetersToPoints( float.Parse( "0" ) );// The indentation left
WordApp.Selection.ParagraphFormat.RightIndent = WordApp.CentimetersToPoints( float.Parse( "0" ) );// Right indent
WordApp.Selection.ParagraphFormat.SpaceBefore = float.Parse( "0" );// Before paragraph spacing
WordApp.Selection.ParagraphFormat.SpaceBeforeAuto = 0;//
WordApp.Selection.ParagraphFormat.SpaceAfter = float.Parse( "0" );// After the period of spacing
WordApp.Selection.ParagraphFormat.SpaceAfterAuto = 0;//
WordApp.Selection.ParagraphFormat.LineSpacingRule = Microsoft.Office.Interop.Word.WdLineSpacing.wdLineSpaceSingle;// single-spaced
WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustify;// The paragraph 2 The alignment
WordApp.Selection.ParagraphFormat.WidowControl = 0;// Make control
WordApp.Selection.ParagraphFormat.KeepWithNext = 0;// On the same page as the next paragraph
WordApp.Selection.ParagraphFormat.KeepTogether = 0;// No paging in segments
WordApp.Selection.ParagraphFormat.PageBreakBefore = 0;// Before paragraph the paging
WordApp.Selection.ParagraphFormat.NoLineNumber = 0;// Cancel the line Numbers
WordApp.Selection.ParagraphFormat.Hyphenation = 1;// Cancel the period of word
WordApp.Selection.ParagraphFormat.FirstLineIndent = WordApp.CentimetersToPoints( float.Parse( "0" ) );// The first line indentation
WordApp.Selection.ParagraphFormat.OutlineLevel = Microsoft.Office.Interop.Word.WdOutlineLevel.wdOutlineLevelBodyText;
WordApp.Selection.ParagraphFormat.CharacterUnitLeftIndent = float.Parse( "0" );
WordApp.Selection.ParagraphFormat.CharacterUnitRightIndent = float.Parse( "0" );
WordApp.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = float.Parse( "0" );
WordApp.Selection.ParagraphFormat.LineUnitBefore = float.Parse( "0" );
WordApp.Selection.ParagraphFormat.LineUnitAfter = float.Parse( "0" );
WordApp.Selection.ParagraphFormat.AutoAdjustRightIndent = 1;
WordApp.Selection.ParagraphFormat.DisableLineHeightGrid = 0;
WordApp.Selection.ParagraphFormat.FarEastLineBreakControl = 1;
WordApp.Selection.ParagraphFormat.WordWrap = 1;
WordApp.Selection.ParagraphFormat.HangingPunctuation = 1;
WordApp.Selection.ParagraphFormat.HalfWidthPunctuationOnTopOfLine = 0;
WordApp.Selection.ParagraphFormat.AddSpaceBetweenFarEastAndAlpha = 1;
WordApp.Selection.ParagraphFormat.AddSpaceBetweenFarEastAndDigit = 1;
WordApp.Selection.ParagraphFormat.BaseLineAlignment = Microsoft.Office.Interop.Word.WdBaselineAlignment.wdBaselineAlignAuto;
#endregion
#region Font formatting
WordApp.Selection.Font.NameFarEast = " HuaWenZhong song ";
WordApp.Selection.Font.NameAscii = "Times New Roman";
WordApp.Selection.Font.NameOther = "Times New Roman";
WordApp.Selection.Font.Name = " Song typeface ";
WordApp.Selection.Font.Size = float.Parse( "14" );
WordApp.Selection.Font.Bold = 0;
WordApp.Selection.Font.Italic = 0;
WordApp.Selection.Font.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineNone;
WordApp.Selection.Font.UnderlineColor = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;
WordApp.Selection.Font.StrikeThrough = 0;// Delete the line
WordApp.Selection.Font.DoubleStrikeThrough = 0;// Double delete line
WordApp.Selection.Font.Outline = 0;// hollow
WordApp.Selection.Font.Emboss = 0;// Yang wen
WordApp.Selection.Font.Shadow = 0;// shadow
WordApp.Selection.Font.Hidden = 0;// The hidden text
WordApp.Selection.Font.SmallCaps = 0;// Small capital letter
WordApp.Selection.Font.AllCaps = 0;// All caps
WordApp.Selection.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;
WordApp.Selection.Font.Engrave = 0;// The spiral
WordApp.Selection.Font.Superscript = 0;// superscript
WordApp.Selection.Font.Subscript = 0;// The subscript
WordApp.Selection.Font.Spacing = float.Parse( "0" );// Between characters
WordApp.Selection.Font.Scaling = 100;// Characters zooming
WordApp.Selection.Font.Position = 0;// location
WordApp.Selection.Font.Kerning = float.Parse( "1" );// Font spacing adjustment
WordApp.Selection.Font.Animation = Microsoft.Office.Interop.Word.WdAnimation.wdAnimationNone;// Text effects
WordApp.Selection.Font.DisableCharacterSpaceGrid = false;
WordApp.Selection.Font.EmphasisMark = Microsoft.Office.Interop.Word.WdEmphasisMark.wdEmphasisMarkNone;
#endregion
#region Get cursor position
/**/////get_Information
WordApp.Selection.get_Information( WdInformation.wdActiveEndPageNumber );
// About the line number - Page number - Column number - location
//information attribute
// Returns information about a specified selected content or area. variant Type, read only.
//expression.information(type)
//expression A necessity. This expression returns 1 a range or selection Object.
//type long Type, required. The information that needs to be returned. Recommend the following wdinformation Constants of 1 :
//wdactiveendadjustedpagenumber Returns the page number that contains the active end of the specified selected content or area. If you set it 1 , and manually adjusted the page number, the adjusted page number is returned.
//wdactiveendpagenumber Returns a page number containing the active end of the specified selected content or area on the page, calculated from the beginning of the document without regard to any manual adjustments to the page number.
//wdactiveendsectionnumber Returns the section number that contains the active end of the specified selected content or area.
//wdatendofrowmarker This parameter is returned if the selected content or area specified is located at the end of the row in the table true .
//wdcapslock This parameter is returned if the caps lock mode is valid true .
//wdendofrangecolumnnumber Returns the table column number that contains the active end of the specified selected content or area.
//wdendofrangerownumber Returns the table row number that contains the end of the activity for the specified selected content or area.
//wdfirstcharactercolumnnumber Returns the value of a specified selected content or area 1 The position of the characters. If the selected content or area is folded, the character number immediately following to the right of the selected content or area is returned.
//wdfirstcharacterlinenumber Returns the first in the selection 1 A line number of characters. if pagination Properties for false Or, draft Properties for true , the return - 1 .
//wdframeisselected If the selected content or area is 1 Text box, this parameter is returned true .
//wdheaderfootertype return 1 , which indicates the type of header or footer that contains the specified selected content or area, as shown in the following table. value The type of header or footer
//- 1 There is no
//0 Even page headers
//1 Odd page header
//2 Even footer
//3 Odd footer
//4 The first 1 A header
//5 The first 1 A footer
//wdhorizontalpositionrelativetopage Returns the horizontal location of the specified selected content or area. This location is the distance in pounds between the left side of the selected content or area and the left side of the page. Returns if the selected content or area is not visible - 1 .
//wdhorizontalpositionrelativetotextboundary Returns the horizontal position, in pounds, of the specified selected content or area to the left of the nearest surrounding body boundary. This parameter is returned if the selected content or area is not displayed on the current screen - 1 .
//wdinclipboard For more information on this constant, see microsoft office 98 macintosh Version of the language reference help.
//wdincommentpane Returns if the selected content or area specified is in the annotation pane true .
//wdinendnote This parameter is returned if the selected content or area specified is in the endnote area of the page view, or in the endnote pane of a normal view true .
//wdinfootnote This parameter is returned if the selected content or area specified is located in the footnote area of the page view, or in the footnote pane of the normal view true .
//wdinfootnoteendnotepane This parameter is returned if the selected content or area specified is in the footnote or endnote area of the page view, or in the footnote or endnote pane of the normal view true . For more information, see the previous section wdinfootnote and wdinendnote The instructions.
//wdinheaderfooter This parameter is returned if the selected content or area specified is located in the header or footer pane, or in the header or footer of the page view true .
//wdinmasterdocument This parameter is returned if the selected content or area specified is located in the master document true .
//wdinwordmail return 1 The value indicates the location of the selected content or area, as shown in the following table. value location
//0 The selected content or area is not present 1 In an email message.
//1 The selected content or area is in the email being sent.
//2 The selected content or area is in the email you are reading.
//wdmaximumnumberofcolumns Returns the maximum number of table columns for any row in the selected content or area.
//wdmaximumnumberofrows Returns the maximum number of rows in a table in the specified selected content or area.
//wdnumberofpagesindocument Returns the number of pages of the document associated with the selected content or area.
//wdnumlock if num lock Valid, this parameter is returned true .
//wdovertype If the overwrite mode is valid, this parameter is returned true . available overtype Property changes the state of the rewrite mode.
//wdreferenceoftype return 1 Is a value indicating the position of the selected content relative to a footnote, endnote, or annotation reference, as shown in the following table. value describe
// - 1 The selected content or area includes, but is not limited to, a footnote, endnote, or annotation reference.
//0 The selected content or area does not precede a footnote, endnote, or annotation reference.
//1 The selected content or area precedes the footnote reference.
//2 The selected content or area precedes the endnote reference.
//3 The selected content or area precedes the annotation reference.
//wdrevisionmarking If the revision function is active, this parameter is returned true .
//wdselectionmode return 1 , which indicates the currently selected schema, as shown in the following table. value The selected mode
//0 Conventional selected
//1 Extend the selected
//2 Selected columns
//wdstartofrangecolumnnumber Returns the column number of the table in which the starting point of the selected content or area is located.
//wdstartofrangerownumber Returns the row number of the table in which the starting point of the selected content or area is located.
//wdverticalpositionrelat