예제 #1
0
        /// <summary>
        /// For Display format numbering Form
        /// </summary>
        public void ParNumValues()
        {
            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;
                if (appWord.ActiveWindow.View.SplitSpecial == WdSpecialPane.wdPaneNone)
                {
                    appWord.ActiveWindow.ActivePane.View.Type = WdViewType.wdNormalView;
                }
                else
                {
                    appWord.ActiveWindow.View.Type = WdViewType.wdNormalView;
                }
                if (form.opt1.Checked)
                {
                    //ParagraphStyle1
                    NumberingClass1.Instance.FormatNumbering();
                }
                else if (form.opt2.Checked)
                {
                    //ParagraphStyle2
                    NumberingClass2.Instance.FormatNumbering();
                }
                else if (form.opt3.Checked)
                {
                    //ParagraphStyle3
                    NumberingClass3.Instance.FormatNumbering();
                }
                else if (form.opt4.Checked)
                {
                    //ParagraphStyle4
                    NumberingClass4.Instance.FormatNumbering();
                }
                else if (form.opt5.Checked)
                {
                    //ParagraphStyle5
                    NumberingClass5.Instance.FormatNumbering();
                }
                else if (form.opt6.Checked)
                {
                    //ParagraphStyle6
                    NumberingClass6.Instance.FormatNumbering();
                }
                else if (form.opt7.Checked)
                {
                    //ParagraphStyle7
                    NumberingClass7.Instance.FormatNumbering();
                }
                else if (form.opt8.Checked)
                {
                    //ParagraphStyle8
                    NumberingClass8.Instance.FormatNumbering();
                }
                else if (form.opt9.Checked)
                {
                    //ParagraphStyle9
                    NumberingClass9.Instance.FormatNumbering();
                }
                else if (form.opt10.Checked)
                {
                    //ParagraphStyle10
                    NumberingClass10.Instance.FormatNumbering();
                }
                else if (form.opt11.Checked)
                {
                    //ParagraphStyle11
                    NumberingClass11.Instance.FormatNumbering();
                }
                else if (form.opt12.Checked)
                {
                    //ParagraphStyle12
                    NumberingClass12.Instance.FormatNumbering();
                }
                else if (form.opt13.Checked)
                {
                    //ParagraphStyle13
                    NumberingClass13.Instance.FormatNumbering();
                }
                else if (form.opt14.Checked)
                {
                    //ParagraphStyle14
                    NumberingClass14.Instance.FormatNumbering();
                }
                else if (form.opt15.Checked)
                {
                    //ParagraphStyle15
                    NumberingClass15.Instance.FormatNumbering();
                }

                else if (form.opt16.Checked)
                {
                    //ParagraphStyle16
                    NumberingClass16.Instance.FormatNumbering();
                }
                else if (form.opt17.Checked)
                {
                    //ParagraphStyle17
                    NumberingClass17.Instance.FormatNumbering();
                }
                else if (form.opt18.Checked)
                {
                    //ParagraphStyle18
                    NumberingClass18.Instance.FormatNumbering();
                }
                else if (form.opt19.Checked)
                {
                    //ParagraphStyle19
                    NumberingClass19.Instance.FormatNumbering();
                }
                else if (form.opt20.Checked)
                {
                    //ParagraphStyle20
                    NumberingClass20.Instance.FormatNumbering();
                }
                else if (form.opt21.Checked)
                {
                    //ParagraphStyle21
                    NumberingClass21.Instance.FormatNumbering();
                }
                appWord.ActiveDocument.Styles[GlobalEnumClass.Heading1].LinkToListTemplate(ListTemplate: appWord.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[6], ListLevelNumber: 1);

                if (appWord.ActiveWindow.View.SplitSpecial == WdSpecialPane.wdPaneNone)
                {
                    appWord.ActiveWindow.ActivePane.View.Type = WdViewType.wdPrintView;
                }
                else
                {
                    appWord.ActiveWindow.View.Type = WdViewType.wdPrintView;
                }

                appWord.Selection.HomeKey(Unit: WdUnits.wdStory);
                appWord.Application.GoBack();
                //form.Hide();
            }
            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);
            }
        }
        private void CreateDocument(String cellResult)
        {
            try
            {
                //Create an instance for word app
                Microsoft.Office.Interop.Word.Application winword = new Microsoft.Office.Interop.Word.Application();

                //Set animation status for word application
                winword.ShowAnimation = false;

                //Set status for word application is to be visible or not.
                winword.Visible = false;

                //Create a missing variable for missing value
                object missing = System.Reflection.Missing.Value;

                //Create a new document
                Microsoft.Office.Interop.Word.Document document = winword.Documents.Add(ref missing, ref missing, ref missing, ref missing);

                //Add header into the document

                /*foreach (Microsoft.Office.Interop.Word.Section section in document.Sections)
                 * {
                 *  //Get the header range and add the header details.
                 *  Microsoft.Office.Interop.Word.Range headerRange = section.Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                 *  headerRange.Fields.Add(headerRange, Microsoft.Office.Interop.Word.WdFieldType.wdFieldPage);
                 *  headerRange.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                 *  headerRange.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdBlue;
                 *  headerRange.Font.Size = 10;
                 *  headerRange.Text = "Header text goes here";
                 * }
                 *
                 * //Add the footers into the document
                 * foreach (Microsoft.Office.Interop.Word.Section wordSection in document.Sections)
                 * {
                 *  //Get the footer range and add the footer details.
                 *  Microsoft.Office.Interop.Word.Range footerRange = wordSection.Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                 *  footerRange.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdDarkRed;
                 *  footerRange.Font.Size = 10;
                 *  footerRange.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                 *  footerRange.Text = "Footer text goes here";
                 * }*/

                //adding text to document
                document.Content.SetRange(0, 0);
                document.Content.Text = cellResult;

                //Save the document
                object filename = @"E:\temp1.docx";
                document.SaveAs2(ref filename);
                document.Close(ref missing, ref missing, ref missing);
                document = null;
                winword.Quit(ref missing, ref missing, ref missing);
                winword = null;
                MessageBox.Show("Document created successfully !");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }