Esempio n. 1
0
        public int ProcessDocument()
        {
            AccessHelper helper = new AccessHelper(); //helper物件用來取得ischool相關資料。

            mdoc = new Document();                    //產生新的文件,用來合併每位學生的懲戒通知單
            mdoc.Sections.Clear();                    //先將新文件的節做清除

            //判斷是否要使用預設的樣版或是自訂樣版
            if (mPreference.UseDefaultTemplate)
            {
                template = new DisciplineNotificationTemplate(new MemoryStream(Properties.Resources.獎懲通知單_住址位移));
            }
            else
            {
                template = new DisciplineNotificationTemplate(mPreference.CustomizeTemplate);
            }

            template.ProcessDocument();

            List <StudentRecord> students = new List <StudentRecord>();

            if (IsClass)
            {
                foreach (ClassRecord crecord in helper.ClassHelper.GetSelectedClass())
                {
                    students.AddRange(crecord.Students);
                }
            }
            else
            {
                students.AddRange(helper.StudentHelper.GetSelectedStudent());
            }

            //填入獎懲資訊
            helper.StudentHelper.FillReward(students);

            //填入連絡資訊
            helper.StudentHelper.FillContactInfo(students);

            //填入家長資訊
            helper.StudentHelper.FillParentInfo(students);

            //循訪每位學生記錄,並建立ActivityNotificationDocument物件來產生報表
            foreach (StudentRecord student in students)
            {
                ISchoolDocument studentdoc = new DisciplineNotificationDocument(student, mconfig, template);

                //將單一學生的每月生活通知單加入到主要的報表當中
                if (studentdoc.ProcessDocument() > 0)
                {
                    mdoc.Sections.Add(mdoc.ImportNode(studentdoc.Document.Sections[0], true));
                }
            }

            return(0);
        }
        public void ImportNodeCustom()
        {
            //ExStart
            //ExFor:DocumentBase.ImportNode(Node, System.Boolean, ImportFormatMode)
            //ExSummary:Shows how to import node from source document to destination document with specific options.
            // Create two documents and add a character style to each document.
            // Configure the styles to have the same name, but different text formatting.
            Document srcDoc   = new Document();
            Style    srcStyle = srcDoc.Styles.Add(StyleType.Character, "My style");

            srcStyle.Font.Name = "Courier New";
            DocumentBuilder srcBuilder = new DocumentBuilder(srcDoc);

            srcBuilder.Font.Style = srcStyle;
            srcBuilder.Writeln("Source document text.");

            Document dstDoc   = new Document();
            Style    dstStyle = dstDoc.Styles.Add(StyleType.Character, "My style");

            dstStyle.Font.Name = "Calibri";
            DocumentBuilder dstBuilder = new DocumentBuilder(dstDoc);

            dstBuilder.Font.Style = dstStyle;
            dstBuilder.Writeln("Destination document text.");

            // Import the Section from the destination document into the source document, causing a style name collision.
            // If we use destination styles, then the imported source text with the same style name
            // as destination text will adopt the destination style.
            Section importedSection = (Section)dstDoc.ImportNode(srcDoc.FirstSection, true, ImportFormatMode.UseDestinationStyles);

            Assert.AreEqual("Source document text.", importedSection.Body.Paragraphs[0].Runs[0].GetText().Trim()); //ExSkip
            Assert.IsNull(dstDoc.Styles["My style_0"]);                                                            //ExSkip
            Assert.AreEqual(dstStyle.Font.Name, importedSection.Body.FirstParagraph.Runs[0].Font.Name);
            Assert.AreEqual(dstStyle.Name, importedSection.Body.FirstParagraph.Runs[0].Font.StyleName);

            // If we use ImportFormatMode.KeepDifferentStyles, the source style is preserved,
            // and the naming clash resolves by adding a suffix.
            dstDoc.ImportNode(srcDoc.FirstSection, true, ImportFormatMode.KeepDifferentStyles);
            Assert.AreEqual(dstStyle.Font.Name, dstDoc.Styles["My style"].Font.Name);
            Assert.AreEqual(srcStyle.Font.Name, dstDoc.Styles["My style_0"].Font.Name);
            //ExEnd
        }
Esempio n. 3
0
        public void MigrateFrom2XImportSection()
        {
            Aspose.Words.Document srcDoc = new Aspose.Words.Document();
            Aspose.Words.Document dstDoc = new Aspose.Words.Document();

            //ExStart
            //ExId:MigrateFrom2XImportSection
            //ExSummary:This fragment shows how to insert a section from another document in Aspose.Words 3.0 or higher.
            Aspose.Words.Section sourceSection = srcDoc.Sections[0];
            Aspose.Words.Section newSection    = (Aspose.Words.Section)dstDoc.ImportNode(sourceSection, true);
            dstDoc.Sections.Add(newSection);
            //ExEnd
        }
Esempio n. 4
0
        public void SectionsImportSection()
        {
            //ExStart
            //ExId:SectionsImportSection
            //ExSummary:Shows how to copy sections between documents.
            Aspose.Words.Document srcDoc = new Aspose.Words.Document(MyDir + "Document.doc");
            Aspose.Words.Document dstDoc = new Aspose.Words.Document();

            Aspose.Words.Section sourceSection = srcDoc.Sections[0];
            Aspose.Words.Section newSection    = (Aspose.Words.Section)dstDoc.ImportNode(sourceSection, true);
            dstDoc.Sections.Add(newSection);
            //ExEnd
        }
Esempio n. 5
0
        private static void InsertSlicedSectionIntoOutput(Document asposeDoc, int start, int currentIndex, Document outputDoc, Queue <int> mainSections)
        {
            var slicedSection = GetSliceOfSection((Section)asposeDoc.FirstSection.Clone(true), start, currentIndex);

            if (IsNullOrWhiteSpaceOrLineBreak(slicedSection.Body.GetText()))
            {
                return;                                                              // don't add empty sections
            }
            slicedSection.HeadersFooters.LinkToPrevious(false);
            var slicedSectionToInsert = outputDoc.ImportNode(slicedSection, true, ImportFormatMode.KeepSourceFormatting);

            outputDoc.AppendChild(slicedSectionToInsert);
        }
Esempio n. 6
0
        private static void InsertAttachmentDocIntoOutput(byte[] attachment, Document outputDoc, double w, double h)
        {
            using (var mergedStream = new MemoryStream(attachment))
            {
                var attachmentDocument = new Document(mergedStream);

                attachmentDocument.FirstSection.HeadersFooters.LinkToPrevious(false);
                attachmentDocument.FirstSection.PageSetup.PageWidth  = w;
                attachmentDocument.FirstSection.PageSetup.PageHeight = h;
                var sectionFromAttachment = outputDoc.ImportNode(attachmentDocument.FirstSection, true, ImportFormatMode.KeepSourceFormatting);

                outputDoc.AppendChild(sectionFromAttachment);
            }
        }
Esempio n. 7
0
        private Aspose.Pdf.Document doc_to_pdf(save_progress progress, System.Windows.Forms.Form dlg, int lst_select)
        {
            int num = 50;

            if (lst_select == 7)
            {
                num = 100;
            }
            Aspose.Pdf.Document document2 = new Aspose.Pdf.Document();
            try
            {
                document2.Pages.Delete();
                if (progress != null)
                {
                    dlg.Invoke(progress, new object[] { 0 });
                }
                if (this.word_doc == null)
                {
                    return(null);
                }
                for (int i = 0; i < this.word_doc.ChildNodes.Count; i++)
                {
                    MemoryStream          stream   = new MemoryStream();
                    Aspose.Words.Document document = new Aspose.Words.Document();
                    document.ChildNodes.RemoveAt(0);
                    document.AppendChild(document.ImportNode(this.word_doc.ChildNodes[i], true));
                    document.Save(stream, Aspose.Words.SaveFormat.Pdf);
                    document2.Pages.Add(new Aspose.Pdf.Document(stream).Pages);
                    if (progress != null)
                    {
                        dlg.Invoke(progress, new object[] { (i * num) / this.word_doc.ChildNodes.Count });
                    }
                }
                if (lst_select == 7)
                {
                    document2.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + this.get_suffix());
                }
                if (progress != null)
                {
                    dlg.Invoke(progress, new object[] { num });
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(document2);
        }
        public void ImportNode()
        {
            //ExStart
            //ExFor:DocumentBase.ImportNode(Node, Boolean)
            //ExSummary:Shows how to import a node from one document to another.
            Document srcDoc = new Document();
            Document dstDoc = new Document();

            srcDoc.FirstSection.Body.FirstParagraph.AppendChild(
                new Run(srcDoc, "Source document first paragraph text."));
            dstDoc.FirstSection.Body.FirstParagraph.AppendChild(
                new Run(dstDoc, "Destination document first paragraph text."));

            // Every node has a parent document, which is the document that contains the node.
            // Inserting a node into a document that the node does not belong to will throw an exception.
            Assert.AreNotEqual(dstDoc, srcDoc.FirstSection.Document);
            Assert.Throws <ArgumentException>(() => { dstDoc.AppendChild(srcDoc.FirstSection); });

            // Use the ImportNode method to create a copy of a node, which will have the document
            // that called the ImportNode method set as its new owner document.
            Section importedSection = (Section)dstDoc.ImportNode(srcDoc.FirstSection, true);

            Assert.AreEqual(dstDoc, importedSection.Document);

            // We can now insert the node into the document.
            dstDoc.AppendChild(importedSection);

            Assert.AreEqual("Destination document first paragraph text.\r\nSource document first paragraph text.\r\n",
                            dstDoc.ToString(SaveFormat.Text));
            //ExEnd

            Assert.AreNotEqual(importedSection, srcDoc.FirstSection);
            Assert.AreNotEqual(importedSection.Document, srcDoc.FirstSection.Document);
            Assert.AreEqual(importedSection.Body.FirstParagraph.GetText(),
                            srcDoc.FirstSection.Body.FirstParagraph.GetText());
        }
Esempio n. 9
0
        public void SectionsImportSection()
        {
            //ExStart
            //ExId:SectionsImportSection
            //ExSummary:Shows how to copy sections between documents.
            Aspose.Words.Document srcDoc = new Aspose.Words.Document(ExDir + "Document.doc");
            Aspose.Words.Document dstDoc = new Aspose.Words.Document();

            Aspose.Words.Section sourceSection = srcDoc.Sections[0];
            Aspose.Words.Section newSection = (Aspose.Words.Section)dstDoc.ImportNode(sourceSection, true);
            dstDoc.Sections.Add(newSection);
            //ExEnd
        }
Esempio n. 10
0
        public void MigrateFrom2XImportSection()
        {
            Aspose.Words.Document srcDoc = new Aspose.Words.Document();
            Aspose.Words.Document dstDoc = new Aspose.Words.Document();

            //ExStart
            //ExId:MigrateFrom2XImportSection
            //ExSummary:This fragment shows how to insert a section from another document in Aspose.Words 3.0 or higher.
            Aspose.Words.Section sourceSection = srcDoc.Sections[0];
            Aspose.Words.Section newSection = (Aspose.Words.Section)dstDoc.ImportNode(sourceSection, true);
            dstDoc.Sections.Add(newSection);
            //ExEnd
        }