Example #1
0
    public void BindGallery()
    {
        DataSet dsa = new DataSet();

        dsa = objsql.GetDataset("select * from tblGallery where Status='1' and Album_Code='" + Cache["gid"].ToString() + "'");
        if (dsa.Tables[0].Rows.Count > 0)
        {
            ListGallery.DataSource = dsa;
            ListGallery.DataBind();
        }
        dsa.Clear();
    }
 private static void ApplyListTemplate(ListGallery listGallery, ListFormat listFormat, int level = 1)
 {
     listFormat.ApplyListTemplateWithLevel(
         listGallery.ListTemplates[level],
         ContinuePreviousList: true,
         ApplyTo: WdListApplyTo.wdListApplyToSelection,
         DefaultListBehavior: WdDefaultListBehavior.wdWord10ListBehavior,
         ApplyLevel: level);
 }
        //! Begin the document.
        /*!
          Open a new Word application and a new document with the given template. After that it set the styles
        */
        /// <summary>
        /// Begin the document.
        /// Open a new Word application and a new document with the given template. After that it set the styles
        /// </summary>
        protected override void BeginDocument()
        {
            this.markupStack = new List<dynamic>();
            this.hyperStack = new List<dynamic>();
            //this.tableStack = new List<dynamic>();
            this.listStack = new List<dynamic>();
            /*Type wordType = Type.GetTypeFromProgID("Word.Application");
            if (wordType == null)
            {
                throw new DocumentException("Failed to create word application. Check whether Word installation is correct");
            }*/
            //this.word = Activator.CreateInstance(wordType);
            this.word = new Application();
            if (this.word == null)
            {
                throw new DocumentException("Failed to create word application. Check whether Word installation is correct");
            }

            String oTemplate = Path.GetFullPath(@"..\..\quickstyles\"+ currentTemplate.ToString() +".dotx");
            try
            {
                this.doc = this.word.Documents.Add(oTemplate);
            }
            catch(Exception)
            {
                oTemplate = Path.GetFullPath(@"..\..\..\SoftwareEngineeringTools\quickstyles\" + currentTemplate.ToString() + ".dotx");
                this.doc = this.word.Documents.Add(oTemplate);
            }
            //setTableStyle();
            this.word.Visible = ShowWord;
            if (this.doc == null)
            {
                throw new DocumentException("Failed to create word document. Check whether Word installation is correct");
            }
            this.sel = this.word.Selection;
            if (this.word.Options.Overtype)
            {
                this.word.Options.Overtype = false;
            }
            this.normalStyle = this.doc.Styles[WdBuiltinStyle.wdStyleNormal];
            this.boldedStyle = this.doc.Styles.Add(Name: "Bolded", Type: WdStyleType.wdStyleTypeCharacter);
            this.verbatimStyle = this.doc.Styles.Add(Name: "Verbatim", Type: WdStyleType.wdStyleTypeCharacter);
            this.verbatimStyle.Font.Name = "Courier New";
            this.verbatimStyle.Font.Size = this.normalStyle.Font.Size - 2;
            listGallery = this.doc.Application.ListGalleries[WdListGalleryType.wdBulletGallery];
            setColor();
        }
        public void GenerateList()
        {
            Application app      = null;
            Document    doc      = null;
            string      filePath = "c:\\output.docx";
            string      pdfPath  = "c:\\export.pdf";

            try
            {
                app         = new Application();
                app.Visible = false;        // Open Microsoft Office in background
                doc         = app.Documents.Open(filePath, Missing.Value, false);
                Range  range  = doc.Range();
                string search = "$list";

                // Find in document to generate list
                while (range.Find.Execute(search))
                {
                    ListGallery listGallery =
                        app.ListGalleries[WdListGalleryType.wdNumberGallery];
                    // Select found location
                    range.Select();
                    // Apply multi level list
                    app.Selection.Range.ListFormat.ApplyListTemplateWithLevel(
                        listGallery.ListTemplates[1],
                        ContinuePreviousList: false,
                        ApplyTo: WdListApplyTo.wdListApplyToWholeList,
                        DefaultListBehavior: WdDefaultListBehavior.wdWord10ListBehavior);
                    // First level
                    app.Selection.TypeText("Root Item A"); // Set text to key in
                    app.Selection.TypeParagraph();         // Simulate typing in MS Word
                    // Go to 2nd level
                    app.Selection.Range.ListFormat.ListIndent();
                    app.Selection.TypeText("Child Item A.1");
                    app.Selection.TypeParagraph();
                    app.Selection.TypeText("Child Item A.2");
                    app.Selection.TypeParagraph();
                    // Back to 1st level
                    app.Selection.Range.ListFormat.ListOutdent();
                    app.Selection.TypeText("Root Item B");
                    app.Selection.TypeParagraph();
                    // Go to 2nd level
                    app.Selection.Range.ListFormat.ListIndent();
                    app.Selection.TypeText("Child Item B.1");
                    app.Selection.TypeParagraph();
                    app.Selection.TypeText("Child Item B.2");
                    app.Selection.TypeParagraph();
                    // Delete empty item generated by app.Selection.TypeParagraph();
                    app.Selection.TypeBackspace();
                }
                // Save document
                doc.Save();
                // Export to pdf
                doc.ExportAsFixedFormat(pdfPath, WdExportFormat.wdExportFormatPDF);
            }
            catch (System.Exception ex)
            {
                LogError(ex);
            }
            finally
            {
                if (doc != null)
                {
                    // Need to close the document to prevent deadlock
                    doc.Close(false);
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(doc);
                }
                if (app != null)
                {
                    app.Quit();
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(app);
                }
            }
        }