Using system; use system.io;
Namespace Ysj.publicClass {/// /// Word summary description. /// summary> public class wordclass {
Word.Application WordApp = NULL; Word.Document WordDoc = NULL;
object Nothing = System.Reflection.Missing.Value; object format = Word.WdSaveFormat.wdFormatDocument; object objt = true; object unit = Word.WdUnits.wdStory; object pBreak = (int) Word.WdBreakType.wdPageBreak; public WordClass () {} /// /// Create a Word object /// summary> public void createWordApp () {Object Daltert = false; WordApp = new word.applicationclass (); Wordapp.displayAlerts = word.wdalertlevel.wdalertsnone }
/// /// Add a picture to a word file //// summary> /// picture path param> public void addimgtoword (StrimGPath) {///// image if (System.IO.File.Exists (strImgPath)) {wordApp.Selection.EndKey (ref unit, ref Nothing); wordApp.Selection.InlineShapes.AddPicture (strImgPath, ref Nothing, ref objt, ref Nothing); wordApp. Selection.Range.Insertafter (" '/ n');}} /// /// Insert images in the current cursor position /// summary> /// image path param> public void AddImgToWordLocation (string strImgPath) {// image if (System.IO.File.Exists (strImgPath)) {wordApp.Selection.Range.InlineShapes.AddPicture (strImgPath, ref Nothing, ref objt, Ref nothing);}}} /// /// Insert the specified content in a specific row and enter /// summary> /// content param> /// font param> /// font size param> public void insertcaption (String Title, String StrfontName, Float Fontsize, Bool Center) { Word.Range rg = wordapp.selection.ran ge; Rg.InsertBefore ( '/ n' Title); Rg.Font.Name = strFontName; Rg.Font.Size = FontSize; if (Center) {Rg.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;}}
/// /// Insert Enter /// Summary> /// Enter a number of Enter param> public void insertenter (int how) {for (INT i = 0; i <= how; i ) {WordApp.seLection.Range.insertbefore (" '/ n');}} /// /// Open file with Word /// summary> /// file path param> public void OpenFileToWord (string strFilePath) {if (System.IO.File.Exists (strFilePath)) {object srcFileName = @ strFilePath; object wdDelete = Word. WdDeleteCells.wdDeleteCellsEntireColumn; object wdCount = 1; wordDoc = wordApp.Documents.Open (ref srcFileName, ref format, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, Ref nothing); Wordapp.Serection.TypebackSpace (); Wordapp.Serection.TypeBackspace (); Wordapp.Serection.Range.insertBreak (Ref pbreak);}} /// /// Close Word object /// < / summary> public void closeword () {WordDoc.close (ref nothing, ref nothing, ref nothing); Wordapp.quit (Ref Nothin g, ref nothing, ref nothing;} /// /// save into a word file /// summary> /// param> public void saveword (String strWordFilePath) {// save as to the htm file doc file object dstFileName = @ strWordFilePath; wordDoc.SaveAs (ref dstFileName, ref format, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, REF NOTHING, REF NOTHING;
}