Exemple #1
0
        public Export()
        {
            //_filename = @"TeacherJournal.doc";
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.DefaultExt      = ".doc";
            saveFileDialog.OverwritePrompt = true;
            saveFileDialog.Title           = "Виберіть місце та назву файлу";
            saveFileDialog.Filter          = "Документ Microsoft Word 97–2003 (*.doc)|*.doc";
            if (saveFileDialog.ShowDialog() == false)
            {
                return;
            }
            // получаем выбранный файл
            _filename = saveFileDialog.FileName;

            WordApp        = new Word.Application();
            adoc           = WordApp.Documents.Add();
            rangeEndOfFile = adoc.Bookmarks.get_Item(ref oEndOfDoc).Range;

            Word.Application wrdApplication = new Word.Application();
            adoc.PageSetup.TopMargin    = wrdApplication.InchesToPoints(0.5f);
            adoc.PageSetup.BottomMargin = wrdApplication.InchesToPoints(0.5f);
            adoc.PageSetup.LeftMargin   = wrdApplication.InchesToPoints(0.5f);
            adoc.PageSetup.RightMargin  = wrdApplication.InchesToPoints(0.5f);
            //wordparagraphs = new Word.Paragraph[10];
        }
Exemple #2
0
        /// <summary>
        /// Formats document pre creation
        /// </summary>
        public override void CreateDocumentSpecificPreFormatting()
        {
            // set margins
            document.PageSetup.LeftMargin   = app.InchesToPoints(0.25F);
            document.PageSetup.TopMargin    = app.InchesToPoints(0.25F);
            document.PageSetup.BottomMargin = app.InchesToPoints(0.5F);
            document.PageSetup.RightMargin  = app.InchesToPoints(0.25F);

            // set header distance (for top)
            document.PageSetup.HeaderDistance = app.InchesToPoints(0.25F);

            // thread sleep to allow COM interop to catch up
            Thread.Sleep(100);
        }
        public void FormatNumbering()
        {
            //Microsoft.Office.Interop.Word.Application appWord = default(Microsoft.Office.Interop.Word.Application);
            //appWord = Interaction.GetObject(, "Word.Application");

            Microsoft.Office.Interop.Word.Application appWord = default(Microsoft.Office.Interop.Word.Application);
            appWord = Globals.ThisAddIn.Application;
            // _Document doc = appWord.ActiveDocument;


            //foreach (Microsoft.Office.Interop.Word.Paragraph paragraph in appWord.ActiveDocument.Paragraphs)
            //{
            //    Microsoft.Office.Interop.Word.Style _with1 = paragraph.get_Style() as Microsoft.Office.Interop.Word.Style;
            //    string styleName = _with1.NameLocal;
            //    string text = paragraph.Range.Text;
            //if (styleName == "Heading 1")
            //{
            var _with1 = appWord.ActiveDocument.Styles["Heading 1"];

            //var _with1 = appWord.ActiveDocument.Styles("Heading 1");  doubt
            //_with1.ParagraphFormat.Alignment = wdAlignParagraphJustify;
            //_with1.AutomaticallyUpdate = false;             doubt
            appWord.ActiveDocument.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphJustify;
            appWord.ActiveDocument.UpdateStylesOnOpen   = false;

            //.BaseStyle = "Normal"
            //_with1.NextParagraphStyle = "Heading 1";      doubt
            // appWord.ActiveDocument.Styles.Add("Heading 1");

            /*
             * _with1.ParagraphFormat.LeftIndent = appWord.InchesToPoints(0);
             * _with1.ParagraphFormat.RightIndent = appWord.InchesToPoints(0);
             * _with1.ParagraphFormat.Alignment = wdAlignParagraphJustify;
             * _with1.ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
             */
            object setStyle = "Heading 1";

            _with1.set_NextParagraphStyle(ref setStyle);

            _with1.ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
            _with1.ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
            _with1.ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
            _with1.ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);



            //.ParagraphFormat.LineSpacingRule = wdLineSpaceExactly
            //.ParagraphFormat.LineSpacing = 24
            //.ParagraphFormat.SpaceAfter = 0
            //.ParagraphFormat.KeepWithNext = False
            _with1.ParagraphFormat.OutlineLevel = WdOutlineLevel.wdOutlineLevel1;
            _with1.ParagraphFormat.TabStops.ClearAll();
            _with1.Font.AllCaps   = 0;
            _with1.Font.Bold      = 0;
            _with1.Font.Italic    = 0;
            _with1.Font.Underline = WdUnderline.wdUnderlineNone;

            // }
            //else if (styleName == "Heading 2")
            // {
            var _with2 = appWord.ActiveDocument.Styles["Heading 2"];

            appWord.ActiveDocument.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphJustify;
            appWord.ActiveDocument.UpdateStylesOnOpen   = false;
            object setStyle2 = "Heading 2";

            _with2.set_NextParagraphStyle(ref setStyle2);
            _with2.ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
            _with2.ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
            _with2.ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
            _with2.ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
            _with2.ParagraphFormat.OutlineLevel    = WdOutlineLevel.wdOutlineLevel2;
            _with2.ParagraphFormat.TabStops.ClearAll();
            _with2.Font.AllCaps   = 0;
            _with2.Font.Bold      = 0;
            _with2.Font.Italic    = 0;
            _with2.Font.Underline = WdUnderline.wdUnderlineNone;

            //}
            // else if (styleName == "Heading 3")
            //{
            var _with3 = appWord.ActiveDocument.Styles["Heading 3"];

            appWord.ActiveDocument.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphJustify;
            appWord.ActiveDocument.UpdateStylesOnOpen   = false;
            object setStyle3 = "Heading 3";

            _with3.set_NextParagraphStyle(ref setStyle3);
            _with3.ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
            _with3.ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
            _with3.ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
            _with3.ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
            _with3.ParagraphFormat.OutlineLevel    = WdOutlineLevel.wdOutlineLevel3;
            _with3.ParagraphFormat.TabStops.ClearAll();
            _with3.Font.AllCaps   = 0;
            _with3.Font.Bold      = 0;
            _with3.Font.Italic    = 0;
            _with3.Font.Underline = WdUnderline.wdUnderlineNone;

            // }
            // else if (styleName == "Heading 4")
            //{
            var _with4 = appWord.ActiveDocument.Styles["Heading 4"];

            appWord.ActiveDocument.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphJustify;
            appWord.ActiveDocument.UpdateStylesOnOpen   = false;
            object setStyle4 = "Heading 4";

            _with4.set_NextParagraphStyle(ref setStyle4);
            _with4.ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
            _with4.ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
            _with4.ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
            _with4.ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
            _with4.ParagraphFormat.OutlineLevel    = WdOutlineLevel.wdOutlineLevel4;
            _with4.ParagraphFormat.TabStops.ClearAll();
            _with4.Font.AllCaps   = 0;
            _with4.Font.Bold      = 0;
            _with4.Font.Italic    = 0;
            _with4.Font.Underline = WdUnderline.wdUnderlineNone;

            //}
            //else if (styleName == "Heading 5")
            //{
            var _with5 = appWord.ActiveDocument.Styles["Heading 5"];

            appWord.ActiveDocument.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphJustify;
            appWord.ActiveDocument.UpdateStylesOnOpen   = false;
            object setStyle5 = "Heading 5";

            _with5.set_NextParagraphStyle(ref setStyle5);
            _with5.ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
            _with5.ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
            _with5.ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
            _with5.ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
            _with5.ParagraphFormat.OutlineLevel    = WdOutlineLevel.wdOutlineLevel5;
            _with5.ParagraphFormat.TabStops.ClearAll();
            _with5.Font.AllCaps   = 0;
            _with5.Font.Bold      = 0;
            _with5.Font.Italic    = 0;
            _with5.Font.Underline = WdUnderline.wdUnderlineNone;
            //    }
            //  else if (styleName == "Heading 6")
            //{
            var _with6 = appWord.ActiveDocument.Styles["Heading 6"];

            appWord.ActiveDocument.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphJustify;
            appWord.ActiveDocument.UpdateStylesOnOpen   = false;
            object setStyle6 = "Heading 6";

            _with6.set_NextParagraphStyle(ref setStyle6);
            _with6.ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
            _with6.ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
            _with6.ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
            _with6.ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
            _with6.ParagraphFormat.OutlineLevel    = WdOutlineLevel.wdOutlineLevel6;
            _with6.ParagraphFormat.TabStops.ClearAll();
            _with6.Font.AllCaps   = 0;
            _with6.Font.Bold      = 0;
            _with6.Font.Italic    = 0;
            _with6.Font.Underline = WdUnderline.wdUnderlineNone;

            //}
            //    else if (styleName == "Heading 7")
            //  {
            var _with7 = appWord.ActiveDocument.Styles["Heading 7"];

            appWord.ActiveDocument.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphJustify;
            appWord.ActiveDocument.UpdateStylesOnOpen   = false;
            object setStyle7 = "Body Text";

            _with7.set_NextParagraphStyle(ref setStyle);
            _with7.ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
            _with7.ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
            _with7.ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
            _with7.ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
            _with7.ParagraphFormat.OutlineLevel    = WdOutlineLevel.wdOutlineLevel7;
            _with7.ParagraphFormat.TabStops.ClearAll();
            _with7.Font.AllCaps   = 0;
            _with7.Font.Bold      = 0;
            _with7.Font.Italic    = 0;
            _with7.Font.Underline = WdUnderline.wdUnderlineNone;
            //                }
            //      else if (styleName == "Heading 8")
            //    {
            var _with8 = appWord.ActiveDocument.Styles["Heading 8"];

            appWord.ActiveDocument.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphJustify;
            appWord.ActiveDocument.UpdateStylesOnOpen   = false;
            object setStyle8 = "Body Text";

            _with8.set_NextParagraphStyle(ref setStyle8);
            _with8.ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
            _with8.ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
            _with8.ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
            _with8.ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
            //_with1.ParagraphFormat.OutlineLevel = WdOutlineLevel.wdOutlineLevel7;
            _with8.ParagraphFormat.TabStops.ClearAll();
            _with8.Font.AllCaps   = 0;
            _with8.Font.Bold      = 0;
            _with8.Font.Italic    = 0;
            _with8.Font.Underline = WdUnderline.wdUnderlineNone;

            //}
            //  else if (styleName == "Heading 9")
            //{
            var _with9 = appWord.ActiveDocument.Styles["Heading 9"];

            appWord.ActiveDocument.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphJustify;
            appWord.ActiveDocument.UpdateStylesOnOpen   = false;
            object setStyle9 = "Body Text";

            _with9.set_NextParagraphStyle(ref setStyle9);
            _with9.ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
            _with9.ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
            _with9.ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
            _with9.ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
            //_wih1.ParagraphFormat.OutlineLevel = WdOutlineLevel.wdOutlineLevel7;
            _with9.ParagraphFormat.TabStops.ClearAll();
            _with9.Font.AllCaps   = 0;
            _with9.Font.Bold      = 0;
            _with9.Font.Italic    = 0;
            _with9.Font.Underline = WdUnderline.wdUnderlineNone;

            //}


            appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].Reset(6);

            //appWord.ListGalleries(wdOutlineNumberGallery).Reset 7
            var _withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1];

            _withList.NumberFormat      = "%1.";
            _withList.TrailingCharacter = WdTrailingCharacter.wdTrailingTab;
            _withList.NumberStyle       = WdListNumberStyle.wdListNumberStyleUppercaseLetter;
            _withList.NumberPosition    = appWord.InchesToPoints(1);
            _withList.Alignment         = WdListLevelAlignment.wdListLevelAlignLeft;
            _withList.TextPosition      = appWord.InchesToPoints(0);
            _withList.TabPosition       = appWord.InchesToPoints(1.5F);
            _withList.ResetOnHigher     = 0;
            _withList.StartAt           = 1;
            // var _with2 = _with1.Font;
            _withList.Font.Bold                = 0;
            _withList.Font.Italic              = 0;
            _withList.Font.AllCaps             = 0;
            _withList.Font.Size                = (float)WdConstants.wdUndefined;
            _withList.Font.Animation           = (WdAnimation)WdConstants.wdUndefined;
            _withList.Font.DoubleStrikeThrough = (int)WdUnderline.wdUnderlineNone;
            _withList.Font.Name                = "";
            _withList.Font.Underline           = WdUnderline.wdUnderlineNone;
            _withList.LinkedStyle              = "Heading 1";

            _withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2];
            _withList.NumberFormat      = "%2.";
            _withList.TrailingCharacter = WdTrailingCharacter.wdTrailingTab;
            _withList.NumberStyle       = WdListNumberStyle.wdListNumberStyleUppercaseLetter;
            _withList.NumberPosition    = appWord.InchesToPoints(1);
            _withList.Alignment         = WdListLevelAlignment.wdListLevelAlignLeft;
            _withList.TextPosition      = appWord.InchesToPoints(0);
            _withList.TabPosition       = appWord.InchesToPoints(1.5F);
            _withList.ResetOnHigher     = 1;
            _withList.StartAt           = 1;
            // var _with2 = _with1.Font;
            _withList.Font.Bold    = 0;
            _withList.Font.Italic  = 0;
            _withList.Font.AllCaps = 0;
            _withList.Font.Size    = (float)WdConstants.wdUndefined;
            //_withList.Font.Animation = (WdAnimation)WdConstants.wdUndefined;
            _withList.Font.DoubleStrikeThrough = (int)WdUnderline.wdUnderlineNone;
            _withList.Font.Name      = "";
            _withList.Font.Underline = WdUnderline.wdUnderlineNone;
            _withList.LinkedStyle    = "Heading 2";

            _withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3];
            _withList.NumberFormat      = "%3.";
            _withList.TrailingCharacter = WdTrailingCharacter.wdTrailingTab;
            _withList.NumberStyle       = WdListNumberStyle.wdListNumberStyleUppercaseLetter;
            _withList.NumberPosition    = appWord.InchesToPoints(1.5f);
            _withList.Alignment         = WdListLevelAlignment.wdListLevelAlignLeft;
            _withList.TextPosition      = appWord.InchesToPoints(0);
            _withList.TabPosition       = appWord.InchesToPoints(2.0F);
            _withList.ResetOnHigher     = 2;
            _withList.StartAt           = 1;
            // var _with2 = _with1.Font;
            _withList.Font.Bold                = 0;
            _withList.Font.Italic              = 0;
            _withList.Font.AllCaps             = 0;
            _withList.Font.Size                = (float)WdConstants.wdUndefined;
            _withList.Font.Animation           = (WdAnimation)WdConstants.wdUndefined;
            _withList.Font.DoubleStrikeThrough = (int)WdUnderline.wdUnderlineNone;
            _withList.Font.Name                = "";
            _withList.Font.Underline           = WdUnderline.wdUnderlineNone;
            _withList.LinkedStyle              = "Heading 3";

            _withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4];
            _withList.NumberFormat      = "%4.";
            _withList.TrailingCharacter = WdTrailingCharacter.wdTrailingTab;
            _withList.NumberStyle       = WdListNumberStyle.wdListNumberStyleUppercaseLetter;
            _withList.NumberPosition    = appWord.InchesToPoints(2);
            _withList.Alignment         = WdListLevelAlignment.wdListLevelAlignLeft;
            _withList.TextPosition      = appWord.InchesToPoints(0);
            _withList.TabPosition       = appWord.InchesToPoints(2.5F);
            _withList.ResetOnHigher     = 3;
            _withList.StartAt           = 1;
            // var _with2 = _with1.Font;
            _withList.Font.Bold                = 0;
            _withList.Font.Italic              = 0;
            _withList.Font.AllCaps             = 0;
            _withList.Font.Size                = (float)WdConstants.wdUndefined;
            _withList.Font.Animation           = (WdAnimation)WdConstants.wdUndefined;
            _withList.Font.DoubleStrikeThrough = (int)WdUnderline.wdUnderlineNone;
            _withList.Font.Name                = "";
            _withList.Font.Underline           = WdUnderline.wdUnderlineNone;
            _withList.LinkedStyle              = "Heading 4";

            _withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5];
            _withList.NumberFormat      = "%5.";
            _withList.TrailingCharacter = WdTrailingCharacter.wdTrailingTab;
            _withList.NumberStyle       = WdListNumberStyle.wdListNumberStyleUppercaseLetter;
            _withList.NumberPosition    = appWord.InchesToPoints(2);
            _withList.Alignment         = WdListLevelAlignment.wdListLevelAlignLeft;
            _withList.TextPosition      = appWord.InchesToPoints(0);
            _withList.TabPosition       = appWord.InchesToPoints(2.5F);
            _withList.ResetOnHigher     = 4;
            _withList.StartAt           = 1;
            // var _with2 = _with1.Font;
            _withList.Font.Bold                = 0;
            _withList.Font.Italic              = 0;
            _withList.Font.AllCaps             = 0;
            _withList.Font.Size                = (float)WdConstants.wdUndefined;
            _withList.Font.Animation           = (WdAnimation)WdConstants.wdUndefined;
            _withList.Font.DoubleStrikeThrough = (int)WdUnderline.wdUnderlineNone;
            _withList.Font.Name                = "";
            _withList.Font.Underline           = WdUnderline.wdUnderlineNone;
            _withList.LinkedStyle              = "Heading 5";

            _withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6];
            _withList.NumberFormat      = "%6.";
            _withList.TrailingCharacter = WdTrailingCharacter.wdTrailingTab;
            _withList.NumberStyle       = WdListNumberStyle.wdListNumberStyleUppercaseLetter;
            _withList.NumberPosition    = appWord.InchesToPoints(2.5f);
            _withList.Alignment         = WdListLevelAlignment.wdListLevelAlignLeft;
            _withList.TextPosition      = appWord.InchesToPoints(0);
            _withList.TabPosition       = appWord.InchesToPoints(3);
            _withList.ResetOnHigher     = 5;
            _withList.StartAt           = 1;
            // var _with2 = _with1.Font;
            _withList.Font.Bold                = 0;
            _withList.Font.Italic              = 0;
            _withList.Font.AllCaps             = 0;
            _withList.Font.Size                = (float)WdConstants.wdUndefined;
            _withList.Font.Animation           = (WdAnimation)WdConstants.wdUndefined;
            _withList.Font.DoubleStrikeThrough = (int)WdUnderline.wdUnderlineNone;
            _withList.Font.Name                = "";
            _withList.Font.Underline           = WdUnderline.wdUnderlineNone;
            _withList.LinkedStyle              = "Heading 6";

            _withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7];
            _withList.NumberFormat      = "%7.";
            _withList.TrailingCharacter = WdTrailingCharacter.wdTrailingTab;
            _withList.NumberStyle       = WdListNumberStyle.wdListNumberStyleUppercaseLetter;
            _withList.NumberPosition    = appWord.InchesToPoints(3);
            _withList.Alignment         = WdListLevelAlignment.wdListLevelAlignLeft;
            _withList.TextPosition      = appWord.InchesToPoints(1);
            _withList.TabPosition       = appWord.InchesToPoints(3.5f);
            _withList.ResetOnHigher     = 6;
            _withList.StartAt           = 1;
            // var _with2 = _with1.Font;
            _withList.Font.Bold                = 0;
            _withList.Font.Italic              = 0;
            _withList.Font.AllCaps             = (int)WdConstants.wdUndefined;
            _withList.Font.Size                = (float)WdConstants.wdUndefined;
            _withList.Font.Animation           = (WdAnimation)WdConstants.wdUndefined;
            _withList.Font.DoubleStrikeThrough = (int)WdUnderline.wdUnderlineNone;
            _withList.Font.Name                = "";
            _withList.Font.Underline           = WdUnderline.wdUnderlineNone;
            _withList.LinkedStyle              = "Heading 7";

            _withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8];
            _withList.NumberFormat      = "%8.";
            _withList.TrailingCharacter = WdTrailingCharacter.wdTrailingNone;

            _withList.NumberStyle       = WdListNumberStyle.wdListNumberStyleNone;
            _withList.TrailingCharacter = WdTrailingCharacter.wdTrailingTab;
            _withList.NumberStyle       = WdListNumberStyle.wdListNumberStyleUppercaseLetter;
            _withList.NumberPosition    = appWord.InchesToPoints(0);
            _withList.Alignment         = WdListLevelAlignment.wdListLevelAlignLeft;
            _withList.TextPosition      = appWord.InchesToPoints(0);
            _withList.TabPosition       = appWord.InchesToPoints(0);
            _withList.ResetOnHigher     = 7;
            _withList.StartAt           = 1;
            // var _with2 = _with1.Font;
            _withList.Font.Bold                = 0;
            _withList.Font.Italic              = 0;
            _withList.Font.AllCaps             = (int)WdConstants.wdUndefined;
            _withList.Font.Size                = (float)WdConstants.wdUndefined;
            _withList.Font.Animation           = (WdAnimation)WdConstants.wdUndefined;
            _withList.Font.DoubleStrikeThrough = (int)WdUnderline.wdUnderlineNone;
            _withList.Font.Name                = "";
            _withList.Font.Underline           = WdUnderline.wdUnderlineNone;
            _withList.LinkedStyle              = "Heading 8";

            _withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9];
            _withList.NumberFormat      = "%9.";
            _withList.TrailingCharacter = WdTrailingCharacter.wdTrailingNone;

            _withList.NumberStyle       = WdListNumberStyle.wdListNumberStyleLowercaseRoman;
            _withList.TrailingCharacter = WdTrailingCharacter.wdTrailingTab;
            _withList.NumberStyle       = WdListNumberStyle.wdListNumberStyleUppercaseLetter;
            _withList.NumberPosition    = appWord.InchesToPoints(0);
            _withList.Alignment         = WdListLevelAlignment.wdListLevelAlignLeft;
            _withList.TextPosition      = appWord.InchesToPoints(0);
            _withList.TabPosition       = appWord.InchesToPoints(0);
            _withList.ResetOnHigher     = 8;
            _withList.StartAt           = 1;
            // var _with2 = _with1.Font;
            _withList.Font.Bold                = 0;
            _withList.Font.Italic              = 0;
            _withList.Font.AllCaps             = (int)WdConstants.wdUndefined;
            _withList.Font.Underline           = (WdUnderline)WdConstants.wdUndefined;
            _withList.Font.Size                = (float)WdConstants.wdUndefined;
            _withList.Font.Animation           = (WdAnimation)WdConstants.wdUndefined;
            _withList.Font.DoubleStrikeThrough = (int)WdUnderline.wdUnderlineNone;
            _withList.Font.Name                = "";
            _withList.Font.Underline           = WdUnderline.wdUnderlineNone;
            _withList.LinkedStyle              = "Heading 9";
            // }
        }
        private void GenerateDocumentButton_Click(object sender, RoutedEventArgs e)
        {
            Word.Application objWord = new Word.Application
            {
                Visible = true
            };
            Word.Document objDoc;
            object        objMissing = System.Reflection.Missing.Value;

            objDoc = objWord.Documents.Add(ref objMissing, ref objMissing, ref objMissing, ref objMissing);
            Word.Range wordRan;
            wordRan = objDoc.Range(ref objMissing, ref objMissing);

            // Форматування
            wordRan.Font.Size = 14;
            wordRan.Font.Name = "Times New Roman";
            wordRan.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            wordRan.ParagraphFormat.LineSpacing     = 18;
            wordRan.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.5);
            wordRan.ParagraphFormat.SpaceAfter      = 0;
            wordRan.ParagraphFormat.SpaceBefore     = 0;

            // Генерація вмісту
            objWord.Selection.TypeText("В.3.10. Попереднє бойове розпорядження командира механізованого батальйону (оборона)\n\nКОМАНДИРУ ");
            objWord.Selection.TypeText(textBox1.Text);
            objWord.Selection.TypeText(".\nПОПЕРЕДНЄ БОЙОВЕ РОЗПОРЯДЖЕННЯ. КСП ");
            objWord.Selection.TypeText(textBox2.Text);
            objWord.Selection.TypeText(", ");
            objWord.Selection.TypeText(textBox3.Text);
            objWord.Selection.TypeText(". Карта ");
            objWord.Selection.TypeText(textBox4.Text);
            objWord.Selection.TypeText(", видання ");
            objWord.Selection.TypeText(textBox5.Text);
            objWord.Selection.TypeText(".\n1. Підрозділи противника ");
            objWord.Selection.TypeText(textBox6.Text);
            objWord.Selection.TypeText(" (відійшли або вийшли) на рубіж ");
            objWord.Selection.TypeText(textBox7.Text);
            objWord.Selection.TypeText(", закріпилися і його утримують.\nЧастини, що висуваються з резерву, зосереджуються в районі ");
            objWord.Selection.TypeText(textBox8.Text);
            objWord.Selection.TypeText(", наступ їх можливий ");
            objWord.Selection.TypeText(textBox9.Text);
            objWord.Selection.TypeText(".\nПраворуч переходить до оборони ");
            objWord.Selection.TypeText(textBox10.Text);
            objWord.Selection.TypeText(" мр сусідньої омбр із завданням обороняти опорний пункт ");
            objWord.Selection.TypeText(textBox11.Text);
            objWord.Selection.TypeText(" і не допустити прориву противника в напрямку ");
            objWord.Selection.TypeText(textBox12.Text);
            objWord.Selection.TypeText(".\nРозмежувальна лінія із сусідом праворуч ");
            objWord.Selection.TypeText(textBox13.Text);
            objWord.Selection.TypeText(".\nЛіворуч ");
            objWord.Selection.TypeText(textBox14.Text);
            objWord.Selection.TypeText(" мр нашої омбр переходить до оборони опорного пункту ");
            objWord.Selection.TypeText(textBox15.Text);
            objWord.Selection.TypeText(" і з завданням не допустити прориву противника в напрямку ");
            objWord.Selection.TypeText(textBox16.Text);
            objWord.Selection.TypeText(".\nРозмежувальна лінія із сусідом ліворуч ");
            objWord.Selection.TypeText(textBox17.Text);
            objWord.Selection.TypeText(".\nРекогносцировку проводжу з ");
            objWord.Selection.TypeText(textBox18.Text);
            objWord.Selection.TypeText(", де віддам бойовий наказ.");

            try
            {
                Directory.CreateDirectory(Constant.RootToSaveGenerated);
                objDoc.SaveAs($"{Constant.RootToSaveGenerated}Form 3_10 {Constant.Date}");
                string path = objDoc.FullName;

                var dialog = new DialogPrintDocument("Підтвердити друк?");
                dialog.ShowDialog();
                if (dialog.Cancelled != true)
                {
                    objDoc.PrintOut();
                }

                objDoc.Close();
                objWord.Quit();

                var order = orderService.AddOrder(path, hashService.GetHash());
                if (order != null)
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Донесення занесено до бази даних!");
                    messageBox.ShowDialog();
                }
                else
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Сталася помилка! Донесення не занесено до бази даних!");
                    messageBox.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                CustomMessageBox messageBox = new CustomMessageBox(ex.Message);
                messageBox.ShowDialog();
            }
        }
Exemple #5
0
        private static void AutomateWordImpl()
        {
            object missing = Type.Missing;
            object oEndOfDoc = @"\endofdoc";    // 预先定义的书签
            object notTrue = false;

            try
            {
                // 创建一个Microsoft Word实例并令其不可见

                Word.Application oWord = new Word.Application();
                oWord.Visible = false;
                Console.WriteLine("Word.Application is started");

                // 创建一个新的文档

                Word.Document oDoc = oWord.Documents.Add(ref missing, ref missing,
                    ref missing, ref missing);

                // 插入段落

                Console.WriteLine("Insert a paragraph");

                Word.Paragraph oPara = oDoc.Paragraphs.Add(ref missing);
                oPara.Range.Text = "Heading 1";
                oPara.Range.Font.Bold = 1;
                oPara.Range.InsertParagraphAfter();

                // 插入表格

                Console.WriteLine("Insert a table");

                Word.Range oBookmarkRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                Word.Table oTable = oDoc.Tables.Add(oBookmarkRng, 5, 2,
                    ref missing, ref missing);
                oTable.Range.ParagraphFormat.SpaceAfter = 6;
                for (int r = 1; r <= 5; r++)
                {
                    for (int c = 1; c <= 2; c++)
                    {
                        oTable.Cell(r, c).Range.Text = "r" + r + "c" + c;
                    }
                }

                // 改变列1和列2的宽度
                oTable.Columns[1].Width = oWord.InchesToPoints(2);
                oTable.Columns[2].Width = oWord.InchesToPoints(3);

                // 将文档保存为.docx文件并关闭

                Console.WriteLine("Save and close the document");

                object fileName = Path.GetDirectoryName(
                    Assembly.GetExecutingAssembly().Location) + "\\Sample2.docx";
                object fileFormat = Word.WdSaveFormat.wdFormatXMLDocument;
                oDoc.SaveAs(ref fileName, ref fileFormat, ref missing,
                    ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref missing, ref missing,
                    ref missing);
                ((Word._Document)oDoc).Close(ref missing, ref missing,
                    ref missing);

                // 退出Word应用程序

                Console.WriteLine("Quit the Word application");
                ((Word._Application)oWord).Quit(ref notTrue, ref missing,
                    ref missing);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Solution2.AutomateWord throws the error: {0}",
                       ex.Message);
            }
        }
Exemple #6
0
        public static string TestWord()
        {
            string report = "Chưa kiểm tra Word.";
            //kt word
            object oMissing  = System.Reflection.Missing.Value;
            object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */

            Word._Application oWord;
            Word._Document    oDoc;
            oWord         = new Word.Application();
            oWord.Visible = true;
            oDoc          = oWord.Documents.Add(ref oMissing, ref oMissing,
                                                ref oMissing, ref oMissing);

            //Insert a paragraph at the beginning of the document.
            Word.Paragraph oPara1;
            oPara1                   = oDoc.Content.Paragraphs.Add(ref oMissing);
            oPara1.Range.Text        = "hello word ";
            oPara1.Range.Font.Bold   = 1;
            oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.
            oPara1.Range.InsertParagraphAfter();
            //Insert a paragraph at the end of the document.
            Word.Paragraph oPara2;
            object         oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;

            oPara2                   = oDoc.Content.Paragraphs.Add(ref oRng);
            oPara2.Range.Text        = "xin chao";
            oPara2.Format.SpaceAfter = 6;
            oPara2.Range.InsertParagraphAfter();
            //Insert another paragraph.
            Word.Paragraph oPara3;
            oRng                     = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oPara3                   = oDoc.Content.Paragraphs.Add(ref oRng);
            oPara3.Range.Text        = "Bây giờ đây là một bảng:";
            oPara3.Range.Font.Bold   = 0;
            oPara3.Format.SpaceAfter = 24;
            oPara3.Range.InsertParagraphAfter();



            //Insert a 3 x 5 table, fill it with data, and make the first row
            //bold and italic.
            Word.Table oTable;
            Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oTable = oDoc.Tables.Add(wrdRng, 3, 5, ref oMissing, ref oMissing);
            oTable.Range.ParagraphFormat.SpaceAfter = 6;
            int    r, c;
            string strText;

            for (r = 1; r <= 3; r++)
            {
                for (c = 1; c <= 5; c++)
                {
                    strText = "r" + r + "c" + c;
                    oTable.Cell(r, c).Range.Text = strText;
                }
            }
            oTable.Rows[1].Range.Font.Bold   = 1;
            oTable.Rows[1].Range.Font.Italic = 1;

            //Add some text after the table.
            Word.Paragraph oPara4;
            oRng   = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oPara4 = oDoc.Content.Paragraphs.Add(ref oRng);
            oPara4.Range.InsertParagraphBefore();
            oPara4.Range.Text        = "bang khac:";
            oPara4.Format.SpaceAfter = 24;
            oPara4.Range.InsertParagraphAfter();

            //Insert a 5 x 2 table, fill it with data, and change the column widths.
            wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oTable = oDoc.Tables.Add(wrdRng, 5, 2, ref oMissing, ref oMissing);
            oTable.Range.ParagraphFormat.SpaceAfter = 6;
            for (r = 1; r <= 5; r++)
            {
                for (c = 1; c <= 2; c++)
                {
                    strText = "r" + r + "c" + c;
                    oTable.Cell(r, c).Range.Text = strText;
                }
            }
            oTable.Columns[1].Width = oWord.InchesToPoints(2); //Change width of columns 1 & 2
            oTable.Columns[2].Width = oWord.InchesToPoints(3);

            //Keep inserting text. When you get to 7 inches from top of the
            //document, insert a hard page break.
            object oPos;
            double dPos = oWord.InchesToPoints(7);

            oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range.InsertParagraphAfter();
            do
            {
                wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                wrdRng.ParagraphFormat.SpaceAfter = 6;
                wrdRng.InsertAfter("A line of text");
                wrdRng.InsertParagraphAfter();
                oPos = wrdRng.get_Information
                           (Word.WdInformation.wdVerticalPositionRelativeToPage);
            }while (dPos >= Convert.ToDouble(oPos));
            object oCollapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
            object oPageBreak   = Word.WdBreakType.wdPageBreak;

            wrdRng.Collapse(ref oCollapseEnd);
            wrdRng.InsertBreak(ref oPageBreak);
            wrdRng.Collapse(ref oCollapseEnd);
            wrdRng.InsertAfter("bieu do:");
            wrdRng.InsertParagraphAfter();

            //Insert a chart.
            Word.InlineShape oShape;
            object           oClassType = "MSGraph.Chart.8";

            wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oShape = wrdRng.InlineShapes.AddOLEObject(ref oClassType, ref oMissing,
                                                      ref oMissing, ref oMissing, ref oMissing,
                                                      ref oMissing, ref oMissing, ref oMissing);

            //Demonstrate use of late bound oChart and oChartApp objects to
            //manipulate the chart object with MSGraph.
            object oChart;
            object oChartApp;

            oChart    = oShape.OLEFormat.Object;
            oChartApp = oChart.GetType().InvokeMember("Application",
                                                      BindingFlags.GetProperty, null, oChart, null);

            //Change the chart type to Line.
            object[] Parameters = new Object[1];
            Parameters[0] = 4; //xlLine = 4
            oChart.GetType().InvokeMember("ChartType", BindingFlags.SetProperty,
                                          null, oChart, Parameters);

            //Update the chart image and quit MSGraph.
            oChartApp.GetType().InvokeMember("Update",
                                             BindingFlags.InvokeMethod, null, oChartApp, null);
            oChartApp.GetType().InvokeMember("Quit",
                                             BindingFlags.InvokeMethod, null, oChartApp, null);
            //... If desired, you can proceed from here using the Microsoft Graph
            //Object model on the oChart and oChartApp objects to make additional
            //changes to the chart.

            //Set the width of the chart.
            oShape.Width  = oWord.InchesToPoints(6.25f);
            oShape.Height = oWord.InchesToPoints(3.57f);

            //Add text after the chart.
            wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            wrdRng.InsertParagraphAfter();
            wrdRng.InsertAfter("THE END.");
            oDoc.SaveAs("MyFile.doc", 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);
            oWord.Quit();
            report += "\nĐÃ KIỂM TRA Word";
            return(report);
        }
Exemple #7
0
        private static void AutomateWordImpl()
        {
            object missing   = Type.Missing;
            object oEndOfDoc = @"\endofdoc";    // A predefined bookmark
            object notTrue   = false;

            try
            {
                // Create an instance of Microsoft Excel and make it invisible.
                Word.Application oWord = new Word.Application();
                oWord.Visible = false;
                Console.WriteLine("Word.Application is started");

                // Create a new Document and add it to document collection.
                Word.Document oDoc = oWord.Documents.Add(ref missing, ref missing,
                                                         ref missing, ref missing);

                // Insert a paragraph.
                Console.WriteLine("Insert a paragraph");

                Word.Paragraph oPara = oDoc.Paragraphs.Add(ref missing);
                oPara.Range.Text      = "Heading 1";
                oPara.Range.Font.Bold = 1;
                oPara.Range.InsertParagraphAfter();

                // Insert a table.
                Console.WriteLine("Insert a table");

                Word.Range oBookmarkRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                Word.Table oTable       = oDoc.Tables.Add(oBookmarkRng, 5, 2,
                                                          ref missing, ref missing);
                oTable.Range.ParagraphFormat.SpaceAfter = 6;
                for (int r = 1; r <= 5; r++)
                {
                    for (int c = 1; c <= 2; c++)
                    {
                        oTable.Cell(r, c).Range.Text = "r" + r + "c" + c;
                    }
                }

                // Change width of columns 1 & 2
                oTable.Columns[1].Width = oWord.InchesToPoints(2);
                oTable.Columns[2].Width = oWord.InchesToPoints(3);

                // Save the document as a docx file and close it.
                Console.WriteLine("Save and close the document");

                object fileName = Path.GetDirectoryName(
                    Assembly.GetExecutingAssembly().Location) + "\\Sample2.docx";
                object fileFormat = Word.WdSaveFormat.wdFormatXMLDocument;

                // Saves the document with a new name or format.
                // Some of the arguments for this method correspond to
                // the options in the Save As dialog box.
                // For details,please refer to
                // :http://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.document.saveas(VS.80).aspx
                oDoc.SaveAs(ref fileName, ref fileFormat, ref missing,
                            ref missing, ref missing, ref missing, ref missing,
                            ref missing, ref missing, ref missing, ref missing,
                            ref missing, ref missing, ref missing, ref missing,
                            ref missing);
                ((Word._Document)oDoc).Close(ref missing, ref missing,
                                             ref missing);

                // Quit the Word application.
                Console.WriteLine("Quit the Word application");
                ((Word._Application)oWord).Quit(ref notTrue, ref missing,
                                                ref missing);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Solution2.AutomateWord throws the error: {0}",
                                  ex.Message);
            }
        }
Exemple #8
0
        private static void AutomateWordImpl()
        {
            object missing   = Type.Missing;
            object oEndOfDoc = @"\endofdoc";    // 预先定义的书签
            object notTrue   = false;

            try
            {
                // 创建一个Microsoft Word实例并令其不可见

                Word.Application oWord = new Word.Application();
                oWord.Visible = false;
                Console.WriteLine("Word.Application is started");

                // 创建一个新的文档

                Word.Document oDoc = oWord.Documents.Add(ref missing, ref missing,
                                                         ref missing, ref missing);

                // 插入段落

                Console.WriteLine("Insert a paragraph");

                Word.Paragraph oPara = oDoc.Paragraphs.Add(ref missing);
                oPara.Range.Text      = "Heading 1";
                oPara.Range.Font.Bold = 1;
                oPara.Range.InsertParagraphAfter();

                // 插入表格

                Console.WriteLine("Insert a table");

                Word.Range oBookmarkRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                Word.Table oTable       = oDoc.Tables.Add(oBookmarkRng, 5, 2,
                                                          ref missing, ref missing);
                oTable.Range.ParagraphFormat.SpaceAfter = 6;
                for (int r = 1; r <= 5; r++)
                {
                    for (int c = 1; c <= 2; c++)
                    {
                        oTable.Cell(r, c).Range.Text = "r" + r + "c" + c;
                    }
                }

                // 改变列1和列2的宽度
                oTable.Columns[1].Width = oWord.InchesToPoints(2);
                oTable.Columns[2].Width = oWord.InchesToPoints(3);

                // 将文档保存为.docx文件并关闭

                Console.WriteLine("Save and close the document");

                object fileName = Path.GetDirectoryName(
                    Assembly.GetExecutingAssembly().Location) + "\\Sample2.docx";
                object fileFormat = Word.WdSaveFormat.wdFormatXMLDocument;
                oDoc.SaveAs(ref fileName, ref fileFormat, ref missing,
                            ref missing, ref missing, ref missing, ref missing,
                            ref missing, ref missing, ref missing, ref missing,
                            ref missing, ref missing, ref missing, ref missing,
                            ref missing);
                ((Word._Document)oDoc).Close(ref missing, ref missing,
                                             ref missing);

                // 退出Word应用程序

                Console.WriteLine("Quit the Word application");
                ((Word._Application)oWord).Quit(ref notTrue, ref missing,
                                                ref missing);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Solution2.AutomateWord throws the error: {0}",
                                  ex.Message);
            }
        }
Exemple #9
0
        public static void AddSimpleChart(Word.Document WordDoc, Word.Application WordApp,
                                          Object oEndOfDoc, string[,] data)
        {
            //插入chart
            object oMissing = System.Reflection.Missing.Value;

            Word.InlineShape oShape;
            object           oClassType = "MSGraph.Chart.8";

            Word.Range wrdRng = WordDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oShape = wrdRng.InlineShapes.AddOLEObject(ref oClassType, ref oMissing,
                                                      ref oMissing, ref oMissing, ref oMissing,
                                                      ref oMissing, ref oMissing, ref oMissing);
            //Demonstrate use of late bound oChart and oChartApp objects to
            //manipulate the chart object with MSGraph.
            object oChart;
            object oChartApp;

            oChart    = oShape.OLEFormat.Object;
            oChartApp = oChart.GetType().InvokeMember("Application", BindingFlags.GetProperty,
                                                      null, oChart, null);
            //Change the chart type
            Chart objChart = (Chart)oShape.OLEFormat.Object;

            //objChart.ChartType = XlChartType.xlColumnClustered;
            objChart.ChartType = XlChartType.xlLine;
            objChart.ChartArea.Border.LineStyle           = XlLineStyle.xlDash;
            objChart.ChartArea.Fill.BackColor.SchemeColor = 28;


            Series s = (Series)objChart.SeriesCollection(1);



            objChart.ChartArea.Border.ColorIndex          = 5;
            objChart.ChartArea.Fill.BackColor.SchemeColor = 1;



            //绑定数据
            Microsoft.Office.Interop.Graph.DataSheet dataSheet;
            dataSheet = objChart.Application.DataSheet;
            dataSheet.Cells.ClearContents();
            int rownum    = data.GetLength(0);
            int columnnum = data.GetLength(1);

            for (int i = 1; i <= rownum; i++)
            {
                for (int j = 1; j <= columnnum; j++)
                {
                    dataSheet.Cells[i, j] = data[i - 1, j - 1];
                }
            }

            objChart.Application.Update();
            objChart.Application.Quit();

            //oChartApp.GetType().InvokeMember("Update",
            //    BindingFlags.InvokeMethod, null, oChartApp, null);
            //oChartApp.GetType().InvokeMember("Quit",
            //    BindingFlags.InvokeMethod, null, oChartApp, null);
            //设置大小
            oShape.Width  = WordApp.InchesToPoints(6.25f);
            oShape.Height = WordApp.InchesToPoints(3.57f);
        }
        private void GenerateDocumentButton_Click(object sender, RoutedEventArgs e)
        {
            object objMissing      = System.Reflection.Missing.Value;
            object objEndOfDocFlag = "\\endofdoc";

            Word.Application objWord = new Word.Application
            {
                Visible = true
            };
            Word.Document objDoc = objWord.Documents.Add(ref objMissing, ref objMissing, ref objMissing, ref objMissing);

            // Перший параграф, форматування
            Word.Range par1 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par1.Font.Size = 14;
            par1.Font.Name = "Times New Roman";
            par1.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par1.ParagraphFormat.LineSpacing     = 18;
            par1.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par1.ParagraphFormat.SpaceAfter      = 0;
            par1.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par1.Text = "В.3.4. Розрахунок часу роботи командира механізованого батальйону (марш)";
            par1.InsertParagraphAfter();
            par1.InsertParagraphAfter();

            // Другий параграф, форматування
            Word.Range par2 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par2.Font.Size = 14;
            par2.Font.Name = "Times New Roman";
            par2.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par2.ParagraphFormat.LineSpacing     = 18;
            par2.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par2.ParagraphFormat.SpaceAfter      = 0;
            par2.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par2.Text = "Задача на марш отримана в " + textBox1.Text + ".";
            par2.InsertParagraphAfter();

            // Третій параграф, форматування
            Word.Range par3 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par3.Font.Size = 14;
            par3.Font.Name = "Times New Roman";
            par3.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par3.ParagraphFormat.LineSpacing     = 18;
            par3.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par3.ParagraphFormat.SpaceAfter      = 0;
            par3.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par3.Text = "Готовність до маршу " + textBox2.Text + ".";
            par3.InsertParagraphAfter();

            // Четвертий параграф, форматування
            Word.Range par4 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par4.Font.Size = 14;
            par4.Font.Name = "Times New Roman";
            par4.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par4.ParagraphFormat.LineSpacing     = 18;
            par4.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par4.ParagraphFormat.SpaceAfter      = 0;
            par4.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par4.Text = "Вихідний пункт пройти " + textBox3.Text + ".";
            par4.InsertParagraphAfter();

            // П'ятий параграф, форматування
            Word.Range par5 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par5.Font.Size = 14;
            par5.Font.Name = "Times New Roman";
            par5.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par5.ParagraphFormat.LineSpacing     = 18;
            par5.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par5.ParagraphFormat.SpaceAfter      = 0;
            par5.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par5.Text = "Усього мається часу на підготовку до маршу " + textBox4.Text + " у тому числі світлого " + textBox5.Text + ".";
            par5.InsertParagraphAfter();

            // Шостий параграф, форматування
            Word.Range par6 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par6.Font.Size = 14;
            par6.Font.Name = "Times New Roman";
            par6.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            par6.ParagraphFormat.LineSpacing     = 12;
            par6.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par6.ParagraphFormat.SpaceAfter      = 1;
            // Генерація вмісту
            par6.Text = "Наявний час розподілити";
            par6.InsertParagraphAfter();

            // Таблиця, форматування
            Word.Range par7 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            Word.Table tableObj;
            tableObj = objDoc.Tables.Add(par7, 18, 4, ref objMissing, ref objMissing);
            tableObj.Range.Font.Name = "Times New Roman";
            tableObj.Range.Font.Size = 12;
            tableObj.Range.ParagraphFormat.LineSpacing = 12;
            tableObj.Borders.InsideLineStyle           = Word.WdLineStyle.wdLineStyleSingle;
            tableObj.Borders.OutsideLineStyle          = Word.WdLineStyle.wdLineStyleSingle;

            tableObj.Cell(1, 1).Merge(tableObj.Cell(2, 1));
            tableObj.Cell(1, 2).Merge(tableObj.Cell(2, 2));
            tableObj.Cell(1, 3).Merge(tableObj.Cell(1, 4));

            tableObj.Cell(1, 1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(1, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(1, 2).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(1, 2).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(1, 3).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(1, 3).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(2, 3).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(2, 3).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(2, 4).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(2, 4).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;

            for (int i = 3; i <= 18; i++)
            {
                tableObj.Cell(i, 1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
                tableObj.Cell(i, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            }

            for (int i = 3; i <= 18; i++)
            {
                for (int j = 2; j <= 4; j++)
                {
                    tableObj.Cell(i, j).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    tableObj.Cell(i, j).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
                }
            }

            tableObj.Cell(1, 3).Range.ParagraphFormat.SpaceAfter = 8;

            // Таблиця, генерація вмісту
            tableObj.Cell(1, 1).Range.Text  = "Заходи, що проводяться";
            tableObj.Cell(1, 2).Range.Text  = "Загальна кількість часу (хв)";
            tableObj.Cell(1, 3).Range.Text  = "Час роботи";
            tableObj.Cell(2, 3).Range.Text  = "Початок\n(час, дата)";
            tableObj.Cell(2, 4).Range.Text  = "Кінець\n(час, дата)";
            tableObj.Cell(3, 1).Range.Text  = "З'ясування задачі";
            tableObj.Cell(3, 2).Range.Text  = textBox6.Text;
            tableObj.Cell(3, 3).Range.Text  = textBox7.Text;
            tableObj.Cell(3, 4).Range.Text  = textBox8.Text;
            tableObj.Cell(4, 1).Range.Text  = "Ознайомлення підлеглих з отриманою задачею і віддача вказівок по підготовці до маршу";
            tableObj.Cell(4, 2).Range.Text  = textBox9.Text;
            tableObj.Cell(4, 3).Range.Text  = textBox10.Text;
            tableObj.Cell(4, 4).Range.Text  = textBox11.Text;
            tableObj.Cell(5, 1).Range.Text  = "Оцінка обстановки і розрахунок маршу";
            tableObj.Cell(5, 2).Range.Text  = textBox12.Text;
            tableObj.Cell(5, 3).Range.Text  = textBox13.Text;
            tableObj.Cell(5, 4).Range.Text  = textBox14.Text;
            tableObj.Cell(6, 1).Range.Text  = "Прийняття рішення й оформлення його на карті";
            tableObj.Cell(6, 2).Range.Text  = textBox15.Text;
            tableObj.Cell(6, 3).Range.Text  = textBox16.Text;
            tableObj.Cell(6, 4).Range.Text  = textBox17.Text;
            tableObj.Cell(7, 1).Range.Text  = "Доповідь рішення командиру мбр";
            tableObj.Cell(7, 2).Range.Text  = textBox18.Text;
            tableObj.Cell(7, 3).Range.Text  = textBox19.Text;
            tableObj.Cell(7, 4).Range.Text  = textBox20.Text;
            tableObj.Cell(8, 1).Range.Text  = "Віддача бойового наказу, організація взаємодії";
            tableObj.Cell(8, 2).Range.Text  = textBox21.Text;
            tableObj.Cell(8, 3).Range.Text  = textBox22.Text;
            tableObj.Cell(8, 4).Range.Text  = textBox23.Text;
            tableObj.Cell(9, 1).Range.Text  = "Віддача вказівок по забезпеченню маршу і по виховній роботі";
            tableObj.Cell(9, 2).Range.Text  = textBox24.Text;
            tableObj.Cell(9, 3).Range.Text  = textBox25.Text;
            tableObj.Cell(9, 4).Range.Text  = textBox26.Text;
            tableObj.Cell(10, 1).Range.Text = "Організація зв'язку і управління";
            tableObj.Cell(10, 2).Range.Text = textBox27.Text;
            tableObj.Cell(10, 3).Range.Text = textBox28.Text;
            tableObj.Cell(10, 4).Range.Text = textBox29.Text;
            tableObj.Cell(11, 1).Range.Text = "Складання заявки на матеріальне забезпечення підрозділів батальйону";
            tableObj.Cell(11, 2).Range.Text = textBox30.Text;
            tableObj.Cell(11, 3).Range.Text = textBox31.Text;
            tableObj.Cell(11, 4).Range.Text = textBox32.Text;
            tableObj.Cell(12, 1).Range.Text = "Складання донесення про бойовий і чисельний склад батальйону";
            tableObj.Cell(12, 2).Range.Text = textBox33.Text;
            tableObj.Cell(12, 3).Range.Text = textBox34.Text;
            tableObj.Cell(12, 4).Range.Text = textBox35.Text;
            tableObj.Cell(13, 1).Range.Text = "Складання донесення про дози радіаційного опромінення особового складу";
            tableObj.Cell(13, 2).Range.Text = textBox36.Text;
            tableObj.Cell(13, 3).Range.Text = textBox37.Text;
            tableObj.Cell(13, 4).Range.Text = textBox38.Text;
            tableObj.Cell(14, 1).Range.Text = "Оформлення документів на організацію маршу";
            tableObj.Cell(14, 2).Range.Text = textBox39.Text;
            tableObj.Cell(14, 3).Range.Text = textBox40.Text;
            tableObj.Cell(14, 4).Range.Text = textBox41.Text;
            tableObj.Cell(15, 1).Range.Text = "Поповнення запасів матеріальних засобів";
            tableObj.Cell(15, 2).Range.Text = textBox42.Text;
            tableObj.Cell(15, 3).Range.Text = textBox43.Text;
            tableObj.Cell(15, 4).Range.Text = textBox44.Text;
            tableObj.Cell(16, 1).Range.Text = "Проведення заходів щодо виховної роботи";
            tableObj.Cell(16, 2).Range.Text = textBox45.Text;
            tableObj.Cell(16, 3).Range.Text = textBox46.Text;
            tableObj.Cell(16, 4).Range.Text = textBox47.Text;
            tableObj.Cell(17, 1).Range.Text = "Контроль і допомога підрозділам у підготовці до маршу";
            tableObj.Cell(17, 2).Range.Text = textBox48.Text;
            tableObj.Cell(17, 3).Range.Text = textBox49.Text;
            tableObj.Cell(17, 4).Range.Text = textBox50.Text;
            tableObj.Cell(18, 1).Range.Text = "Доповідь про готовність до маршу";
            tableObj.Cell(18, 2).Range.Text = textBox51.Text;
            tableObj.Cell(18, 3).Range.Text = textBox52.Text;
            tableObj.Cell(18, 4).Range.Text = textBox53.Text;
            par7.InsertParagraphAfter();

            // Восьмий параграф, форматування
            Word.Range par8 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par8.Font.Size = 14;
            par8.Font.Name = "Times New Roman";
            par8.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par8.ParagraphFormat.LineSpacing     = 18;
            par8.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par8.ParagraphFormat.SpaceBefore     = 20;
            // Генерація вмісту
            par8.Text = "Начальник штабу " + textBox54.Text + " мб";
            par8.InsertParagraphAfter();

            try
            {
                Directory.CreateDirectory(Constant.RootToSaveGenerated);
                objDoc.SaveAs($"{Constant.RootToSaveGenerated}Form 3_4 {Constant.Date}");
                string path = objDoc.FullName;

                var dialog = new DialogPrintDocument("Підтвердити друк?");
                dialog.ShowDialog();
                if (dialog.Cancelled != true)
                {
                    objDoc.PrintOut();
                }

                objDoc.Close();
                objWord.Quit();

                var order = orderService.AddOrder(path, hashService.GetHash());
                if (order != null)
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Донесення занесено до бази даних!");
                    messageBox.ShowDialog();
                }
                else
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Сталася помилка! Донесення не занесено до бази даних!");
                    messageBox.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                CustomMessageBox messageBox = new CustomMessageBox(ex.Message);
                messageBox.ShowDialog();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            object oMissing = System.Reflection.Missing.Value;
            object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */

            //Start Word and create a new document.
            Word._Application oWord;
            Word._Document oDoc;
            oWord = new Word.Application();
            oWord.Visible = true;
            oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
                ref oMissing, ref oMissing);

            //Insert a paragraph at the beginning of the document.
            Word.Paragraph oPara1;
            oPara1 = oDoc.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();

            //Insert a paragraph at the end of the document.
            Word.Paragraph oPara2;
            object oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oPara2 = oDoc.Content.Paragraphs.Add(ref oRng);
            oPara2.Range.Text = "Heading 2";
            oPara2.Format.SpaceAfter = 6;
            oPara2.Range.InsertParagraphAfter();

            //Insert another paragraph.
            Word.Paragraph oPara3;
            oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oPara3 = oDoc.Content.Paragraphs.Add(ref oRng);
            oPara3.Range.Text = "This is a sentence of normal text. Now here is a table:";
            oPara3.Range.Font.Bold = 0;
            oPara3.Format.SpaceAfter = 24;
            oPara3.Range.InsertParagraphAfter();

            //Insert a 3 x 5 table, fill it with data, and make the first row
            //bold and italic.
            Word.Table oTable;
            Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oTable = oDoc.Tables.Add(wrdRng, 3, 5, ref oMissing, ref oMissing);
            oTable.Range.ParagraphFormat.SpaceAfter = 6;
            int r, c;
            string strText;
            for (r = 1; r <= 3; r++)
                for (c = 1; c <= 5; c++)
                {
                    strText = "r" + r + "c" + c;
                    oTable.Cell(r, c).Range.Text = strText;
                }
            oTable.Rows[1].Range.Font.Bold = 1;
            oTable.Rows[1].Range.Font.Italic = 1;

            //Add some text after the table.
            Word.Paragraph oPara4;
            oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oPara4 = oDoc.Content.Paragraphs.Add(ref oRng);
            oPara4.Range.InsertParagraphBefore();
            oPara4.Range.Text = "And here's another table:";
            oPara4.Format.SpaceAfter = 24;
            oPara4.Range.InsertParagraphAfter();

            //Insert a 5 x 2 table, fill it with data, and change the column widths.
            wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oTable = oDoc.Tables.Add(wrdRng, 5, 2, ref oMissing, ref oMissing);
            oTable.Range.ParagraphFormat.SpaceAfter = 6;
            for (r = 1; r <= 5; r++)
                for (c = 1; c <= 2; c++)
                {
                    strText = "r" + r + "c" + c;
                    oTable.Cell(r, c).Range.Text = strText;
                }
            oTable.Columns[1].Width = oWord.InchesToPoints(2); //Change width of columns 1 & 2
            oTable.Columns[2].Width = oWord.InchesToPoints(3);

            //Keep inserting text. When you get to 7 inches from top of the
            //document, insert a hard page break.
            object oPos;
            double dPos = oWord.InchesToPoints(7);
            oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range.InsertParagraphAfter();
            do
            {
                wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                wrdRng.ParagraphFormat.SpaceAfter = 6;
                wrdRng.InsertAfter("A line of text");
                wrdRng.InsertParagraphAfter();
                oPos = wrdRng.get_Information
                               (Word.WdInformation.wdVerticalPositionRelativeToPage);
            }
            while (dPos >= Convert.ToDouble(oPos));
            object oCollapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
            object oPageBreak = Word.WdBreakType.wdPageBreak;
            wrdRng.Collapse(ref oCollapseEnd);
            wrdRng.InsertBreak(ref oPageBreak);
            wrdRng.Collapse(ref oCollapseEnd);
            wrdRng.InsertAfter("We're now on page 2. Here's my chart:");
            wrdRng.InsertParagraphAfter();

            //Insert a chart.
            Word.InlineShape oShape;
            object oClassType = "MSGraph.Chart.8";
            wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oShape = wrdRng.InlineShapes.AddOLEObject(ref oClassType, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing);

            //Demonstrate use of late bound oChart and oChartApp objects to
            //manipulate the chart object with MSGraph.
            object oChart;
            object oChartApp;
            oChart = oShape.OLEFormat.Object;
            oChartApp = oChart.GetType().InvokeMember("Application",
                BindingFlags.GetProperty, null, oChart, null);

            //Change the chart type to Line.
            object[] Parameters = new Object[1];
            Parameters[0] = 4; //xlLine = 4
            oChart.GetType().InvokeMember("ChartType", BindingFlags.SetProperty,
                null, oChart, Parameters);

            //Update the chart image and quit MSGraph.
            oChartApp.GetType().InvokeMember("Update",
                BindingFlags.InvokeMethod, null, oChartApp, null);
            oChartApp.GetType().InvokeMember("Quit",
                BindingFlags.InvokeMethod, null, oChartApp, null);
            //... If desired, you can proceed from here using the Microsoft Graph 
            //Object model on the oChart and oChartApp objects to make additional
            //changes to the chart.

            //Set the width of the chart.
            oShape.Width = oWord.InchesToPoints(6.25f);
            oShape.Height = oWord.InchesToPoints(3.57f);

            //Add text after the chart.
            wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            wrdRng.InsertParagraphAfter();
            wrdRng.InsertAfter("THE END.");

            //Close this form.
            this.Close();

        }
Exemple #12
0
        private void GenerateDocumentButton_Click(object sender, RoutedEventArgs e)
        {
            object objMissing      = System.Reflection.Missing.Value;
            object objEndOfDocFlag = "\\endofdoc";

            Word.Application objWord = new Word.Application();
            objWord.Visible = true;
            Word.Document objDoc = objWord.Documents.Add(ref objMissing, ref objMissing, ref objMissing, ref objMissing);

            // Перший параграф, форматування
            Word.Range par1 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par1.Font.Size = 14;
            par1.Font.Name = "Times New Roman";
            par1.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par1.ParagraphFormat.LineSpacing     = 18;
            par1.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par1.ParagraphFormat.SpaceAfter      = 0;
            par1.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par1.Text = "В.4.2. Розрахунок часу на організацію наступу командиром механізованої роти (наступ)";
            par1.InsertParagraphAfter();

            // Другий параграф, форматування
            Word.Range par2 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par2.Font.Size = 14;
            par2.Font.Name = "Times New Roman";
            par2.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par2.ParagraphFormat.LineSpacing     = 12;
            par2.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par2.ParagraphFormat.SpaceAfter      = 0;
            par2.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par2.Text = "Завдання отримано о " + textBox1.Text;
            par2.InsertParagraphAfter();

            // Третій параграф, форматування
            Word.Range par3 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par3.Font.Size = 14;
            par3.Font.Name = "Times New Roman";
            par3.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par3.ParagraphFormat.LineSpacing     = 12;
            par3.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par3.ParagraphFormat.SpaceAfter      = 0;
            par3.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par3.Text = "Готовність до наступу " + textBox2.Text;
            par3.InsertParagraphAfter();

            // Четвертий параграф, форматування
            Word.Range par4 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par4.Font.Size = 14;
            par4.Font.Name = "Times New Roman";
            par4.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par4.ParagraphFormat.LineSpacing     = 12;
            par4.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par4.ParagraphFormat.SpaceAfter      = 0;
            par4.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par4.Text = "На підготовку наступу є " + textBox3.Text + " год. з них " + textBox4.Text + " год. світлого часу.";
            par4.InsertParagraphAfter();

            // П'ятий параграф, форматування
            Word.Range par5 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par5.Font.Size = 14;
            par5.Font.Name = "Times New Roman";
            par5.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par5.ParagraphFormat.LineSpacing     = 12;
            par5.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par5.ParagraphFormat.SpaceAfter      = 0;
            par5.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par5.Text = "Рішення доповісти о " + textBox5.Text;
            par5.InsertParagraphAfter();

            // Шостий параграф, форматування
            Word.Range par6 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par6.Font.Size = 14;
            par6.Font.Name = "Times New Roman";
            par6.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            par6.ParagraphFormat.LineSpacing     = 12;
            par6.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par6.ParagraphFormat.SpaceAfter      = 0;
            par6.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par6.Text = "Наявний час розподілити:\n";
            par6.InsertParagraphAfter();

            // Таблиця, форматування
            Word.Range par7 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            Word.Table tableObj;
            tableObj = objDoc.Tables.Add(par7, 18, 4, ref objMissing, ref objMissing);
            tableObj.Range.Font.Name = "Times New Roman";
            tableObj.Range.Font.Size = 12;
            tableObj.Range.ParagraphFormat.LineSpacing = 12;
            tableObj.Borders.InsideLineStyle           = Word.WdLineStyle.wdLineStyleSingle;
            tableObj.Borders.OutsideLineStyle          = Word.WdLineStyle.wdLineStyleSingle;

            tableObj.Cell(1, 1).Merge(tableObj.Cell(2, 1));
            tableObj.Cell(1, 2).Merge(tableObj.Cell(2, 2));
            tableObj.Cell(1, 3).Merge(tableObj.Cell(1, 4));

            tableObj.Cell(1, 1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(1, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(1, 2).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(1, 2).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(1, 3).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(1, 3).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(2, 3).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(2, 3).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(2, 4).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(2, 4).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;

            for (int i = 3; i <= 18; i++)
            {
                for (int j = 1; j <= 4; j++)
                {
                    tableObj.Cell(i, j).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    tableObj.Cell(i, j).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
                }
            }

            tableObj.Cell(1, 3).Range.ParagraphFormat.SpaceAfter = 8;

            // Таблиця, генерація вмісту
            tableObj.Cell(1, 1).Range.Text  = "Заходи, що проводяться";
            tableObj.Cell(1, 2).Range.Text  = "Загальна кількість часу (хв)";
            tableObj.Cell(1, 3).Range.Text  = "Час роботи";
            tableObj.Cell(2, 3).Range.Text  = "Початок\n(час, дата)";
            tableObj.Cell(2, 4).Range.Text  = "Кінець\n(час, дата)";
            tableObj.Cell(3, 1).Range.Text  = "Віддача вказівок з підготовки підрозділів до виконання бойового завдання, з організації розвідки та про час і порядок роботи на місцевості";
            tableObj.Cell(3, 2).Range.Text  = textBox6.Text;
            tableObj.Cell(3, 3).Range.Text  = textBox7.Text;
            tableObj.Cell(3, 4).Range.Text  = textBox8.Text;
            tableObj.Cell(4, 1).Range.Text  = "Проведення розрахунку часу";
            tableObj.Cell(4, 2).Range.Text  = textBox9.Text;
            tableObj.Cell(4, 3).Range.Text  = textBox10.Text;
            tableObj.Cell(4, 4).Range.Text  = textBox11.Text;
            tableObj.Cell(5, 1).Range.Text  = "Оцінка обстановки";
            tableObj.Cell(5, 2).Range.Text  = textBox12.Text;
            tableObj.Cell(5, 3).Range.Text  = textBox13.Text;
            tableObj.Cell(5, 4).Range.Text  = textBox14.Text;
            tableObj.Cell(6, 1).Range.Text  = "Прийняття рішення";
            tableObj.Cell(6, 2).Range.Text  = textBox15.Text;
            tableObj.Cell(6, 3).Range.Text  = textBox16.Text;
            tableObj.Cell(6, 4).Range.Text  = textBox17.Text;
            tableObj.Cell(7, 1).Range.Text  = "Доповідь рішення командиру батальйону";
            tableObj.Cell(7, 2).Range.Text  = textBox18.Text;
            tableObj.Cell(7, 3).Range.Text  = textBox19.Text;
            tableObj.Cell(7, 4).Range.Text  = textBox20.Text;
            tableObj.Cell(8, 1).Range.Text  = "Виїзд на рекогносцировку";
            tableObj.Cell(8, 2).Range.Text  = textBox21.Text;
            tableObj.Cell(8, 3).Range.Text  = textBox22.Text;
            tableObj.Cell(8, 4).Range.Text  = textBox23.Text;
            tableObj.Cell(9, 1).Range.Text  = "Участь у роботі на місцевості, що проводиться командиром батальйону, уточнення бойового завдання і отримання вказівок по взаємодії";
            tableObj.Cell(9, 2).Range.Text  = textBox24.Text;
            tableObj.Cell(9, 3).Range.Text  = textBox25.Text;
            tableObj.Cell(9, 4).Range.Text  = textBox26.Text;
            tableObj.Cell(10, 1).Range.Text = "Проведення рекогносцировки з командирами штатних, приданих і підтримуючих підрозділів";
            tableObj.Cell(10, 2).Range.Text = textBox27.Text;
            tableObj.Cell(10, 3).Range.Text = textBox28.Text;
            tableObj.Cell(10, 4).Range.Text = textBox29.Text;
            tableObj.Cell(11, 1).Range.Text = "Віддача бойового наказу";
            tableObj.Cell(11, 2).Range.Text = textBox30.Text;
            tableObj.Cell(11, 3).Range.Text = textBox31.Text;
            tableObj.Cell(11, 4).Range.Text = textBox32.Text;
            tableObj.Cell(12, 1).Range.Text = "Організація взаємодії та управління";
            tableObj.Cell(12, 2).Range.Text = textBox33.Text;
            tableObj.Cell(12, 3).Range.Text = textBox34.Text;
            tableObj.Cell(12, 4).Range.Text = textBox35.Text;
            tableObj.Cell(13, 1).Range.Text = "Уточнення взаємодії з командирами сусідніх рот";
            tableObj.Cell(13, 2).Range.Text = textBox36.Text;
            tableObj.Cell(13, 3).Range.Text = textBox37.Text;
            tableObj.Cell(13, 4).Range.Text = textBox38.Text;
            tableObj.Cell(14, 1).Range.Text = "Повернення командирів і робота у своїх підрозділах";
            tableObj.Cell(14, 2).Range.Text = textBox39.Text;
            tableObj.Cell(14, 3).Range.Text = textBox40.Text;
            tableObj.Cell(14, 4).Range.Text = textBox41.Text;
            tableObj.Cell(15, 1).Range.Text = "Віддача вказівок щодо всебічного забезпечення";
            tableObj.Cell(15, 2).Range.Text = textBox42.Text;
            tableObj.Cell(15, 3).Range.Text = textBox43.Text;
            tableObj.Cell(15, 4).Range.Text = textBox44.Text;
            tableObj.Cell(16, 1).Range.Text = "Контроль готовності підрозділів до виконання бойових завдань";
            tableObj.Cell(16, 2).Range.Text = textBox45.Text;
            tableObj.Cell(16, 3).Range.Text = textBox46.Text;
            tableObj.Cell(16, 4).Range.Text = textBox47.Text;
            tableObj.Cell(17, 1).Range.Text = "Доповідь командирів підрозділів про готовність до наступу";
            tableObj.Cell(17, 2).Range.Text = textBox48.Text;
            tableObj.Cell(17, 3).Range.Text = textBox49.Text;
            tableObj.Cell(17, 4).Range.Text = textBox50.Text;
            tableObj.Cell(18, 1).Range.Text = "Доповідь командиру батальйону про готовність до наступу";
            tableObj.Cell(18, 2).Range.Text = textBox51.Text;
            tableObj.Cell(18, 3).Range.Text = textBox52.Text;
            tableObj.Cell(18, 4).Range.Text = textBox53.Text;
            par7.InsertParagraphAfter();

            try
            {
                Directory.CreateDirectory(Constant.RootToSaveGenerated);
                objDoc.SaveAs($"{Constant.RootToSaveGenerated}Form 4_2 {Constant.Date}");
                string path = objDoc.FullName;

                var dialog = new DialogPrintDocument("Підтвердити друк?");
                dialog.ShowDialog();
                if (dialog.Cancelled != true)
                {
                    objDoc.PrintOut();
                }

                objDoc.Close();
                objWord.Quit();

                var order = orderService.AddOrder(path, hashService.GetHash());
                if (order != null)
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Донесення занесено до бази даних!");
                    messageBox.ShowDialog();
                }
                else
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Сталася помилка! Донесення не занесено до бази даних!");
                    messageBox.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                CustomMessageBox messageBox = new CustomMessageBox(ex.Message);
                messageBox.ShowDialog();
            }
        }
        private void GenerateDocumentButton_Click(object sender, RoutedEventArgs e)
        {
            Word.Application objWord = new Word.Application
            {
                Visible = true
            };
            Word.Document objDoc;
            object        objMissing = System.Reflection.Missing.Value;

            objDoc = objWord.Documents.Add(ref objMissing, ref objMissing, ref objMissing, ref objMissing);
            Word.Range wordRan;
            wordRan = objDoc.Range(ref objMissing, ref objMissing);

            // Форматування
            wordRan.Font.Size = 14;
            wordRan.Font.Name = "Times New Roman";
            wordRan.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            wordRan.ParagraphFormat.LineSpacing     = 18;
            wordRan.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.5);
            wordRan.ParagraphFormat.SpaceAfter      = 0;
            wordRan.ParagraphFormat.SpaceBefore     = 0;

            // Генерація вмісту
            objWord.Selection.TypeText("В.3.24. Бойове донесення командира механізованого батальйону\n\nБОЙОВЕ ДОНЕСЕННЯ командира ");
            objWord.Selection.TypeText(textBox1.Text);
            objWord.Selection.TypeText(" мб. КСП ");
            objWord.Selection.TypeText(textBox2.Text);
            objWord.Selection.TypeText(" ");
            objWord.Selection.TypeText(textBox3.Text);
            objWord.Selection.TypeText(". Карта (масштаб) ");
            objWord.Selection.TypeText(textBox4.Text);
            objWord.Selection.TypeText(", видання ");
            objWord.Selection.TypeText(textBox5.Text);
            objWord.Selection.TypeText(" року.\nБатальйон, наступаючи в напрямку ");
            objWord.Selection.TypeText(textBox6.Text);
            objWord.Selection.TypeText(", виконав найближчу задачу і веде бій з підрозділами ");
            objWord.Selection.TypeText(textBox7.Text);
            objWord.Selection.TypeText(" мпб.\n");
            objWord.Selection.TypeText(textBox8.Text);
            objWord.Selection.TypeText(" мр веде бій на рубежі ");
            objWord.Selection.TypeText(textBox9.Text);
            objWord.Selection.TypeText(" ");
            objWord.Selection.TypeText(textBox10.Text);
            objWord.Selection.TypeText(" мр веде бій з підрозділами, що відходять, на рубежі ");
            objWord.Selection.TypeText(textBox11.Text);
            objWord.Selection.TypeText(" ");
            objWord.Selection.TypeText(textBox12.Text);
            objWord.Selection.TypeText(" мр – другий ешелон, головою колони досягла ");
            objWord.Selection.TypeText(textBox13.Text);
            objWord.Selection.TypeText(".\nВтрати в підрозділах: ");
            objWord.Selection.TypeText(textBox14.Text);
            objWord.Selection.TypeText(".\nПраворуч на рубежі ");
            objWord.Selection.TypeText(textBox15.Text);
            objWord.Selection.TypeText(" веде бій ");
            objWord.Selection.TypeText(textBox16.Text);
            objWord.Selection.TypeText(" мр ");
            objWord.Selection.TypeText(textBox17.Text);
            objWord.Selection.TypeText(" батальйону.\nЛіворуч на рубежі ");
            objWord.Selection.TypeText(textBox18.Text);
            objWord.Selection.TypeText(" мр ");
            objWord.Selection.TypeText(textBox19.Text);
            objWord.Selection.TypeText(" успішно просувається в зазначеному напрямку.\nПротивник підрозділами ");
            objWord.Selection.TypeText(textBox20.Text);
            objWord.Selection.TypeText(" чинить опір на рубежі, перед фронтом ");
            objWord.Selection.TypeText(textBox21.Text);
            objWord.Selection.TypeText(" мр, відходить, одночасно висуває резерви силою до ");
            objWord.Selection.TypeText(textBox22.Text);
            objWord.Selection.TypeText(" для проведення контратаки в напрямку ");
            objWord.Selection.TypeText(textBox23.Text);
            objWord.Selection.TypeText(".\nВирішив: ввести в бій другий ешелон з рубежу ");
            objWord.Selection.TypeText(textBox24.Text);
            objWord.Selection.TypeText(" у напрямку ");
            objWord.Selection.TypeText(textBox25.Text);
            objWord.Selection.TypeText(" із завданням знищити противника, що висувається, у зустрічному бою і продовжувати наступ в зазначеному напрямку. Час виходу на рубіж введення в бій ");
            objWord.Selection.TypeText(textBox26.Text);
            objWord.Selection.TypeText(".\nПрошу вогнем артилерії придушити артилерійську батарею в районі ");
            objWord.Selection.TypeText(textBox27.Text);
            objWord.Selection.TypeText(" і противника, що висувається.");

            try
            {
                Directory.CreateDirectory(Constant.RootToSaveGenerated);
                objDoc.SaveAs($"{Constant.RootToSaveGenerated}Form 3_24 {Constant.Date}");
                string path = objDoc.FullName;

                var dialog = new DialogPrintDocument("Підтвердити друк?");
                dialog.ShowDialog();
                if (dialog.Cancelled != true)
                {
                    objDoc.PrintOut();
                }

                objDoc.Close();
                objWord.Quit();

                var order = orderService.AddOrder(path, hashService.GetHash());
                if (order != null)
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Донесення занесено до бази даних!");
                    messageBox.ShowDialog();
                }
                else
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Сталася помилка! Донесення не занесено до бази даних!");
                    messageBox.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                CustomMessageBox messageBox = new CustomMessageBox(ex.Message);
                messageBox.ShowDialog();
            }
        }
        private void performOperation()
        {
            List <TableInformation> tableData = new List <TableInformation>();
            var date = DateTime.Now;

            #region Connect To DB
            string statement = Constatnts.statement1;
            using (SqlConnection con = new SqlConnection(cs))
            {
                SqlCommand executeStatement = new SqlCommand(statement, con);
                con.Open();
                SqlDataReader reader = executeStatement.ExecuteReader();
                while (reader.Read())
                {
                    TableInformation t = new TableInformation();
                    t.SynonymName = reader["Synonym_NAME"].ToString();
                    t.TableName   = reader["Table_NAME"].ToString();
                    tableData.Add(t);
                }
            }

            List <TableInformation> sortedTableData = tableData.OrderBy(order => order.SynonymName).ToList();
            #endregion


            #region Starting Word Application
            object oMissing  = System.Reflection.Missing.Value;
            object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */

            //Start Word and create a new document.
            Word._Application oWord;
            Word._Document    oDoc;
            oWord         = new Word.Application();
            oWord.Visible = true;
            oDoc          = oWord.Documents.Add(ref oMissing, ref oMissing,
                                                ref oMissing, ref oMissing);
            #endregion


            //Insert a paragraph at the beginning of the document.
            Word.Paragraph oPara1;
            oPara1                   = oDoc.Content.Paragraphs.Add(ref oMissing);
            oPara1.Range.Text        = "All tables are under dbo schema and all columns are not nullable.";
            oPara1.Range.Font.Bold   = 1;
            oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.
            oPara1.Range.InsertParagraphAfter();

            #region Insert Table Information
            //Insert a table, fill it with data, and make the first row bold

            Word.Table oTable;
            Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oTable = oDoc.Tables.Add(wrdRng, sortedTableData.Count + 1, 3, ref oMissing, ref oMissing);
            oTable.Range.ParagraphFormat.SpaceAfter = 6;
            int r;
            oTable.Borders.InsideLineStyle  = Word.WdLineStyle.wdLineStyleSingle;
            oTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
            oTable.Cell(1, 1).Range.Text    = "NO";
            oTable.Cell(1, 2).Range.Text    = "TABLE NAME";
            oTable.Cell(1, 3).Range.Text    = "SYNONYM NAME";
            oTable.Cell(1, 1).Range.Shading.BackgroundPatternColor = Word.WdColor.wdColorGray40;
            oTable.Cell(1, 2).Range.Shading.BackgroundPatternColor = Word.WdColor.wdColorGray40;
            oTable.Cell(1, 3).Range.Shading.BackgroundPatternColor = Word.WdColor.wdColorGray40;
            oTable.Range.Font.Bold = 0;
            int z = 0;
            for (r = 2; r <= sortedTableData.Count + 1; r++)
            {
                oTable.Cell(r, 1).Range.Text = (z + 1).ToString();
                oTable.Cell(r, 2).Range.Text = sortedTableData[z].TableName;
                oTable.Cell(r, 3).Range.Text = sortedTableData[z].SynonymName;
                z++;
            }

            oTable.Rows[1].Range.Font.Bold   = 1;
            oTable.Columns[1].PreferredWidth = oWord.InchesToPoints(0.4f);
            oTable.Columns[2].PreferredWidth = oWord.InchesToPoints(2.5f);
            oTable.Columns[3].PreferredWidth = oWord.InchesToPoints(2.3f);
            #endregion


            //Add some text after the table.
            Word.Paragraph oPara4;
            object         oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oPara4 = oDoc.Content.Paragraphs.Add(ref oRng);
            oPara4.Range.InsertParagraphBefore();
            oPara4.Range.Text        = "Detailed Table Information";
            oPara4.Format.SpaceAfter = 6;
            oPara4.Range.InsertParagraphAfter();

            #region Setting Header
            foreach (Word.Section section in oDoc.Sections)
            {
                Word.Range headerRange = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                headerRange.Fields.Add(headerRange, Word.WdFieldType.wdFieldPage);
                headerRange.Text = "Govt Portal \t \t Protech Solutions \nPDM";
            }
            #endregion

            #region Setting Footer
            foreach (Word.Section wordSection in oDoc.Sections)
            {
                Word.Range footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                footerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
                footerRange.Text = date.ToString("MMMM dd, yyyy");
            }
            #endregion

            //Get Table Meta Data

            foreach (var t in sortedTableData)
            {
                statement = Constatnts.statement2;
                List <string> primaryKeysList = new List <string>();

                //Get Primary Key List
                #region Get Primary Key List for Each Table
                using (SqlConnection con1 = new SqlConnection(cs))
                {
                    string     s   = Constatnts.statement3;
                    SqlCommand cmd = new SqlCommand(s, con1);
                    con1.Open();
                    SqlDataReader reader;
                    cmd.Parameters.AddWithValue("@As_Table_NAME", t.TableName);
                    reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        string colName = reader["COLUMN_NAME"].ToString();
                        primaryKeysList.Add(colName);
                    }
                }
                #endregion

                using (SqlConnection con = new SqlConnection(cs))
                {
                    SqlCommand cmd = new SqlCommand(statement, con);
                    con.Open();
                    SqlDataReader reader;
                    cmd.Parameters.AddWithValue("@As_Table_NAME", t.TableName);
                    reader = cmd.ExecuteReader();
                    List <TableMetaData> listOfTMD = new List <TableMetaData>();
                    while (reader.Read())
                    {
                        TableMetaData tmd = new TableMetaData();
                        tmd.TableName  = t.TableName;
                        tmd.ColumnName = reader["COLUMN_NAME"].ToString();
                        tmd.Id         = reader["ORDINAL_POSITION"].ToString();
                        tmd.PK         = reader["IS_NULLABLE"].ToString();
                        tmd.DataType   = reader["DATA_TYPE"].ToString();
                        tmd.Length     = reader["LENGTH"].ToString();
                        tmd.Precision  = reader["PRECISION"].ToString();
                        tmd.Scale      = reader["SCALE"].ToString();
                        tmd.Identity   = reader["IsIdentity"].ToString();
                        listOfTMD.Add(tmd);
                    }
                    //Add para to show table Name and Synonym Name
                    Word.Paragraph oPara3;
                    oRng   = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    oPara3 = oDoc.Content.Paragraphs.Add(ref oRng);
                    oPara3.Range.ParagraphFormat.SpaceAfter = 6;
                    oPara3.Range.Text = $@"Table Name: {t.TableName}        Synonym Name: {t.SynonymName}";

                    wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    oTable = oDoc.Tables.Add(wrdRng, listOfTMD.Count + 1, 8, ref oMissing, ref oMissing);
                    oTable.Borders.InsideLineStyle          = Word.WdLineStyle.wdLineStyleSingle;
                    oTable.Borders.OutsideLineStyle         = Word.WdLineStyle.wdLineStyleSingle;
                    oTable.Range.ParagraphFormat.SpaceAfter = 6;
                    oTable.Range.Font.Bold       = 1;
                    oTable.Cell(1, 1).Range.Text = "ColumnName";
                    oTable.Cell(1, 2).Range.Text = "Id";
                    oTable.Cell(1, 3).Range.Text = "PK";
                    oTable.Cell(1, 4).Range.Text = "DataType";
                    oTable.Cell(1, 5).Range.Text = "Length";
                    oTable.Cell(1, 6).Range.Text = "Precision";
                    oTable.Cell(1, 7).Range.Text = "Scale";
                    oTable.Cell(1, 8).Range.Text = "IsIdentity";
                    oTable.Cell(1, 1).Range.Shading.BackgroundPatternColor = Word.WdColor.wdColorGray40;
                    oTable.Cell(1, 2).Range.Shading.BackgroundPatternColor = Word.WdColor.wdColorGray40;
                    oTable.Cell(1, 3).Range.Shading.BackgroundPatternColor = Word.WdColor.wdColorGray40;
                    oTable.Cell(1, 4).Range.Shading.BackgroundPatternColor = Word.WdColor.wdColorGray40;
                    oTable.Cell(1, 5).Range.Shading.BackgroundPatternColor = Word.WdColor.wdColorGray40;
                    oTable.Cell(1, 6).Range.Shading.BackgroundPatternColor = Word.WdColor.wdColorGray40;
                    oTable.Cell(1, 7).Range.Shading.BackgroundPatternColor = Word.WdColor.wdColorGray40;
                    oTable.Cell(1, 8).Range.Shading.BackgroundPatternColor = Word.WdColor.wdColorGray40;
                    oTable.Rows[1].Range.Font.Bold   = 1;
                    oTable.Columns[1].PreferredWidth = oWord.InchesToPoints(2.4f);
                    oTable.Columns[2].PreferredWidth = oWord.InchesToPoints(0.35f);
                    oTable.Columns[3].PreferredWidth = oWord.InchesToPoints(0.42f);
                    oTable.Columns[4].PreferredWidth = oWord.InchesToPoints(0.9f);
                    oTable.Columns[5].PreferredWidth = oWord.InchesToPoints(0.7f);
                    oTable.Columns[6].PreferredWidth = oWord.InchesToPoints(0.75f);
                    oTable.Columns[7].PreferredWidth = oWord.InchesToPoints(0.7f);
                    oTable.Columns[8].PreferredWidth = oWord.InchesToPoints(0.75f);
                    wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    wrdRng.InsertParagraphAfter();
                    wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    wrdRng.InsertParagraphAfter();
                    oTable.Range.Font.Bold = 0;
                    int q = 0;
                    for (r = 2; r <= listOfTMD.Count + 1; r++)
                    {
                        oTable.Cell(r, 1).Range.Text = listOfTMD[q].ColumnName;
                        oTable.Cell(r, 2).Range.Text = listOfTMD[q].Id;
                        if (primaryKeysList.Contains(listOfTMD[q].ColumnName))
                        {
                            oTable.Cell(r, 3).Range.Text = "1";
                        }
                        else
                        {
                            oTable.Cell(r, 3).Range.Text = "0";
                        }
                        oTable.Cell(r, 4).Range.Text = listOfTMD[q].DataType;
                        oTable.Cell(r, 5).Range.Text = listOfTMD[q].Length;
                        oTable.Cell(r, 6).Range.Text = listOfTMD[q].Precision;
                        oTable.Cell(r, 7).Range.Text = listOfTMD[q].Scale;
                        oTable.Cell(r, 8).Range.Text = listOfTMD[q].Identity;
                        q++;
                    }
                    oTable.Rows[1].Range.Font.Bold = 1;
                }
            }
            string fileName = textBox_OutputPath.Text == "" ? @"C:" : textBox_OutputPath.Text;
            fileName = textBox_OutputPath.Text + @"\PDM";
            oDoc.SaveAs2(fileName);
            this.Close();
        }
Exemple #15
0
        public static void foo()
        {
            object oMissing = System.Reflection.Missing.Value;

            object oEndOfDoc = "\\endofdoc";

            Word._Application oWord = new Word.Application();

            Word._Document oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
                                                      ref oMissing, ref oMissing);

            oWord.Visible = true;

            Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            //Insert a chart.

            Word.InlineShape oShape;

            object oClassType = "MSGraph.Chart.8";

            wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;

            oShape = wrdRng.InlineShapes.AddOLEObject(ref oClassType, ref oMissing,
                                                      ref oMissing, ref oMissing, ref oMissing,
                                                      ref oMissing, ref oMissing, ref oMissing);



            //Demonstrate use of late bound oChart and oChartApp objects to
            //manipulate the chart object with MSGraph.

            object oChart;
            object oChartApp;

            oChart    = oShape.OLEFormat.Object;
            oChartApp = oChart.GetType().InvokeMember("Application", BindingFlags.GetProperty,
                                                      null, oChart, null);



            //Change the chart type to Line.

            object[] Parameters = new Object[1];
            Parameters[0] = 2;             //xlLine = 4
            oChart.GetType().InvokeMember("ChartType", BindingFlags.SetProperty,
                                          null, oChart, Parameters);


            //Update the chart image and quit MSGraph.

            oChartApp.GetType().InvokeMember("Update", BindingFlags.InvokeMethod, null, oChartApp, null);

            oChartApp.GetType().InvokeMember("Quit", BindingFlags.InvokeMethod, null, oChartApp, null);

            //... If desired, you can proceed from here using the Microsoft Graph

            //Object model on the oChart and oChartApp objects to make additional

            //changes to the chart.



            //Set the width of the chart.

            oShape.Width = oWord.InchesToPoints(6.25f);

            oShape.Height = oWord.InchesToPoints(3.57f);



            //Add text after the chart.

            wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;

            wrdRng.InsertParagraphAfter();

            wrdRng.InsertAfter("THE END.");
        }
Exemple #16
0
        private void GenerateDocumentButton_Click(object sender, RoutedEventArgs e)
        {
            Word.Application objWord = new Word.Application
            {
                Visible = true
            };
            Word.Document objDoc;
            object        objMissing = System.Reflection.Missing.Value;

            objDoc = objWord.Documents.Add(ref objMissing, ref objMissing, ref objMissing, ref objMissing);
            Word.Range wordRan;
            wordRan = objDoc.Range(ref objMissing, ref objMissing);

            // Форматування
            wordRan.Font.Size = 14;
            wordRan.ParagraphFormat.Alignment   = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            wordRan.ParagraphFormat.LineSpacing = 18;
            wordRan.Font.Name = "Times New Roman";
            wordRan.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.5);
            wordRan.ParagraphFormat.SpaceAfter      = 0;
            wordRan.ParagraphFormat.SpaceBefore     = 0;

            // Генерація вмісту
            objWord.Selection.TypeText("В.8.1. Бойовий наказ командира розвідувального взводу на проведення засідки\n\n" +
                                       "1. Орієнтири: перший ");
            objWord.Selection.TypeText(textBox1.Text);
            objWord.Selection.TypeText(", другий ");
            objWord.Selection.TypeText(textBox2.Text);
            objWord.Selection.TypeText(", третій ");
            objWord.Selection.TypeText(textBox3.Text);
            objWord.Selection.TypeText(", четвертий ");
            objWord.Selection.TypeText(textBox4.Text);
            objWord.Selection.TypeText(".\n2. Противник веде оборону рубежів ");
            objWord.Selection.TypeText(textBox5.Text);
            objWord.Selection.TypeText(", ");
            objWord.Selection.TypeText(textBox6.Text);
            objWord.Selection.TypeText(".\nВзводні опорні пункти виявлені в районі ");
            objWord.Selection.TypeText(textBox7.Text);
            objWord.Selection.TypeText(";\nВогневі засоби виявлені ");
            objWord.Selection.TypeText(textBox8.Text);
            objWord.Selection.TypeText(";\nПеред переднім краєм і в проміжках між опорними пунктами – мінно-вибухові " +
                                       "загородження.\nДо ");
            objWord.Selection.TypeText(textBox9.Text);
            objWord.Selection.TypeText(" зосереджено в районі ");
            objWord.Selection.TypeText(textBox10.Text);
            objWord.Selection.TypeText(".\nПо дорозі ");
            objWord.Selection.TypeText(textBox11.Text);
            objWord.Selection.TypeText(" і назад встановлено рух поодиноких автомобілів і квадрациклів. Об ");
            objWord.Selection.TypeText(textBox12.Text);
            objWord.Selection.TypeText(" рух посилюється.\n3. ");
            objWord.Selection.TypeText(textBox13.Text);
            objWord.Selection.TypeText(" з двома саперами отримав завдання в ніч з ");
            objWord.Selection.TypeText(textBox14.Text);
            objWord.Selection.TypeText(" на ");
            objWord.Selection.TypeText(textBox15.Text);
            objWord.Selection.TypeText(" у ");
            objWord.Selection.TypeText(textBox16.Text);
            objWord.Selection.TypeText(" і влаштувати засідку на маршруті ");
            objWord.Selection.TypeText(textBox17.Text);
            objWord.Selection.TypeText(", захопити полоненого, документи і носії інформації.\nМаршрут висування в район засідки: ");
            objWord.Selection.TypeText(textBox18.Text);
            objWord.Selection.TypeText(". Маршрут повернення в розташування своїх військ ");
            objWord.Selection.TypeText(textBox19.Text);
            objWord.Selection.TypeText(".\n");
            objWord.Selection.TypeText(textBox20.Text);
            objWord.Selection.TypeText(" з ");
            objWord.Selection.TypeText(textBox21.Text);
            objWord.Selection.TypeText(" – група забезпечення № 1 з вихідного пункту ");
            objWord.Selection.TypeText(textBox22.Text);
            objWord.Selection.TypeText(" висуватися в напрямку ");
            objWord.Selection.TypeText(textBox23.Text);
            objWord.Selection.TypeText(", з виходом в район засідки зайняти позицію ");
            objWord.Selection.TypeText(textBox24.Text);
            objWord.Selection.TypeText(". Бути в готовності вогнем з близької відстані нанести ураження противнику і " +
                                       "забезпечити захоплення полоненого. Не допустити підходу противника з напрямку ");
            objWord.Selection.TypeText(textBox25.Text);
            objWord.Selection.TypeText(", дорогу перед мостом замінувати ");
            objWord.Selection.TypeText(textBox26.Text);
            objWord.Selection.TypeText(".\n");
            objWord.Selection.TypeText(textBox27.Text);
            objWord.Selection.TypeText(" - група нападу, висуватися за ");
            objWord.Selection.TypeText(textBox28.Text);
            objWord.Selection.TypeText(". З виходом в район засідки зайняти позицію ");
            objWord.Selection.TypeText(textBox29.Text);
            objWord.Selection.TypeText(". Бути в готовності і за моїм сигналом раптово здійснити напад на противника " +
                                       "і захопити полоненого, документи і носії інформації.\n");
            objWord.Selection.TypeText(textBox30.Text);
            objWord.Selection.TypeText(" - група забезпечення №2 висуватися за ");
            objWord.Selection.TypeText(textBox31.Text);
            objWord.Selection.TypeText(". Зайняти позицію ");
            objWord.Selection.TypeText(textBox32.Text);
            objWord.Selection.TypeText(". Бути в готовності вогнем із близької відстані нанести ураження противнику і " +
                                       "забезпечити захоплення полоненого, не допустити підходу резервів з напрямку ");
            objWord.Selection.TypeText(textBox33.Text);
            objWord.Selection.TypeText(".\nСпостерігачам-розвідникам ");
            objWord.Selection.TypeText(textBox34.Text);
            objWord.Selection.TypeText(", старший ");
            objWord.Selection.TypeText(textBox35.Text);
            objWord.Selection.TypeText(" зайняти спостережний пост ");
            objWord.Selection.TypeText(textBox36.Text);
            objWord.Selection.TypeText(". Вести спостереження в секторі ");
            objWord.Selection.TypeText(textBox37.Text);
            objWord.Selection.TypeText(". Про підхід противника в район засідки доповідати негайно сигналами: БТР, " +
                                       "танк – ");
            objWord.Selection.TypeText(textBox38.Text);
            objWord.Selection.TypeText(", автомобіль, квадрацикл – ");
            objWord.Selection.TypeText(textBox39.Text);
            objWord.Selection.TypeText(". Бути в готовності і не допустити відходу противника в напрямку ");
            objWord.Selection.TypeText(textBox40.Text);
            objWord.Selection.TypeText(". Відходити на позиції ");
            objWord.Selection.TypeText(textBox41.Text);
            objWord.Selection.TypeText(".\nПорядок повернення: першим відходить ");
            objWord.Selection.TypeText(textBox42.Text);
            objWord.Selection.TypeText(", за ним ");
            objWord.Selection.TypeText(textBox43.Text);
            objWord.Selection.TypeText(", прикриває відхід ");
            objWord.Selection.TypeText(textBox44.Text);
            objWord.Selection.TypeText(".\n4. Артилерія готує загороджувальний вогонь по ділянках: № 1 ");
            objWord.Selection.TypeText(textBox45.Text);
            objWord.Selection.TypeText(", № 2 ");
            objWord.Selection.TypeText(textBox46.Text);
            objWord.Selection.TypeText(", № 3 ");
            objWord.Selection.TypeText(textBox47.Text);
            objWord.Selection.TypeText(", № 4 ");
            objWord.Selection.TypeText(textBox48.Text);
            objWord.Selection.TypeText(". Вихідний пункт ");
            objWord.Selection.TypeText(textBox49.Text);
            objWord.Selection.TypeText(", взвод проходить о ");
            objWord.Selection.TypeText(textBox50.Text);
            objWord.Selection.TypeText(", готовність до руху ");
            objWord.Selection.TypeText(textBox51.Text);
            objWord.Selection.TypeText(".\nСигнали: на відкриття вогню ");
            objWord.Selection.TypeText(textBox52.Text);
            objWord.Selection.TypeText(";\nВиклик зосередженого вогню по ділянці № 1 - ");
            objWord.Selection.TypeText(textBox53.Text);
            objWord.Selection.TypeText(";\nпо ділянці № 2 - ");
            objWord.Selection.TypeText(textBox54.Text);
            objWord.Selection.TypeText(";\nпо ділянці № 3 - ");
            objWord.Selection.TypeText(textBox55.Text);
            objWord.Selection.TypeText(";\nпо ділянці № 4 - ");
            objWord.Selection.TypeText(textBox56.Text);
            objWord.Selection.TypeText(".\nПрипинення вогню артилерії - ");
            objWord.Selection.TypeText(textBox57.Text);
            objWord.Selection.TypeText(".\nЯ – з ");
            objWord.Selection.TypeText(textBox58.Text);
            objWord.Selection.TypeText(".\nМій заступник – командир ");
            objWord.Selection.TypeText(textBox59.Text);
            objWord.Selection.TypeText(".\nПропуск - ");
            objWord.Selection.TypeText(textBox60.Text);
            objWord.Selection.TypeText(".");

            try
            {
                Directory.CreateDirectory(Constant.RootToSaveGenerated);
                objDoc.SaveAs($"{Constant.RootToSaveGenerated}Form 8_1 {Constant.Date}");
                string path = objDoc.FullName;

                var dialog = new DialogPrintDocument("Підтвердити друк?");
                dialog.ShowDialog();
                if (dialog.Cancelled != true)
                {
                    objDoc.PrintOut();
                }

                objDoc.Close();
                objWord.Quit();

                var order = orderService.AddOrder(path, hashService.GetHash());
                if (order != null)
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Донесення занесено до бази даних!");
                    messageBox.ShowDialog();
                }
                else
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Сталася помилка! Донесення не занесено до бази даних!");
                    messageBox.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                CustomMessageBox messageBox = new CustomMessageBox(ex.Message);
                messageBox.ShowDialog();
            }
        }
Exemple #17
0
    public int MyWord(string MessageSaveFile, bool SaveWordPage, bool WordVisible)
    {
        object oMissing  = System.Reflection.Missing.Value;
        object oEndOfDoc = "\\endofdoc";     /* \endofdoc is a predefined bookmark */


        //Start Word and create a new document
        Word._Application oWord;
        Word._Document    oDoc;
        oWord = new Word.Application();
        if (WordVisible)
        {
            oWord.Visible = true;
        }
        else
        {
            oWord.Visible = false;
        }

        oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

        //Insert a paragraph at the beginning of the document
        Word.Paragraph oPara1;
        oPara1                   = oDoc.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();

        //Insert a paragraph at the end of the document.
        Word.Paragraph oPara2;
        object         oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;

        oPara2                   = oDoc.Content.Paragraphs.Add(ref oRng);
        oPara2.Range.Text        = "Heading 2";
        oPara2.Format.SpaceAfter = 6;
        oPara2.Range.InsertParagraphAfter();

        //Insert another paragraph.
        Word.Paragraph oPara3;
        oRng                     = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
        oPara3                   = oDoc.Content.Paragraphs.Add(ref oRng);
        oPara3.Range.Text        = "This is a sentence of normal text. Now here is a table:";
        oPara3.Range.Font.Bold   = 0;
        oPara3.Format.SpaceAfter = 24;
        oPara3.Range.InsertParagraphAfter();

        //Insert a 3 x 5 table, fill it with data, and make the first row
        //bold and italic.
        Word.Table oTable;
        Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
        oTable = oDoc.Tables.Add(wrdRng, 3, 5, ref oMissing, ref oMissing);
        oTable.Range.ParagraphFormat.SpaceAfter = 6;
        int    r, c;
        string strText;

        for (r = 1; r <= 3; r++)
        {
            for (c = 1; c <= 5; c++)
            {
                strText = "r" + r + "c" + c;
                oTable.Cell(r, c).Range.Text = strText;
            }
        }
        oTable.Rows[1].Range.Font.Bold   = 1;
        oTable.Rows[1].Range.Font.Italic = 1;

        //Add some text after the table.
        Word.Paragraph oPara4;
        oRng   = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
        oPara4 = oDoc.Content.Paragraphs.Add(ref oRng);
        oPara4.Range.InsertParagraphBefore();
        oPara4.Range.Text        = "And here's another table:";
        oPara4.Format.SpaceAfter = 24;
        oPara4.Range.InsertParagraphAfter();

        //Insert a 5 x 2 table, fill it with data, and change the column widths.
        wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
        oTable = oDoc.Tables.Add(wrdRng, 5, 2, ref oMissing, ref oMissing);
        oTable.Range.ParagraphFormat.SpaceAfter = 6;
        for (r = 1; r <= 5; r++)
        {
            for (c = 1; c <= 2; c++)
            {
                strText = "r" + r + "c" + c;
                oTable.Cell(r, c).Range.Text = strText;
            }
        }
        oTable.Columns[1].Width = oWord.InchesToPoints(2);     //Change width of columns 1 & 2
        oTable.Columns[2].Width = oWord.InchesToPoints(3);

        //Keep inserting text. When you get to 7 inches from top of the
        //document, insert a hard page break.
        object oPos;
        double dPos = oWord.InchesToPoints(7);

        oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range.InsertParagraphAfter();
        do
        {
            wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            wrdRng.ParagraphFormat.SpaceAfter = 6;
            wrdRng.InsertAfter("A line of text");
            wrdRng.InsertParagraphAfter();
            oPos = wrdRng.get_Information
                       (Word.WdInformation.wdVerticalPositionRelativeToPage);
        }while (dPos >= Convert.ToDouble(oPos));
        object oCollapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
        object oPageBreak   = Word.WdBreakType.wdPageBreak;

        wrdRng.Collapse(ref oCollapseEnd);
        wrdRng.InsertBreak(ref oPageBreak);
        wrdRng.Collapse(ref oCollapseEnd);
        wrdRng.InsertAfter("We're now on page 2. Here's my chart:");
        wrdRng.InsertParagraphAfter();

        //Insert a chart.
        Word.InlineShape oShape;
        object           oClassType = "MSGraph.Chart.8";

        wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
        oShape = wrdRng.InlineShapes.AddOLEObject(ref oClassType, ref oMissing,
                                                  ref oMissing, ref oMissing, ref oMissing,
                                                  ref oMissing, ref oMissing, ref oMissing);

        //Demonstrate use of late bound oChart and oChartApp objects to
        //manipulate the chart object with MSGraph.
        object oChart;
        object oChartApp;

        oChart    = oShape.OLEFormat.Object;
        oChartApp = oChart.GetType().InvokeMember("Application",
                                                  BindingFlags.GetProperty, null, oChart, null);

        //Change the chart type to Line.
        object[] Parameters = new Object[1];
        Parameters[0] = 4;     //xlLine = 4
        oChart.GetType().InvokeMember("ChartType", BindingFlags.SetProperty,
                                      null, oChart, Parameters);

        //Update the chart image and quit MSGraph.
        oChartApp.GetType().InvokeMember("Update",
                                         BindingFlags.InvokeMethod, null, oChartApp, null);
        oChartApp.GetType().InvokeMember("Quit",
                                         BindingFlags.InvokeMethod, null, oChartApp, null);
        //... If desired, you can proceed from here using the Microsoft Graph
        //Object model on the oChart and oChartApp objects to make additional
        //changes to the chart.

        //Set the width of the chart.
        oShape.Width  = oWord.InchesToPoints(6.25f);
        oShape.Height = oWord.InchesToPoints(3.57f);

        //Add text after the chart.
        wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
        wrdRng.InsertParagraphAfter();
        wrdRng.InsertAfter("THE END.");


        //Закрываем документ

        object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;

        if (SaveWordPage)
        {
            saveChanges = Word.WdSaveOptions.wdSaveChanges;
        }

        object originalFormat = Word.WdOriginalFormat.wdWordDocument;
        object routeDocument  = Type.Missing;

        oWord.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
        oWord = null;



        return(0);
    }
    private void dd()
    {
        object objMiss = System.Reflection.Missing.Value;
        object objEndOfDocFlag = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
        //Start Word and create a new document.
        Word._Application oWord;
        Word._Document doc;
        oWord = new Word.Application();
        oWord.Visible = true;
        doc = oWord.Documents.Add(ref objMiss, ref objMiss, ref objMiss, ref objMiss);

        //Insert a paragraph at the end of the document.
        Word.Paragraph objPara2; //define paragraph object
        object oRng = doc.Bookmarks.get_Item(ref objEndOfDocFlag).Range; //go to end of the page
        objPara2 = doc.Content.Paragraphs.Add(ref oRng); //add paragraph at end of document
        objPara2.Range.Text = "Test Table Caption"; //add some text in paragraph
        objPara2.Format.SpaceAfter = 10; //define some style
        objPara2.Range.InsertParagraphAfter(); //insert paragraph

        //Insert a 2 x 2 table, (table with 2 row and 2 column)
        Word.Table Table; //create table object
        Word.Range range = doc.Bookmarks.get_Item(ref objEndOfDocFlag).Range; //go to end of document
        Table = doc.Tables.Add(range, 2, 2, ref objMiss, ref objMiss); //add table object in word document
        Table.Range.ParagraphFormat.SpaceAfter = 6;
        int iRow, iCols;
        string strText;
        for (iRow = 1; iRow <= 2; iRow++)
            for (iCols = 1; iCols <= 2; iCols++)
            {
                strText = "row:" + iRow + "col:" + iCols;
                Table.Cell(iRow, iCols).Range.Text = strText; //add some text to cell
            }
        Table.Rows[1].Range.Font.Bold = 1; //make first row of table BOLD
        Table.Columns[1].Width = oWord.InchesToPoints(3); //increase first column width

        //Add some text after table
        range = doc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
        range.InsertParagraphAfter(); //put enter in document
        range.InsertAfter("THIS IS THE SIMPLE WORD DEMO : THANKS YOU.");
        object szPath = "test.docx";
        doc.SaveAs(ref szPath);
    }
        private void GenerateDocumentButton_Click(object sender, RoutedEventArgs e)
        {
            object objMissing      = System.Reflection.Missing.Value;
            object objEndOfDocFlag = "\\endofdoc";

            Word.Application objWord = new Word.Application
            {
                Visible = true
            };
            Word.Document objDoc = objWord.Documents.Add(ref objMissing, ref objMissing, ref objMissing, ref objMissing);

            // Перший параграф, форматування
            Word.Range par1 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par1.Font.Size = 14;
            par1.Font.Name = "Times New Roman";
            par1.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par1.ParagraphFormat.LineSpacing     = 18;
            par1.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par1.ParagraphFormat.SpaceAfter      = 0;
            par1.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par1.Text = "В.4.1. Розрахунок часу командира механізованої роти.";
            par1.InsertParagraphAfter();

            // Другий параграф, форматування
            Word.Range par2 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par2.Font.Size = 14;
            par2.Font.Name = "Times New Roman";
            par2.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par2.ParagraphFormat.LineSpacing     = 18;
            par2.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par2.ParagraphFormat.SpaceAfter      = 0;
            par2.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par2.Text = "Час отримання завдання: " + textBox1.Text + ".";
            par2.InsertParagraphAfter();

            // Третій параграф, форматування
            Word.Range par3 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par3.Font.Size = 14;
            par3.Font.Name = "Times New Roman";
            par3.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par3.ParagraphFormat.LineSpacing     = 18;
            par3.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par3.ParagraphFormat.SpaceAfter      = 0;
            par3.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par3.Text = "Час готовності: " + textBox2.Text + ".";
            par3.InsertParagraphAfter();

            // Четвертий параграф, форматування
            Word.Range par4 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par4.Font.Size = 14;
            par4.Font.Name = "Times New Roman";
            par4.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par4.ParagraphFormat.LineSpacing     = 18;
            par4.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par4.ParagraphFormat.SpaceAfter      = 0;
            par4.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par4.Text = "Загальний час для підготовки підрозділів: " + textBox3.Text + ".";
            par4.InsertParagraphAfter();

            // П'ятий параграф, форматування
            Word.Range par5 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par5.Font.Size = 14;
            par5.Font.Name = "Times New Roman";
            par5.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par5.ParagraphFormat.LineSpacing     = 18;
            par5.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par5.ParagraphFormat.SpaceAfter      = 0;
            par5.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par5.Text = "Кількість світлого часу доби: " + textBox4.Text + ".";
            par5.InsertParagraphAfter();

            // Шостий параграф, форматування
            Word.Range par6 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            par6.Font.Size = 14;
            par6.Font.Name = "Times New Roman";
            par6.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            par6.ParagraphFormat.LineSpacing     = 18;
            par6.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            par6.ParagraphFormat.SpaceAfter      = 0;
            par6.ParagraphFormat.SpaceBefore     = 0;
            // Генерація вмісту
            par6.Text = "Кількість темного часу доби: " + textBox5.Text + ".";
            par6.InsertParagraphAfter();

            // Таблиця, форматування
            Word.Range par7 = objDoc.Bookmarks.get_Item(ref objEndOfDocFlag).Range;
            Word.Table tableObj;
            tableObj = objDoc.Tables.Add(par7, 18, 4, ref objMissing, ref objMissing);
            tableObj.Range.Font.Name = "Times New Roman";
            tableObj.Range.Font.Size = 12;
            tableObj.Range.ParagraphFormat.LineSpacing = 12;
            tableObj.Borders.InsideLineStyle           = Word.WdLineStyle.wdLineStyleSingle;
            tableObj.Borders.OutsideLineStyle          = Word.WdLineStyle.wdLineStyleSingle;

            tableObj.Cell(1, 1).Merge(tableObj.Cell(2, 1));
            tableObj.Cell(1, 2).Merge(tableObj.Cell(2, 2));
            tableObj.Cell(1, 3).Merge(tableObj.Cell(1, 4));

            tableObj.Cell(1, 1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(1, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(1, 2).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(1, 2).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(1, 3).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(1, 3).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(2, 3).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(2, 3).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            tableObj.Cell(2, 4).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            tableObj.Cell(2, 4).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            for (int i = 3; i <= 18; i++)
            {
                tableObj.Cell(i, 1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
                tableObj.Cell(i, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
            }

            for (int i = 3; i <= 18; i++)
            {
                for (int j = 2; j <= 4; j++)
                {
                    tableObj.Cell(i, j).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    tableObj.Cell(i, j).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalTop;
                }
            }

            tableObj.Cell(1, 3).Range.ParagraphFormat.SpaceAfter = 8;

            // Таблиця, генерація вмісту
            tableObj.Cell(1, 1).Range.Text  = "Заходи, що проводяться";
            tableObj.Cell(1, 2).Range.Text  = "Загальна кількість часу (хв)";
            tableObj.Cell(1, 3).Range.Text  = "Час роботи";
            tableObj.Cell(2, 3).Range.Text  = "Початок\n(час, дата)";
            tableObj.Cell(2, 4).Range.Text  = "Кінець\n(час, дата)";
            tableObj.Cell(3, 1).Range.Text  = "З’ясування завдання";
            tableObj.Cell(3, 2).Range.Text  = textBox6.Text;
            tableObj.Cell(3, 3).Range.Text  = textBox7.Text;
            tableObj.Cell(3, 4).Range.Text  = textBox8.Text;
            tableObj.Cell(4, 1).Range.Text  = "Визначення заходів, які необхідно провести негайно для підготовки роти до бою";
            tableObj.Cell(4, 2).Range.Text  = textBox9.Text;
            tableObj.Cell(4, 3).Range.Text  = textBox10.Text;
            tableObj.Cell(4, 4).Range.Text  = textBox11.Text;
            tableObj.Cell(5, 1).Range.Text  = "Відпрацювання розрахунку часу";
            tableObj.Cell(5, 2).Range.Text  = textBox12.Text;
            tableObj.Cell(5, 3).Range.Text  = textBox13.Text;
            tableObj.Cell(5, 4).Range.Text  = textBox14.Text;
            tableObj.Cell(6, 1).Range.Text  = "Оцінка обстановки";
            tableObj.Cell(6, 2).Range.Text  = textBox15.Text;
            tableObj.Cell(6, 3).Range.Text  = textBox16.Text;
            tableObj.Cell(6, 4).Range.Text  = textBox17.Text;
            tableObj.Cell(7, 1).Range.Text  = "Прийняття рішення";
            tableObj.Cell(7, 2).Range.Text  = textBox18.Text;
            tableObj.Cell(7, 3).Range.Text  = textBox19.Text;
            tableObj.Cell(7, 4).Range.Text  = textBox20.Text;
            tableObj.Cell(8, 1).Range.Text  = "Доповідь рішення старшому командиру";
            tableObj.Cell(8, 2).Range.Text  = textBox21.Text;
            tableObj.Cell(8, 3).Range.Text  = textBox22.Text;
            tableObj.Cell(8, 4).Range.Text  = textBox23.Text;
            tableObj.Cell(9, 1).Range.Text  = "Проведення рекогносцировки";
            tableObj.Cell(9, 2).Range.Text  = textBox24.Text;
            tableObj.Cell(9, 3).Range.Text  = textBox25.Text;
            tableObj.Cell(9, 4).Range.Text  = textBox26.Text;
            tableObj.Cell(10, 1).Range.Text = "Віддання бойового наказу";
            tableObj.Cell(10, 2).Range.Text = textBox27.Text;
            tableObj.Cell(10, 3).Range.Text = textBox28.Text;
            tableObj.Cell(10, 4).Range.Text = textBox29.Text;
            tableObj.Cell(11, 1).Range.Text = "Організація взаємодії і системи вогню та віддання вказівок, щодо всебічного забезпечення";
            tableObj.Cell(11, 2).Range.Text = textBox30.Text;
            tableObj.Cell(11, 3).Range.Text = textBox31.Text;
            tableObj.Cell(11, 4).Range.Text = textBox32.Text;
            tableObj.Cell(12, 1).Range.Text = "Зайняття ротного опорного пункту";
            tableObj.Cell(12, 2).Range.Text = textBox33.Text;
            tableObj.Cell(12, 3).Range.Text = textBox34.Text;
            tableObj.Cell(12, 4).Range.Text = textBox35.Text;
            tableObj.Cell(13, 1).Range.Text = "Доповідь командиру батальйону про готовність системи вогню";
            tableObj.Cell(13, 2).Range.Text = textBox36.Text;
            tableObj.Cell(13, 3).Range.Text = textBox37.Text;
            tableObj.Cell(13, 4).Range.Text = textBox38.Text;
            tableObj.Cell(14, 1).Range.Text = "Виконання робіт інженерного обладнання РОП 1 черги";
            tableObj.Cell(14, 2).Range.Text = textBox39.Text;
            tableObj.Cell(14, 3).Range.Text = textBox40.Text;
            tableObj.Cell(14, 4).Range.Text = textBox41.Text;
            tableObj.Cell(15, 1).Range.Text = "Виконання робіт інженерного обладнання РОП 2 черги";
            tableObj.Cell(15, 2).Range.Text = textBox42.Text;
            tableObj.Cell(15, 3).Range.Text = textBox43.Text;
            tableObj.Cell(15, 4).Range.Text = textBox44.Text;
            tableObj.Cell(16, 1).Range.Text = "Контроль та допомога командирам підрозділів в організації оборони.";
            tableObj.Cell(16, 2).Range.Text = textBox45.Text;
            tableObj.Cell(16, 3).Range.Text = textBox46.Text;
            tableObj.Cell(16, 4).Range.Text = textBox47.Text;
            tableObj.Cell(17, 1).Range.Text = "Прийняття доповіді командирів підрозділів про готовність оборони";
            tableObj.Cell(17, 2).Range.Text = textBox48.Text;
            tableObj.Cell(17, 3).Range.Text = textBox49.Text;
            tableObj.Cell(17, 4).Range.Text = textBox50.Text;
            tableObj.Cell(18, 1).Range.Text = "Доповідь командиру батальйону про готовність оборони";
            tableObj.Cell(18, 2).Range.Text = textBox51.Text;
            tableObj.Cell(18, 3).Range.Text = textBox52.Text;
            tableObj.Cell(18, 4).Range.Text = textBox53.Text;
            par7.InsertParagraphAfter();

            try
            {
                Directory.CreateDirectory(Constant.RootToSaveGenerated);
                objDoc.SaveAs($"{Constant.RootToSaveGenerated}Form 4_1 {Constant.Date}");
                string path = objDoc.FullName;

                var dialog = new DialogPrintDocument("Підтвердити друк?");
                dialog.ShowDialog();
                if (dialog.Cancelled != true)
                {
                    objDoc.PrintOut();
                }

                objDoc.Close();
                objWord.Quit();

                var order = orderService.AddOrder(path, hashService.GetHash());
                if (order != null)
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Донесення занесено до бази даних!");
                    messageBox.ShowDialog();
                }
                else
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Сталася помилка! Донесення не занесено до бази даних!");
                    messageBox.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                CustomMessageBox messageBox = new CustomMessageBox(ex.Message);
                messageBox.ShowDialog();
            }
        }
Exemple #20
0
    public void ImprimirEtiquetasArreglos(JObject pJDocumento, int pIdImpresionTemplate, string pRutaTemplate, CConexion pConexion)
    {
        CImpresionEtiquetas         ImpresionEtiquetas = new CImpresionEtiquetas();
        Dictionary <string, object> Parametros         = new Dictionary <string, object>();

        Parametros.Add("IdImpresionTemplate", pIdImpresionTemplate);

        object oEndOfDoc = "\\endofdoc"; /* \endofdoc es un bookmark predefinido */
        Object oMissing  = System.Reflection.Missing.Value;

        Word.Range wrdRng = documentoWord.Bookmarks.get_Item(ref oEndOfDoc).Range;
        int        ind    = 0;
        object     oPos;
        double     dPos = aplicacionWord.InchesToPoints(10);

        foreach (JProperty oPropiedadDocumento in pJDocumento.Properties())
        {
            if (oPropiedadDocumento.Value.Type.ToString() == "Object")
            {
                JObject JTablaConceptos = new JObject();
                JTablaConceptos = (JObject)pJDocumento[oPropiedadDocumento.Name];
                foreach (JProperty oPropiedadTabla in JTablaConceptos.Properties())
                {
                    if (oPropiedadTabla.Name == "Tipo")
                    {
                        if (oPropiedadTabla.Value.ToString() == "Conceptos")
                        {
                            for (int i = 1; i <= documentoWord.Tables.Count; i++)
                            {
                                Word.Table wTable = documentoWord.Tables[i];
                                Word.Cell  pCell  = wTable.Cell(1, 1);

                                if (wTable.ID != null && wTable.ID == "tblReceptor")
                                {
                                    foreach (CImpresionEtiquetas oImpresionEtiqueta in ImpresionEtiquetas.LlenaObjetosFiltros(Parametros, pConexion))
                                    {
                                        Word.Range rangePlantilla = wTable.Range;

                                        int rc = wTable.Rows.Count;
                                        // Selecciona y copia el renglon Layout.
                                        rangePlantilla.Start = 1;
                                        rangePlantilla.End   = wTable.Rows[rc].Cells[wTable.Rows[rc].Cells.Count].Range.End;
                                        rangePlantilla.Find.ClearFormatting();
                                        rangePlantilla.Find.Text = oImpresionEtiqueta.Etiqueta;
                                        rangePlantilla.Find.Replacement.ClearFormatting();


                                        if (pJDocumento[oImpresionEtiqueta.Campo] != null)
                                        {
                                            rangePlantilla.Find.Replacement.Text = pJDocumento[oImpresionEtiqueta.Campo].ToString();
                                        }
                                        object replaceAll = Word.WdReplace.wdReplaceAll;
                                        rangePlantilla.Find.Execute(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref replaceAll, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                                    }
                                }

                                if (wTable.ID != null && wTable.ID == JTablaConceptos["NombreTabla"].ToString())
                                {
                                    bool pRowsNum = false;
                                    if (wTable.Rows.Count > 1)
                                    {
                                        pRowsNum = true;
                                    }

                                    int contador = 1;
                                    // Layaout
                                    foreach (JObject JInventario in JTablaConceptos["Inventarios"])
                                    {
                                        contador = contador + 1;
                                        Word.Range range = wTable.Range;

                                        // Renglon Layout
                                        int selectedRow = 1;

                                        // Selecciona y copia el renglon Layout.
                                        range.Start = wTable.Rows[selectedRow].Cells[1].Range.Start;
                                        range.End   = wTable.Rows[selectedRow].Cells[wTable.Rows[selectedRow].Cells.Count].Range.End;
                                        range.Copy();

                                        // Inserta renglon nuevo al final de la tabla.
                                        wTable.Rows.Add(ref oMissing);

                                        // Mueve el cursor a la primera celda del renglon nuevo.
                                        range.Start = wTable.Rows[wTable.Rows.Count].Cells[1].Range.Start;
                                        range.End   = range.Start;

                                        // Pega los valores del renglon layout al renglon nuevo.
                                        range.Paste();

                                        int m = wTable.Rows.Count;

                                        Word.Row  renglonPlantilla = wTable.Rows[m];
                                        Word.Cell celdaPlantilla   = renglonPlantilla.Cells[1];

                                        for (int x = 1; x <= celdaPlantilla.Tables.Count; x++)
                                        {
                                            bool sRowsNum = false;
                                            if (celdaPlantilla.Tables[x].Rows.Count > 3)
                                            {
                                                sRowsNum = true;
                                            }
                                            foreach (CImpresionEtiquetas oImpresionEtiqueta in ImpresionEtiquetas.LlenaObjetosFiltros(Parametros, pConexion))
                                            {
                                                Word.Range rangePlantilla = wTable.Range;

                                                // Selecciona y copia el renglon Layout.
                                                rangePlantilla.Start = celdaPlantilla.Tables[x].Rows[1].Cells[1].Range.Start;
                                                rangePlantilla.End   = celdaPlantilla.Tables[x].Rows[1].Cells[celdaPlantilla.Tables[x].Rows[1].Cells.Count].Range.End;
                                                rangePlantilla.Find.ClearFormatting();
                                                rangePlantilla.Find.Text = oImpresionEtiqueta.Etiqueta;
                                                rangePlantilla.Find.Replacement.ClearFormatting();

                                                if (JInventario[oImpresionEtiqueta.Campo] != null)
                                                {
                                                    rangePlantilla.Find.Replacement.Text = JInventario[oImpresionEtiqueta.Campo].ToString();
                                                }
                                                object replaceAll = Word.WdReplace.wdReplaceAll;
                                                rangePlantilla.Find.Execute(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref replaceAll, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                                            }

                                            foreach (JObject JConcepto in JInventario["Lista"])
                                            {
                                                Word.Range sRange = celdaPlantilla.Tables[x].Range;

                                                // Selecciona y copia el renglon Layout.
                                                sRange.Start = celdaPlantilla.Tables[x].Rows[3].Cells[1].Range.Start;
                                                sRange.End   = celdaPlantilla.Tables[x].Rows[3].Cells[celdaPlantilla.Tables[x].Rows[3].Cells.Count].Range.End;
                                                sRange.Copy();

                                                // Inserta renglon nuevo al final de la tabla.
                                                celdaPlantilla.Tables[x].Rows.Add(ref oMissing);

                                                // Mueve el cursor a la primera celda del renglon nuevo.
                                                sRange.Start = celdaPlantilla.Tables[x].Rows[celdaPlantilla.Tables[x].Rows.Count].Cells[1].Range.Start;
                                                sRange.End   = sRange.Start;

                                                // Pega los valores del renglon layout al renglon nuevo.
                                                sRange.Paste();

                                                foreach (CImpresionEtiquetas oImpresionEtiqueta in ImpresionEtiquetas.LlenaObjetosFiltros(Parametros, pConexion))
                                                {
                                                    Word.Range rowRange = wTable.Range;

                                                    // Selecciona y copia el renglon Layout.
                                                    sRange.Find.ClearFormatting();
                                                    sRange.Find.Text = oImpresionEtiqueta.Etiqueta;
                                                    sRange.Find.Replacement.ClearFormatting();

                                                    if (JConcepto[oImpresionEtiqueta.Campo] != null)
                                                    {
                                                        sRange.Find.Replacement.Text = JConcepto[oImpresionEtiqueta.Campo].ToString();
                                                    }
                                                    object replaceAll = Word.WdReplace.wdReplaceAll;
                                                    sRange.Find.Execute(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref replaceAll, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                                                }
                                            }
                                            if (sRowsNum)
                                            {
                                                JObject JTotal = new JObject();
                                                JTotal = (JObject)JInventario["Total"];

                                                Word.Range sRange = celdaPlantilla.Tables[x].Range;

                                                // Selecciona y copia el renglon Layout.
                                                sRange.Start = celdaPlantilla.Tables[x].Rows[4].Cells[1].Range.Start;
                                                sRange.End   = celdaPlantilla.Tables[x].Rows[4].Cells[celdaPlantilla.Tables[x].Rows[4].Cells.Count].Range.End;
                                                sRange.Copy();

                                                // Inserta renglon nuevo al final de la tabla.
                                                celdaPlantilla.Tables[x].Rows.Add(ref oMissing);

                                                // Mueve el cursor a la primera celda del renglon nuevo.
                                                sRange.Start = celdaPlantilla.Tables[x].Rows[celdaPlantilla.Tables[x].Rows.Count].Cells[1].Range.Start;
                                                sRange.End   = sRange.Start;

                                                // Pega los valores del renglon layout al renglon nuevo.
                                                sRange.Paste();

                                                foreach (CImpresionEtiquetas oImpresionEtiqueta in ImpresionEtiquetas.LlenaObjetosFiltros(Parametros, pConexion))
                                                {
                                                    Word.Range rowRange = wTable.Range;

                                                    // Selecciona y copia el renglon Layout.
                                                    sRange.Find.ClearFormatting();
                                                    sRange.Find.Text = oImpresionEtiqueta.Etiqueta;
                                                    sRange.Find.Replacement.ClearFormatting();

                                                    if (JTotal[oImpresionEtiqueta.Campo] != null)
                                                    {
                                                        sRange.Find.Replacement.Text = JTotal[oImpresionEtiqueta.Campo].ToString();
                                                    }
                                                    object replaceAll = Word.WdReplace.wdReplaceAll;
                                                    sRange.Find.Execute(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref replaceAll, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                                                }
                                                celdaPlantilla.Tables[x].Rows[4].Delete();
                                            }
                                            celdaPlantilla.Tables[x].Rows[3].Delete();
                                        }
                                    }

                                    if (pRowsNum)
                                    {
                                        Word.Range sRange = wTable.Range;

                                        // Selecciona y copia el renglon Layout.
                                        sRange.Start = wTable.Rows[2].Cells[1].Range.Start;
                                        sRange.End   = wTable.Rows[2].Cells[wTable.Rows[2].Cells.Count].Range.End;
                                        sRange.Copy();

                                        // Inserta renglon nuevo al final de la tabla.
                                        wTable.Rows.Add(ref oMissing);

                                        // Mueve el cursor a la primera celda del renglon nuevo.
                                        sRange.Start = wTable.Rows[wTable.Rows.Count].Cells[1].Range.Start;
                                        sRange.End   = sRange.Start;

                                        // Pega los valores del renglon layout al renglon nuevo.
                                        sRange.Paste();

                                        foreach (CImpresionEtiquetas oImpresionEtiqueta in ImpresionEtiquetas.LlenaObjetosFiltros(Parametros, pConexion))
                                        {
                                            Word.Range rangePlantilla = wTable.Range;

                                            // Selecciona y copia el renglon Layout.
                                            rangePlantilla.Find.ClearFormatting();
                                            rangePlantilla.Find.Text = oImpresionEtiqueta.Etiqueta;
                                            rangePlantilla.Find.Replacement.ClearFormatting();


                                            if (pJDocumento[oImpresionEtiqueta.Campo] != null)
                                            {
                                                rangePlantilla.Find.Replacement.Text = pJDocumento[oImpresionEtiqueta.Campo].ToString();
                                            }
                                            object replaceAll = Word.WdReplace.wdReplaceAll;
                                            rangePlantilla.Find.Execute(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref replaceAll, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                                        }
                                        wTable.Rows[2].Delete();
                                    }
                                    wTable.Rows[1].Delete();
                                }
                            }
                        }
                    }
                }
            }
        }
    }
        private void GenerateDocumentButton_Click(object sender, RoutedEventArgs e)
        {
            Word.Application objWord = new Word.Application
            {
                Visible = true
            };
            Word.Document objDoc;
            object        objMissing = System.Reflection.Missing.Value;

            objDoc = objWord.Documents.Add(ref objMissing, ref objMissing, ref objMissing, ref objMissing);
            Word.Range wordRan;
            wordRan = objDoc.Range(ref objMissing, ref objMissing);

            // Форматування
            wordRan.Font.Size = 14;
            wordRan.ParagraphFormat.Alignment   = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            wordRan.ParagraphFormat.LineSpacing = 18;
            wordRan.Font.Name = "Times New Roman";
            wordRan.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.0);
            wordRan.ParagraphFormat.SpaceAfter      = 0;
            wordRan.ParagraphFormat.SpaceBefore     = 0;

            // Генерація вмісту
            objWord.Selection.TypeText("В.8.2. Бойовий наказ командира розвідувального взводу на проведення пошуку\n\n1. Орієнтири:\nперший ");
            objWord.Selection.TypeText(textBox1.Text);
            objWord.Selection.TypeText(",\nдругий ");
            objWord.Selection.TypeText(textBox2.Text);
            objWord.Selection.TypeText(",\nтретій ");
            objWord.Selection.TypeText(textBox3.Text);
            objWord.Selection.TypeText(".\n2. Противник веде оборону по рубежу ");
            objWord.Selection.TypeText(textBox4.Text);
            objWord.Selection.TypeText(", його вогневі засоби виявлені: ");
            objWord.Selection.TypeText(textBox5.Text);
            objWord.Selection.TypeText(".\nПеред переднім краєм оборони противника виявлені дротяні загородження і мінне " +
                                       "поле.\n3. ");
            objWord.Selection.TypeText(textBox6.Text);
            objWord.Selection.TypeText(" з ");
            objWord.Selection.TypeText(textBox7.Text);
            objWord.Selection.TypeText(" в ніч з ");
            objWord.Selection.TypeText(textBox8.Text);
            objWord.Selection.TypeText(" на ");
            objWord.Selection.TypeText(textBox9.Text);
            objWord.Selection.TypeText(" здійснює пошук в районі: ");
            objWord.Selection.TypeText(textBox10.Text);
            objWord.Selection.TypeText(" з метою захоплення ");
            objWord.Selection.TypeText(textBox11.Text);
            objWord.Selection.TypeText(" зі складу ");
            objWord.Selection.TypeText(textBox12.Text);
            objWord.Selection.TypeText(", що зосереджений в районі: ");
            objWord.Selection.TypeText(textBox13.Text);
            objWord.Selection.TypeText(".\nДії взводу підтримують ");
            objWord.Selection.TypeText(textBox14.Text);
            objWord.Selection.TypeText(". Вогонь підготований по ");
            objWord.Selection.TypeText(textBox15.Text);
            objWord.Selection.TypeText(".\n");
            objWord.Selection.TypeText(textBox16.Text);
            objWord.Selection.TypeText(" - група захоплення. Приховано висунутись до ");
            objWord.Selection.TypeText(textBox17.Text);
            objWord.Selection.TypeText(". За моєю командою здійснити напад на об’єкт, захопити полоненого, документи і " +
                                       "доставити в розташування своїх військ.\nГрупа розгородження – старший ");
            objWord.Selection.TypeText(textBox18.Text);
            objWord.Selection.TypeText(", з двома розвідниками ");
            objWord.Selection.TypeText(textBox19.Text);
            objWord.Selection.TypeText(" і ");
            objWord.Selection.TypeText(textBox20.Text);
            objWord.Selection.TypeText(" висунутись до дротових загороджень противника, проробити і позначити прохід в " +
                                       "них і мінному полі і охороняти їх до виконання завдання взводом. Розвідники ");
            objWord.Selection.TypeText(textBox21.Text);
            objWord.Selection.TypeText(", з підходом ");
            objWord.Selection.TypeText(textBox22.Text);
            objWord.Selection.TypeText(" до проходу діють в складі відділення ");
            objWord.Selection.TypeText(textBox23.Text);
            objWord.Selection.TypeText(" - група забезпечення №1 приховано висувається в напрямку ");
            objWord.Selection.TypeText(textBox24.Text);
            objWord.Selection.TypeText(" і займає позицію в районі ");
            objWord.Selection.TypeText(textBox25.Text);
            objWord.Selection.TypeText(". Бути в готовності прикрити вогнем дії ");
            objWord.Selection.TypeText(textBox26.Text);
            objWord.Selection.TypeText(" і його відхід в розташування своїх військ.\n");
            objWord.Selection.TypeText(textBox27.Text);
            objWord.Selection.TypeText(" - група забезпечення №2, висунутись на позицію в районі ");
            objWord.Selection.TypeText(textBox28.Text);
            objWord.Selection.TypeText(". Бути в готовності не допустити ведення вогню і підходу противника з напрямку ");
            objWord.Selection.TypeText(textBox29.Text);
            objWord.Selection.TypeText(", в подальшому прикрити вогнем відхід ");
            objWord.Selection.TypeText(textBox30.Text);
            objWord.Selection.TypeText(" і ");
            objWord.Selection.TypeText(textBox31.Text);
            objWord.Selection.TypeText(" після виконання завдання.\nНапрямок руху ");
            objWord.Selection.TypeText(textBox32.Text);
            objWord.Selection.TypeText(".\nПершими до загородження противника висуваються сапери і розвідники ");
            objWord.Selection.TypeText(textBox33.Text);
            objWord.Selection.TypeText(", проробляють прохід і позначають його. По готовності проходу починає рух ");
            objWord.Selection.TypeText(textBox34.Text);
            objWord.Selection.TypeText(", за ним ");
            objWord.Selection.TypeText(textBox35.Text);
            objWord.Selection.TypeText(" і ");
            objWord.Selection.TypeText(textBox36.Text);
            objWord.Selection.TypeText(", я пересуваюсь з ");
            objWord.Selection.TypeText(textBox37.Text);
            objWord.Selection.TypeText(". Після заняття відділеннями вказаних позицій за моєю командою ");
            objWord.Selection.TypeText(textBox38.Text);
            objWord.Selection.TypeText(" здійснює напад на ");
            objWord.Selection.TypeText(textBox39.Text);
            objWord.Selection.TypeText(", захоплює полоненого, документи і відходить з ним в розташування своїх військ.\n" +
                                       "Після відходу ");
            objWord.Selection.TypeText(textBox40.Text);
            objWord.Selection.TypeText(" за моєю командою починає відхід ");
            objWord.Selection.TypeText(textBox41.Text);
            objWord.Selection.TypeText(", а потім ");
            objWord.Selection.TypeText(textBox42.Text);
            objWord.Selection.TypeText(". Після подолання загороджень противника (просування через загородження) займає " +
                                       "позицію з боку нашого фронту і забезпечує відхід всього ");
            objWord.Selection.TypeText(textBox43.Text);
            objWord.Selection.TypeText(", в вихідне положення.\nМаршрут відходу ");
            objWord.Selection.TypeText(textBox44.Text);
            objWord.Selection.TypeText(". У випадку виявлення противником взводу відхід здійснювати в тій же " +
                                       "послідовності під прикриттям вогню артилерії і мінометів.\nСигнали про готовність проходу в загородженнях - ");
            objWord.Selection.TypeText(textBox45.Text);
            objWord.Selection.TypeText("; виклика вогню - ");
            objWord.Selection.TypeText(textBox46.Text);
            objWord.Selection.TypeText("; припинення вогню - ");
            objWord.Selection.TypeText(textBox47.Text);
            objWord.Selection.TypeText(".\nЯ знаходжусь в ");
            objWord.Selection.TypeText(textBox48.Text);
            objWord.Selection.TypeText(", при виході до проходу в загородженні, в подальшому – з ");
            objWord.Selection.TypeText(textBox49.Text);
            objWord.Selection.TypeText(".\nМій заступник ");
            objWord.Selection.TypeText(textBox50.Text);
            objWord.Selection.TypeText(".\nПропуск ");
            objWord.Selection.TypeText(textBox51.Text);
            objWord.Selection.TypeText(";");

            try
            {
                Directory.CreateDirectory(Constant.RootToSaveGenerated);
                objDoc.SaveAs($"{Constant.RootToSaveGenerated}Form 8_2 {Constant.Date}");
                string path = objDoc.FullName;

                var dialog = new DialogPrintDocument("Підтвердити друк?");
                dialog.ShowDialog();
                if (dialog.Cancelled != true)
                {
                    objDoc.PrintOut();
                }

                objDoc.Close();
                objWord.Quit();

                var order = orderService.AddOrder(path, hashService.GetHash());
                if (order != null)
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Донесення занесено до бази даних!");
                    messageBox.ShowDialog();
                }
                else
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Сталася помилка! Донесення не занесено до бази даних!");
                    messageBox.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                CustomMessageBox messageBox = new CustomMessageBox(ex.Message);
                messageBox.ShowDialog();
            }
        }
        private void GenerateDocumentButton_Click(object sender, RoutedEventArgs e)
        {
            Word.Application objWord = new Word.Application
            {
                Visible = true
            };
            Word.Document objDoc;
            object        objMissing = System.Reflection.Missing.Value;

            objDoc = objWord.Documents.Add(ref objMissing, ref objMissing, ref objMissing, ref objMissing);
            Word.Range wordRan;
            wordRan = objDoc.Range(ref objMissing, ref objMissing);

            // Форматування
            wordRan.Font.Size = 14;
            wordRan.Font.Name = "Times New Roman";
            wordRan.ParagraphFormat.Alignment       = Word.WdParagraphAlignment.wdAlignParagraphJustify;
            wordRan.ParagraphFormat.LineSpacing     = 18;
            wordRan.ParagraphFormat.FirstLineIndent = objWord.InchesToPoints((float)0.5);
            wordRan.ParagraphFormat.SpaceAfter      = 0;
            wordRan.ParagraphFormat.SpaceBefore     = 0;

            // Генерація вмісту
            objWord.Selection.TypeText("В.4.6. Схема опорного пункту роти\nНа схемі опорного пункту роти:\n- орієнтири ");
            objWord.Selection.TypeText(textBox1.Text);
            objWord.Selection.TypeText(";\n- положення противника:\n- передній край ");
            objWord.Selection.TypeText(textBox2.Text);
            objWord.Selection.TypeText(";\n- рубежі розгортання ");
            objWord.Selection.TypeText(textBox3.Text);
            objWord.Selection.TypeText(";\n- смуга вогню роти ");
            objWord.Selection.TypeText(textBox4.Text);
            objWord.Selection.TypeText(";\n- опорні пункти взводів ");
            objWord.Selection.TypeText(textBox5.Text);
            objWord.Selection.TypeText(", їхні смуги вогню ");
            objWord.Selection.TypeText(textBox6.Text);
            objWord.Selection.TypeText(" і додаткові сектори обстрілу ");
            objWord.Selection.TypeText(textBox7.Text);
            objWord.Selection.TypeText(";\n- основні і запасні вогневі позиції ");
            objWord.Selection.TypeText(textBox8.Text);
            objWord.Selection.TypeText(" бойових машин піхоти (бронетранспортерів), танків, протитанкових і зенітних засобів;\n" +
                                       "- вогневі позиції, сектори обстрілу ");
            objWord.Selection.TypeText(textBox9.Text);
            objWord.Selection.TypeText(" вогневих засобів, які забезпечують фланги роти і проміжки між взводними опорними пунктами, а на " +
                                       "схемі опорного пункту механізованої роти і приданих танків;\n- ділянки зосередженого вогню роти і кожного взводу ");
            objWord.Selection.TypeText(textBox10.Text);
            objWord.Selection.TypeText(";\n- рубежі ");
            objWord.Selection.TypeText(textBox11.Text);
            objWord.Selection.TypeText(" відкриття вогню з танків, бойових машин піхоти; протитанкових керованих ракетних комплексів та " +
                                       "інших вогневих засобів;\n- район ");
            objWord.Selection.TypeText(textBox12.Text);
            objWord.Selection.TypeText(" зосередження і вогневі рубежі ");
            objWord.Selection.TypeText(textBox13.Text);
            objWord.Selection.TypeText(" бронегрупи;\n- позиції ");
            objWord.Selection.TypeText(textBox14.Text);
            objWord.Selection.TypeText(" і шляхи ");
            objWord.Selection.TypeText(textBox15.Text);
            objWord.Selection.TypeText(" маневру кочуючих вогневих засобів;\n- місця влаштування вогневих засад ");
            objWord.Selection.TypeText(textBox16.Text);
            objWord.Selection.TypeText(";\n- інженерні загородження ");
            objWord.Selection.TypeText(textBox17.Text);
            objWord.Selection.TypeText(", і фортифікаційні споруди;\n- проходи ");
            objWord.Selection.TypeText(textBox18.Text);
            objWord.Selection.TypeText(" в загородженнях для кочуючих вогневих засобів і діючих у вогневих засадах;\n- місця ");
            objWord.Selection.TypeText(textBox19.Text);
            objWord.Selection.TypeText(" розгортання пунктів технічного спостереження ");
            objWord.Selection.TypeText(textBox20.Text);
            objWord.Selection.TypeText(" бойового постачання ");
            objWord.Selection.TypeText(textBox21.Text);
            objWord.Selection.TypeText(" і медичного поста роти ");
            objWord.Selection.TypeText(textBox22.Text);
            objWord.Selection.TypeText(";\n- місця командно-спостережних пунктів роти і взводів ");
            objWord.Selection.TypeText(textBox23.Text);
            objWord.Selection.TypeText(".");

            try
            {
                Directory.CreateDirectory(Constant.RootToSaveGenerated);
                objDoc.SaveAs($"{Constant.RootToSaveGenerated}Form 4_6 {Constant.Date}");
                string path = objDoc.FullName;

                var dialog = new DialogPrintDocument("Підтвердити друк?");
                dialog.ShowDialog();
                if (dialog.Cancelled != true)
                {
                    objDoc.PrintOut();
                }

                objDoc.Close();
                objWord.Quit();

                var order = orderService.AddOrder(path, hashService.GetHash());
                if (order != null)
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Донесення занесено до бази даних!");
                    messageBox.ShowDialog();
                }
                else
                {
                    CustomMessageBox messageBox = new CustomMessageBox("Сталася помилка! Донесення не занесено до бази даних!");
                    messageBox.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                CustomMessageBox messageBox = new CustomMessageBox(ex.Message);
                messageBox.ShowDialog();
            }
        }
 private static void WriteWord(string filename)
 {
     Word.Application word = null;
     Word.Document    doc  = null;
     try {
         word         = new Word.Application();
         word.Visible = false;
         doc          = word.Documents.Add(Visible: false);
         {
             Word.PageSetup ps = doc.PageSetup;
             ps.Orientation = Word.WdOrientation.wdOrientLandscape;
             ps.TopMargin   = ps.BottomMargin = ps.LeftMargin = ps.RightMargin = word.InchesToPoints(0.5f);
             Word.TextColumns ts = ps.TextColumns;
             ts.SetCount(4);
         }
         int            columnLines = 0;
         Word.Paragraph p           = null;
         foreach (Household h in Households)
         {
             int    paraLines = 2;
             string content   = h.Name;
             if (h.Phone != "")
             {
                 ++paraLines;
                 content += String.Format("\vPhone: {0}", h.Phone);
             }
             if (h.Contacts.Count == 1)
             {
                 Contact c = h.Contacts[0];
                 if (c.CellPhone != "")
                 {
                     ++paraLines;
                     content += String.Format("\vCell: {0}", c.CellPhone);
                 }
                 if (c.Email != "")
                 {
                     ++paraLines;
                     content += String.Format("\vEmail: {0}", h.Email);
                 }
                 if (c.WorkEmail != "")
                 {
                     ++paraLines;
                     content += String.Format("\vWork Email: {0}", c.WorkEmail);
                 }
                 //if (c.Birthday.HasValue) {
                 //   ++paraLines;
                 //   content += String.Format("\vBirthday: {0:MMM d}", c.Birthday.Value);
                 //}
             }
             else
             {
                 foreach (Contact c in h.Contacts)
                 {
                     if (c.CellPhone != "")
                     {
                         ++paraLines;
                         content += String.Format("\v{0} Cell: {1}", c.First, c.CellPhone);
                     }
                 }
                 if (h.Email != "")
                 {
                     ++paraLines;
                     content += String.Format("\vEmail: {0}", h.Email);
                 }
                 else
                 {
                     foreach (Contact c in h.Contacts)
                     {
                         if (c.Email != "")
                         {
                             ++paraLines;
                             content += String.Format("\v{0} Email: {1}", c.First, c.Email);
                         }
                     }
                 }
                 foreach (Contact c in h.Contacts)
                 {
                     if (c.WorkEmail != "")
                     {
                         ++paraLines;
                         content += String.Format("\v{0} Work Email: {1}", c.First, c.Email);
                     }
                 }
                 //foreach (Contact c in h.Contacts) {
                 //   if (c.Birthday.HasValue) {
                 //      ++paraLines;
                 //      content += String.Format("\v{0} Birthday: {1:MMM d}", c.First, c.Birthday.Value);
                 //   }
                 //}
             }
             if (h.Address != "")
             {
                 ++paraLines;
                 content += "\vAddress:";
                 foreach (string line in h.Address.Split('\n'))
                 {
                     ++paraLines;
                     content += String.Format("\v\t{0}", line);
                 }
             }
             if (columnLines + paraLines > 50)
             {
                 content     = (char)14 + content;
                 columnLines = paraLines;
             }
             else
             {
                 columnLines += paraLines;
             }
             p                 = doc.Paragraphs.Add();
             p.Range.Text      = content;
             p.Range.Font.Bold = 0;
             p.Range.Font.Size = 8.0f;
             p.TabStops.Add(16.0f);
             doc.Range(p.Range.Start, p.Range.Start + content.IndexOf('\v')).Font.Bold = 1;
             p.Range.InsertParagraphAfter();
         }
         p = doc.Paragraphs.Add();
         p.Range.InsertBreak(Word.WdBreakType.wdPageBreak);
         p.Range.InsertParagraphAfter();
         Dictionary <int, List <Contact> > birthdays = Contacts
                                                       .Where(c => c.Birthday.HasValue)
                                                       .GroupBy(c => c.Birthday.Value.Month)
                                                       .ToDictionary(
             cg => cg.Key,
             cg => cg.OrderBy(c => c.Birthday).ToList()
             );
         foreach (var month in birthdays.OrderBy(k => k.Key))
         {
             string content = month.Value[0].Birthday.Value.ToString("MMMM");
             foreach (Contact c in month.Value.OrderBy(k => k.Birthday.Value.Day))
             {
                 content += String.Format("\v\t{0:MMM-d}: {1}", c.Birthday.Value, c.ShortName);
                 if (c.Birthday.Value < DateTime.Today)
                 {
                     content += String.Format(" ({0})", c.Birthday.Value.Year);
                 }
             }
             p                 = doc.Paragraphs.Last;
             p.Range.Text      = content;
             p.Range.Font.Bold = 0;
             p.Range.Font.Size = 12.0f;
             p.TabStops.Add(16.0f);
             doc.Range(p.Range.Start, p.Range.Start + content.IndexOf('\v')).Font.Bold = 1;
             p.Range.InsertParagraphAfter();
         }
     } finally {
         if (doc != null)
         {
             doc.SaveAs2(FileName: filename);
             doc.Close();
         }
         if (word != null)
         {
             word.Quit();
         }
     }
 }
Exemple #24
0
        /// <summary>
        /// For Calling FormatNumbering method in FormatNumbering content under legal Ribbon
        /// </summary>
        public void FormatNumbering()
        {
            StringBuilder sbTrace = new StringBuilder();

            try
            {
                sbTrace.AppendLine("Start");
                Logger.SaveLoggerTrace(sbTrace);
                Microsoft.Office.Interop.Word.Application appWord = default(Microsoft.Office.Interop.Word.Application);
                appWord = Globals.ThisAddIn.Application;
                appWord.ActiveDocument.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphJustify;
                appWord.ActiveDocument.UpdateStylesOnOpen   = false;
                //.BaseStyle = "Normal"
                object setStyle = GlobalEnumClass.Heading1;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading1].set_NextParagraphStyle(ref setStyle);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading1].ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading1].ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading1].ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading1].ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading1].ParagraphFormat.OutlineLevel    = WdOutlineLevel.wdOutlineLevel1;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading1].ParagraphFormat.TabStops.ClearAll();
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading1].Font.AllCaps   = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading1].Font.Bold      = (int)GlobalEnumClass.AllEnum.True;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading1].Font.Italic    = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading1].Font.Underline = WdUnderline.wdUnderlineNone;
                appWord.ActiveDocument.UpdateStylesOnOpen = false;

                setStyle = GlobalEnumClass.Heading2;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading2].set_NextParagraphStyle(ref setStyle);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading2].ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading2].ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading2].ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading2].ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading2].ParagraphFormat.OutlineLevel    = WdOutlineLevel.wdOutlineLevel2;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading2].ParagraphFormat.TabStops.ClearAll();
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading2].Font.AllCaps   = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading2].Font.Bold      = (int)GlobalEnumClass.AllEnum.True;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading2].Font.Italic    = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading2].Font.Underline = WdUnderline.wdUnderlineNone;
                appWord.ActiveDocument.UpdateStylesOnOpen = false;

                setStyle = GlobalEnumClass.Heading3;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading3].set_NextParagraphStyle(ref setStyle);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading3].ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading3].ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading3].ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading3].ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading3].ParagraphFormat.OutlineLevel    = WdOutlineLevel.wdOutlineLevel3;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading3].ParagraphFormat.TabStops.ClearAll();
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading3].Font.AllCaps   = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading3].Font.Bold      = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading3].Font.Italic    = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading3].Font.Underline = WdUnderline.wdUnderlineNone;
                appWord.ActiveDocument.UpdateStylesOnOpen = false;

                setStyle = GlobalEnumClass.Heading4;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading4].set_NextParagraphStyle(ref setStyle);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading4].ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading4].ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading4].ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading4].ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading4].ParagraphFormat.OutlineLevel    = WdOutlineLevel.wdOutlineLevel4;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading4].ParagraphFormat.TabStops.ClearAll();
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading4].Font.AllCaps   = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading4].Font.Bold      = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading4].Font.Italic    = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading4].Font.Underline = WdUnderline.wdUnderlineNone;

                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading5].AutomaticallyUpdate = false;
                //.BaseStyle = "Normal"
                setStyle = GlobalEnumClass.Heading5;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading5].set_NextParagraphStyle(ref setStyle);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading5].ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading5].ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading5].ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading5].ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading5].ParagraphFormat.OutlineLevel    = WdOutlineLevel.wdOutlineLevel5;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading5].ParagraphFormat.TabStops.ClearAll();
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading5].Font.AllCaps   = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading5].Font.Bold      = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading5].Font.Italic    = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading5].Font.Underline = WdUnderline.wdUnderlineNone;

                // _with1 = appWord.ActiveDocument.Styles[GlobalEnumClass.Heading6];
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading6].AutomaticallyUpdate = false;
                //.BaseStyle = "Normal"
                setStyle = GlobalEnumClass.Heading6;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading6].set_NextParagraphStyle(ref setStyle);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading6].ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading6].ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading6].ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading6].ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading6].ParagraphFormat.OutlineLevel    = WdOutlineLevel.wdOutlineLevel6;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading6].ParagraphFormat.TabStops.ClearAll();
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading6].Font.AllCaps   = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading6].Font.Bold      = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading6].Font.Italic    = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading6].Font.Underline = WdUnderline.wdUnderlineNone;

                // _with1 = appWord.ActiveDocument.Styles[GlobalEnumClass.Heading7];
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading7].AutomaticallyUpdate = false;
                //.BaseStyle = "Normal"
                setStyle = "Body Text";
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading7].set_NextParagraphStyle(ref setStyle);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading7].ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading7].ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading7].ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading7].ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading7].ParagraphFormat.OutlineLevel    = WdOutlineLevel.wdOutlineLevel7;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading7].ParagraphFormat.TabStops.ClearAll();
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading7].Font.AllCaps   = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading7].Font.Bold      = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading7].Font.Italic    = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading7].Font.Underline = WdUnderline.wdUnderlineNone;

                //_with1 = appWord.ActiveDocument.Styles[GlobalEnumClass.Heading8];
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading8].AutomaticallyUpdate = false;
                //.BaseStyle = "Normal"
                setStyle = "Body Text";
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading8].set_NextParagraphStyle(ref setStyle);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading8].ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading8].ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading8].ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading8].ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
                //appWord.ActiveDocument.Styles[GlobalEnumClass.Heading8].ParagraphFormat.OutlineLevel = WdOutlineLevel.wdOutlineLevel8;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading8].ParagraphFormat.TabStops.ClearAll();
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading8].Font.AllCaps   = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading8].Font.Bold      = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading8].Font.Italic    = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading8].Font.Underline = WdUnderline.wdUnderlineNone;

                //_with1 = appWord.ActiveDocument.Styles[GlobalEnumClass.Heading9];
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading9].AutomaticallyUpdate = false;
                //.BaseStyle = "Normal"
                setStyle = "Body Text";
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading9].set_NextParagraphStyle(ref setStyle);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading9].ParagraphFormat.LeftIndent      = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading9].ParagraphFormat.RightIndent     = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading9].ParagraphFormat.Alignment       = WdParagraphAlignment.wdAlignParagraphJustify;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading9].ParagraphFormat.FirstLineIndent = appWord.InchesToPoints(0);
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading9].Font.AllCaps   = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading9].Font.Bold      = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading9].Font.Italic    = (int)GlobalEnumClass.AllEnum.False;
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading9].Font.Underline = WdUnderline.wdUnderlineNone;

                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].Reset(6);

                //var _withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1];
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].NumberFormat             = "SECTION %1.";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].TrailingCharacter        = WdTrailingCharacter.wdTrailingTab;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].NumberStyle              = WdListNumberStyle.wdListNumberStyleArabic;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].NumberPosition           = appWord.InchesToPoints(0);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].Alignment                = WdListLevelAlignment.wdListLevelAlignLeft;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].TextPosition             = appWord.InchesToPoints(1);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].TabPosition              = appWord.InchesToPoints(1);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].ResetOnHigher            = 0;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].StartAt                  = 1;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].Font.Bold                = (int)GlobalEnumClass.AllEnum.True;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].Font.Italic              = (int)GlobalEnumClass.AllEnum.False;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].Font.AllCaps             = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].Font.Size                = (float)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].Font.Animation           = (WdAnimation)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].Font.DoubleStrikeThrough = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].Font.Name                = "";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].Font.Underline           = WdUnderline.wdUnderlineNone;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[1].LinkedStyle              = GlobalEnumClass.Heading1;

                //_withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2];
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].NumberFormat             = "%1.%2";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].TrailingCharacter        = WdTrailingCharacter.wdTrailingTab;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].NumberStyle              = WdListNumberStyle.wdListNumberStyleLegal;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].NumberPosition           = appWord.InchesToPoints(1);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].Alignment                = WdListLevelAlignment.wdListLevelAlignLeft;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].TextPosition             = appWord.InchesToPoints(0);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].TabPosition              = appWord.InchesToPoints(1.5f);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].ResetOnHigher            = 1;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].StartAt                  = 1;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].Font.Bold                = (int)GlobalEnumClass.AllEnum.True;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].Font.Italic              = (int)GlobalEnumClass.AllEnum.False;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].Font.AllCaps             = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].Font.Size                = (float)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].Font.DoubleStrikeThrough = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].Font.Name                = "";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].Font.Underline           = WdUnderline.wdUnderlineNone;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[2].LinkedStyle              = GlobalEnumClass.Heading2;

                //_withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3];
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].NumberFormat             = "%1.%2.%3.";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].TrailingCharacter        = WdTrailingCharacter.wdTrailingTab;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].NumberStyle              = WdListNumberStyle.wdListNumberStyleArabic;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].NumberPosition           = appWord.InchesToPoints(1.5f);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].Alignment                = WdListLevelAlignment.wdListLevelAlignLeft;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].TextPosition             = appWord.InchesToPoints(0);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].TabPosition              = appWord.InchesToPoints(2);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].ResetOnHigher            = 2;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].StartAt                  = 1;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].Font.Bold                = (int)GlobalEnumClass.AllEnum.False;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].Font.Italic              = (int)GlobalEnumClass.AllEnum.False;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].Font.AllCaps             = (int)GlobalEnumClass.AllEnum.False;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].Font.Size                = (float)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].Font.Animation           = (WdAnimation)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].Font.DoubleStrikeThrough = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].Font.Name                = "";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].Font.Underline           = WdUnderline.wdUnderlineNone;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[3].LinkedStyle              = GlobalEnumClass.Heading3;

                //_withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4];
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].NumberFormat             = "(%4)";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].TrailingCharacter        = WdTrailingCharacter.wdTrailingTab;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].NumberStyle              = WdListNumberStyle.wdListNumberStyleLowercaseLetter;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].NumberPosition           = appWord.InchesToPoints(2.0f);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].Alignment                = WdListLevelAlignment.wdListLevelAlignLeft;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].TextPosition             = appWord.InchesToPoints(0);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].TabPosition              = appWord.InchesToPoints(2.5f);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].ResetOnHigher            = 3;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].StartAt                  = 1;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].Font.Bold                = (int)GlobalEnumClass.AllEnum.False;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].Font.Italic              = (int)GlobalEnumClass.AllEnum.False;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].Font.AllCaps             = (int)GlobalEnumClass.AllEnum.False;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].Font.Size                = (float)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].Font.DoubleStrikeThrough = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].Font.Name                = "";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].Font.Underline           = WdUnderline.wdUnderlineNone;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[4].LinkedStyle              = GlobalEnumClass.Heading4;

                // _withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5];
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].NumberFormat             = "%5.";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].TrailingCharacter        = WdTrailingCharacter.wdTrailingTab;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].NumberStyle              = WdListNumberStyle.wdListNumberStyleLowercaseRoman;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].NumberPosition           = appWord.InchesToPoints(2);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].Alignment                = WdListLevelAlignment.wdListLevelAlignLeft;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].TextPosition             = appWord.InchesToPoints(0.5f);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].TabPosition              = appWord.InchesToPoints(2.5F);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].ResetOnHigher            = 4;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].StartAt                  = 1;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].Font.Bold                = (int)GlobalEnumClass.AllEnum.False;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].Font.Italic              = (int)GlobalEnumClass.AllEnum.False;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].Font.AllCaps             = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].Font.Size                = (float)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].Font.Animation           = (WdAnimation)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].Font.DoubleStrikeThrough = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].Font.Name                = "";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].Font.Underline           = WdUnderline.wdUnderlineNone;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[5].LinkedStyle              = GlobalEnumClass.Heading5;

                //_withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6];
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].NumberFormat             = "%6";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].TrailingCharacter        = WdTrailingCharacter.wdTrailingTab;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].NumberStyle              = WdListNumberStyle.wdListNumberStyleLowercaseLetter;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].NumberPosition           = appWord.InchesToPoints(2.5f);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].Alignment                = WdListLevelAlignment.wdListLevelAlignLeft;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].TextPosition             = appWord.InchesToPoints(0.5f);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].TabPosition              = appWord.InchesToPoints(3);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].ResetOnHigher            = 5;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].StartAt                  = 1;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].Font.Bold                = (int)GlobalEnumClass.AllEnum.False;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].Font.Italic              = (int)GlobalEnumClass.AllEnum.False;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].Font.AllCaps             = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].Font.Size                = (float)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].Font.Animation           = (WdAnimation)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].Font.DoubleStrikeThrough = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].Font.Name                = "";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].Font.Underline           = WdUnderline.wdUnderlineNone;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[6].LinkedStyle              = GlobalEnumClass.Heading6;

                //_withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7];
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].NumberFormat             = "%7";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].TrailingCharacter        = WdTrailingCharacter.wdTrailingTab;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].NumberStyle              = WdListNumberStyle.wdListNumberStyleUppercaseLetter;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].NumberPosition           = appWord.InchesToPoints(3);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].Alignment                = WdListLevelAlignment.wdListLevelAlignLeft;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].TextPosition             = appWord.InchesToPoints(0.5f);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].TabPosition              = appWord.InchesToPoints(3.5f);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].ResetOnHigher            = 6;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].StartAt                  = 1;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].Font.Bold                = (int)GlobalEnumClass.AllEnum.False;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].Font.Italic              = (int)GlobalEnumClass.AllEnum.False;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].Font.AllCaps             = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].Font.Size                = (float)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].Font.Animation           = (WdAnimation)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].Font.DoubleStrikeThrough = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].Font.Name                = "";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].Font.Underline           = WdUnderline.wdUnderlineNone;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[7].LinkedStyle              = GlobalEnumClass.Heading7;

                //_withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8];
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].NumberFormat             = "%8";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].TrailingCharacter        = WdTrailingCharacter.wdTrailingNone;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].NumberStyle              = WdListNumberStyle.wdListNumberStyleNone;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].NumberPosition           = appWord.InchesToPoints(0);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].Alignment                = WdListLevelAlignment.wdListLevelAlignLeft;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].TextPosition             = appWord.InchesToPoints(0);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].TabPosition              = appWord.InchesToPoints(0);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].ResetOnHigher            = 7;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].StartAt                  = 1;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].Font.Bold                = (int)GlobalEnumClass.AllEnum.False;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].Font.Italic              = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].Font.AllCaps             = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].Font.Size                = (float)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].Font.Animation           = (WdAnimation)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].Font.DoubleStrikeThrough = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].Font.Name                = "";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].Font.Underline           = WdUnderline.wdUnderlineNone;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[8].LinkedStyle              = GlobalEnumClass.Heading8;

                //_withList = appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9];
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].NumberFormat             = "%9.";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].TrailingCharacter        = WdTrailingCharacter.wdTrailingNone;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].NumberStyle              = WdListNumberStyle.wdListNumberStyleLowercaseRoman;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].NumberPosition           = appWord.InchesToPoints(0);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].Alignment                = WdListLevelAlignment.wdListLevelAlignLeft;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].TextPosition             = appWord.InchesToPoints(0);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].TabPosition              = appWord.InchesToPoints(0);
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].ResetOnHigher            = 8;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].StartAt                  = 1;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].Font.Bold                = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].Font.Italic              = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].Font.AllCaps             = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].Font.Underline           = (WdUnderline)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].Font.Size                = (float)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].Font.Animation           = (WdAnimation)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].Font.DoubleStrikeThrough = (int)WdConstants.wdUndefined;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].Font.Name                = "";
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].Font.Underline           = WdUnderline.wdUnderlineNone;
                appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6].ListLevels[9].LinkedStyle              = GlobalEnumClass.Heading9;
            }
            catch (Exception ex)
            {
                sbTrace.Clear();
                sbTrace.AppendLine("Exception" + ex);
                Logger.SaveLoggerTrace(sbTrace);
                Logger.LogWriter(ex.StackTrace);
            }
            finally
            {
                sbTrace.Clear();
                sbTrace.AppendLine("End");
                Logger.SaveLoggerTrace(sbTrace);
            }
        }
Exemple #25
0
        private void ExporttoWord(string aFlag, string aSort)
        {
            if (lsGdb.Gdb.State == ConnectionState.Closed)
            {
                lsGdb.ConnectDatabase();
            }
            else
            {
                lsGdb.Gdb.Close();
                lsGdb.Gdb.Open();
                //lsGdb.ConnectDatabase();
            }
            string sql = "Select count(*) cnt From meetingcontact Where meetingid = '" + TxtMeetingID.Text + "' and contactname <> '' and flagvisit = '1'";

            if (aFlag == "1")
            {
                sql = "Select count(*) cnt From meetingcontact Where meetingid = '" + TxtMeetingID.Text + "' and contactname <> ''";
            }
            else
            {
                sql = "Select count(*) cnt From meetingcontact Where meetingid = '" + TxtMeetingID.Text + "' and contactname <> '' and flagvisit = '1'";
            }

            Int32           liCnt = 0, i = 0;
            MySqlCommand    lsComm = new MySqlCommand(sql, lsGdb.Gdb);
            MySqlDataReader lsRead;

            lsRead = lsComm.ExecuteReader();
            if (lsRead.HasRows)
            {
                while (lsRead.Read())
                {
                    liCnt = Convert.ToInt32(lsRead["cnt"].ToString());
                }
            }
            lsRead.Close();
            if (liCnt == 0)
            {
                MessageBox.Show("äÁèÁÕ¢éÍÁÙÅ", "Export");
                return;
            }
            string[,] lsArr = new string[liCnt + 1, 4];
            if (aFlag == "1")
            {
                if (aSort == "memnamet")
                {
                    sql = "Select mc.contactname, mc.companyname, mc.tmemnamet, mc.memnamet, m.skk9id "
                          + "From meetingcontact mc left join member m on mc.memid = m.memid "
                          + "Where mc.meetingid = '" + TxtMeetingID.Text + "' and mc.contactname <> '' Order By mc.tmemnamet, mc.memnamet";
                }
                else
                {
                    sql = "Select mc.contactname, mc.companyname, mc.tmemnamet, mc.memnamet, m.skk9id "
                          + "From meetingcontact mc left join member m on mc.memid = m.memid "
                          + "Where mc.meetingid = '" + TxtMeetingID.Text + "' and mc.contactname <> '' Order By mc.tmemnamet, mc.memnamet";
                }
            }
            else
            {
                if (aSort == "memnamet")
                {
                    sql = "Select mc.contactname, mc.companyname, mc.tmemnamet, mc.memnamet, m.skk9id "
                          + "From meetingcontact mc left join member m on mc.memid = m.memid "
                          + "Where mc.meetingid = '" + TxtMeetingID.Text + "' and mc.contactname <> '' and mc.flagvisit = '1' Order By tmemnamet, mc.memnamet";
                }
                else
                {
                    sql = "Select mc.contactname, mc.companyname, mc.tmemnamet, mc.memnamet, m.skk9id "
                          + "From meetingcontact mc left join member m on mc.memid = m.memid "
                          + "Where mc.meetingid = '" + TxtMeetingID.Text + "' and mc.contactname <> '' and mc.flagvisit = '1' Order By mc.tmemnamet, mc.companyname";
                }
            }
            lsComm.CommandText = sql;
            lsRead             = lsComm.ExecuteReader();
            if (lsRead.HasRows)
            {
                while (lsRead.Read())
                {
                    lsArr[i, 0] = lsRead["contactname"].ToString();
                    lsArr[i, 1] = lsRead["memnamet"].ToString();
                    lsArr[i, 2] = lsRead["tmemnamet"].ToString();
                    lsArr[i, 3] = lsRead["skk9id"].ToString();
                    i++;
                }
            }
            lsRead.Close();

            string lsMeetingFileName = lsIni.GetString("thahr30", "exportmeetingfilename", "meeting.doc");


            object oMissing  = System.Reflection.Missing.Value;
            object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */

            //Start Word and create a new document.
            Word._Application oWord;
            Word._Document    oDoc;
            oWord         = new Word.Application();
            oWord.Visible = true;
            oDoc          = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            //Insert a paragraph at the beginning of the document.
            Word.Paragraph oPara1;
            oPara1                   = oDoc.Content.Paragraphs.Add(ref oMissing);
            oPara1.Range.Text        = TxtMeetingNameT.Text;
            oPara1.Range.Font.Bold   = 1;
            oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.
            oPara1.Range.InsertParagraphAfter();
            oPara1.Range.Text        = TxtDescription.Text;
            oPara1.Range.Font.Bold   = 1;
            oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.
            oPara1.Range.InsertParagraphAfter();
            oPara1.Range.Text = TxtPlace.Text;

            //Insert a paragraph at the end of the document.
            //Word.Paragraph oPara2;
            object oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;

            //oPara2 = oDoc.Content.Paragraphs.Add(ref oRng);
            //oPara2.Range.Text = "Heading 2";
            //oPara2.Format.SpaceAfter = 6;
            //oPara2.Range.InsertParagraphAfter();

            ////Insert another paragraph.
            //Word.Paragraph oPara3;
            //oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            //oPara3 = oDoc.Content.Paragraphs.Add(ref oRng);
            //oPara3.Range.Text = "This is a sentence of normal text. Now here is a table:";
            //oPara3.Range.Font.Bold = 0;
            //oPara3.Format.SpaceAfter = 24;
            //oPara3.Range.InsertParagraphAfter();

            //Insert a 3 x 5 table, fill it with data, and make the first row
            //bold and italic.
            Word.Table oTable;
            Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oTable = oDoc.Tables.Add(wrdRng, liCnt, 5, ref oMissing, ref oMissing);
            oTable.Range.ParagraphFormat.SpaceAfter = 6;
            oTable.Rows[1].Range.Font.Bold          = 1;
            oTable.Rows[1].Range.Font.Italic        = 1;

            oTable.Columns[1].Width = oWord.InchesToPoints(1); //Change width of columns 1 & 2
            oTable.Columns[2].Width = oWord.InchesToPoints(3);
            oTable.Columns[3].Width = oWord.InchesToPoints(3);
            oTable.Columns[4].Width = oWord.InchesToPoints(4);
            oTable.Columns[5].Width = oWord.InchesToPoints(5);
            int    r, c;
            string strText;

            for (r = 0; r <= liCnt - 1; r++)
            {
                for (c = 0; c <= 5; c++)
                {
                    strText = "r" + r + "c" + c;
                    switch (c)
                    {
                    case 1:
                    {
                        oTable.Cell(r, c).Range.Text = r.ToString();
                        break;
                    }

                    case 2:
                    {
                        oTable.Cell(r, c).Range.Text = lsArr[r, 0].ToString();
                        break;
                    }

                    case 3:
                    {
                        oTable.Cell(r, c).Range.Text = lsArr[r, 1].ToString();
                        break;
                    }

                    case 4:
                    {
                        oTable.Cell(r, c).Range.Text = lsArr[r, 2].ToString();
                        break;
                    }

                    case 5:
                    {
                        oTable.Cell(r, c).Range.Text = lsArr[r, 3].ToString();
                        break;
                    }
                    }
                }
            }
            //Add text after the chart.
            wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            wrdRng.InsertParagraphAfter();
            wrdRng.InsertAfter("THE END.");


            //Process myProcess = new Process();
            //string myDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            //myProcess.StartInfo.FileName = Application.StartupPath + "\\" + lsMeetingFileName;
            //myProcess.StartInfo.CreateNoWindow = true;
            //myProcess.Start();
            Cursor.Current = System.Windows.Forms.Cursors.Default;
            Cursor.Show();
            MessageBox.Show("Export to Word success", "Export");
        }