Esempio n. 1
0
        public void BodyEnsureMinimum()
        {
            //ExStart
            //ExFor:Section.Body
            //ExFor:Body.EnsureMinimum
            //ExSummary:Clears main text from all sections from the document leaving the sections themselves.

            // Open a document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Section.BodyEnsureMinimum.doc");

            // This shows what is in the document originally. The document has two sections.
            Console.WriteLine(doc.GetText());

            // Loop through all sections in the document.
            foreach (Aspose.Words.Section section in doc.Sections)
            {
                // Each section has a Body node that contains main story (main text) of the section.
                Body body = section.Body;

                // This clears all nodes from the body.
                body.RemoveAllChildren();

                // Technically speaking, for the main story of a section to be valid, it needs to have
                // at least one empty paragraph. That's what the EnsureMinimum method does.
                body.EnsureMinimum();
            }

            // Check how the content of the document looks now.
            Console.WriteLine(doc.GetText());
            //ExEnd

            Assert.AreEqual("\x000c\x000c", doc.GetText());
        }
Esempio n. 2
0
        public void AddRemove()
        {
            //ExStart
            //ExFor:Document.Sections
            //ExFor:Section.Clone
            //ExFor:SectionCollection
            //ExFor:NodeCollection.RemoveAt(Int32)
            //ExSummary:Shows how to add/remove sections in a document.
            // Open the document.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Section.AddRemove.doc");

            // This shows what is in the document originally. The document has two sections.
            Console.WriteLine(doc.GetText());

            // Delete the first section from the document
            doc.Sections.RemoveAt(0);

            // Duplicate the last section and append the copy to the end of the document.
            int lastSectionIdx = doc.Sections.Count - 1;
            Aspose.Words.Section newSection = doc.Sections[lastSectionIdx].Clone();
            doc.Sections.Add(newSection);

            // Check what the document contains after we changed it.
            Console.WriteLine(doc.GetText());
            //ExEnd

            Assert.AreEqual("Hello2\x000cHello2\x000c", doc.GetText());
        }
Esempio n. 3
0
        public void AddRemove()
        {
            //ExStart
            //ExFor:Document.Sections
            //ExFor:Section.Clone
            //ExFor:SectionCollection
            //ExFor:NodeCollection.RemoveAt(Int32)
            //ExSummary:Shows how to add/remove sections in a document.
            // Open the document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Section.AddRemove.doc");

            // This shows what is in the document originally. The document has two sections.
            Console.WriteLine(doc.GetText());

            // Delete the first section from the document
            doc.Sections.RemoveAt(0);

            // Duplicate the last section and append the copy to the end of the document.
            int lastSectionIdx = doc.Sections.Count - 1;

            Aspose.Words.Section newSection = doc.Sections[lastSectionIdx].Clone();
            doc.Sections.Add(newSection);

            // Check what the document contains after we changed it.
            Console.WriteLine(doc.GetText());
            //ExEnd

            Assert.AreEqual("Hello2\x000cHello2\x000c", doc.GetText());
        }
Esempio n. 4
0
        public void BodyEnsureMinimum()
        {
            //ExStart
            //ExFor:Section.Body
            //ExFor:Body.EnsureMinimum
            //ExSummary:Clears main text from all sections from the document leaving the sections themselves.

            // Open a document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Section.BodyEnsureMinimum.doc");

            // This shows what is in the document originally. The document has two sections.
            Console.WriteLine(doc.GetText());

            // Loop through all sections in the document.
            foreach (Aspose.Words.Section section in doc.Sections)
            {
                // Each section has a Body node that contains main story (main text) of the section.
                Body body = section.Body;

                // This clears all nodes from the body.
                body.RemoveAllChildren();

                // Technically speaking, for the main story of a section to be valid, it needs to have
                // at least one empty paragraph. That's what the EnsureMinimum method does.
                body.EnsureMinimum();
            }

            // Check how the content of the document looks now.
            Console.WriteLine(doc.GetText());
            //ExEnd

            Assert.AreEqual("\x000c\x000c", doc.GetText());
        }
        public void LoadPdf()
        {
            //ExStart
            //ExFor:Document.#ctor(String)
            //ExSummary:Shows how to load a PDF.
            Aspose.Words.Document doc     = new Aspose.Words.Document();
            DocumentBuilder       builder = new DocumentBuilder(doc);

            builder.Write("Hello world!");

            doc.Save(ArtifactsDir + "PDF2Word.LoadPdf.pdf");

            // Below are two ways of loading PDF documents using Aspose products.
            // 1 -  Load as an Aspose.Words document:
            Aspose.Words.Document asposeWordsDoc = new Aspose.Words.Document(ArtifactsDir + "PDF2Word.LoadPdf.pdf");

            Assert.AreEqual("Hello world!", asposeWordsDoc.GetText().Trim());

            // 2 -  Load as an Aspose.Pdf document:
            Aspose.Pdf.Document asposePdfDoc = new Aspose.Pdf.Document(ArtifactsDir + "PDF2Word.LoadPdf.pdf");

            TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber();

            asposePdfDoc.Pages.Accept(textFragmentAbsorber);

            Assert.AreEqual("Hello world!", textFragmentAbsorber.Text.Trim());
            //ExEnd
        }
Esempio n. 6
0
        public void DeleteSelection()
        {
            //ExStart
            //ExFor:Node.Range
            //ExFor:Range.Delete
            //ExSummary:Shows how to delete a section from a Word document.
            // Open Word document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Range.DeleteSection.doc");

            // The document contains two sections. Each section has a paragraph of text.
            Console.WriteLine(doc.GetText());

            // Delete the first section from the document.
            doc.Sections[0].Range.Delete();

            // Check the first section was deleted by looking at the text of the whole document again.
            Console.WriteLine(doc.GetText());
            //ExEnd

            Assert.AreEqual("Hello2\x000c", doc.GetText());
        }
Esempio n. 7
0
        public void DeleteSelection()
        {
            //ExStart
            //ExFor:Node.Range
            //ExFor:Range.Delete
            //ExSummary:Shows how to delete a section from a Word document.
            // Open Word document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Range.DeleteSection.doc");

            // The document contains two sections. Each section has a paragraph of text.
            Console.WriteLine(doc.GetText());

            // Delete the first section from the document.
            doc.Sections[0].Range.Delete();

            // Check the first section was deleted by looking at the text of the whole document again.
            Console.WriteLine(doc.GetText());
            //ExEnd

            Assert.AreEqual("Hello2\x000c", doc.GetText());
        }
        public void IfElseWithoutData()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "ReportingEngine.IfElse.docx");

            BuildReport(doc, Common.GetEmptyManagers(), "m");

            MemoryStream dstStream = new MemoryStream();

            doc.Save(dstStream, SaveFormat.Docx);

            Assert.AreEqual("You have chosen no items.\f", doc.GetText());
        }
Esempio n. 9
0
        //ExStart
        //ExFor:Range.Replace(Regex,IReplacingCallback,Boolean)
        //ExFor:ReplacingArgs.Replacement
        //ExFor:IReplacingCallback
        //ExFor:IReplacingCallback.Replacing
        //ExFor:ReplacingArgs
        //ExFor:DocumentBuilder.InsertHtml(string)
        //ExSummary:Replaces text specified with regular expression with HTML.
        public void ReplaceWithInsertHtml()
        {
            // Open the document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Range.ReplaceWithInsertHtml.doc");

            doc.Range.Replace(new Regex(@"<CustomerName>"), new ReplaceWithHtmlEvaluator(), false);

            // Save the modified document.
            doc.Save(MyDir + "Range.ReplaceWithInsertHtml Out.doc");

            Assert.AreEqual("Hello James Bond,\r\x000c", doc.GetText());  //ExSkip
        }
Esempio n. 10
0
        public override string Extract(Stream stream, TextExtractorContext context)
        {
            Task.Run(() =>
            {
                AsposePreviewProvider.CheckLicense(AsposePreviewProvider.LicenseProvider.Words);

                var document = new AsposeWords.Document(stream);

                IndexingTools.AddTextExtract(context.VersionId, document.GetText());
            });

            return(string.Empty);
        }
        public void NumberFormat()
        {
            Aspose.Words.Document doc = DocumentHelper.CreateSimpleDocument("<<[s.Value1]:alphabetic>> : <<[s.Value2]:roman:lower>>, <<[s.Value3]:ordinal>>, <<[s.Value1]:ordinalText:upper>>" + ", <<[s.Value2]:cardinal>>, <<[s.Value3]:hex>>, <<[s.Value3]:arabicDash>>");

            NumericTestClass sender = new NumericTestBuilder().WithValuesAndDate(1, 2.2, 200, null, DateTime.Parse("10.09.2016 10:00:00")).Build();

            BuildReport(doc, sender, "s");

            MemoryStream dstStream = new MemoryStream();

            doc.Save(dstStream, SaveFormat.Docx);

            Assert.AreEqual("A : ii, 200th, FIRST, Two, C8, - 200 -\f", doc.GetText());
        }
        public void SimpleCase()
        {
            Aspose.Words.Document doc = DocumentHelper.CreateSimpleDocument("<<[s.Name]>> says: <<[s.Message]>>");

            MessageTestClass sender = new MessageTestClass("LINQ Reporting Engine", "Hello World");

            BuildReport(doc, sender, "s", ReportBuildOptions.None);

            MemoryStream dstStream = new MemoryStream();

            doc.Save(dstStream, SaveFormat.Docx);

            Assert.AreEqual("LINQ Reporting Engine says: Hello World\f", doc.GetText());
        }
Esempio n. 13
0
 private void btnLoadText_Click(object sender, EventArgs e) //пока только для txt файлов
 {
     if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         if (openFileDialog1.FilterIndex == 1)
         {
             StreamReader sr = new StreamReader(openFileDialog1.FileName);
             tbOriginalText.Text = sr.ReadToEnd();
             sr.Close();
         }
         if (openFileDialog1.FilterIndex == 2)
         {
             Document document = new Aspose.Words.Document(openFileDialog1.FileName);
             tbOriginalText.Text = document.GetText();
         }
     }
 }
Esempio n. 14
0
        public void ReplaceSimple()
        {
            //ExStart
            //ExFor:Range.Replace(String,String,Boolean,Boolean)
            //ExSummary:Simple find and replace operation.
            // Open the document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Range.ReplaceSimple.doc");

            // Check the document contains what we are about to test.
            Console.WriteLine(doc.FirstSection.Body.Paragraphs[0].GetText());

            // Replace the text in the document.
            doc.Range.Replace("_CustomerName_", "James Bond", false, false);

            // Save the modified document.
            doc.Save(MyDir + "Range.ReplaceSimple Out.doc");
            //ExEnd

            Assert.AreEqual("Hello James Bond,\r\x000c", doc.GetText());
        }
Esempio n. 15
0
        public void CreateFromScratch()
        {
            //ExStart
            //ExFor:Node.GetText
            //ExFor:CompositeNode.RemoveAllChildren
            //ExFor:CompositeNode.AppendChild
            //ExFor:Section
            //ExFor:Section.#ctor
            //ExFor:Section.PageSetup
            //ExFor:PageSetup.SectionStart
            //ExFor:PageSetup.PaperSize
            //ExFor:SectionStart
            //ExFor:PaperSize
            //ExFor:Body
            //ExFor:Body.#ctor
            //ExFor:Paragraph
            //ExFor:Paragraph.#ctor
            //ExFor:Paragraph.ParagraphFormat
            //ExFor:ParagraphFormat
            //ExFor:ParagraphFormat.StyleName
            //ExFor:ParagraphFormat.Alignment
            //ExFor:ParagraphAlignment
            //ExFor:Run
            //ExFor:Run.#ctor(DocumentBase)
            //ExFor:Run.Text
            //ExFor:Inline.Font
            //ExSummary:Creates a simple document from scratch using the Aspose.Words object model.

            // Create an "empty" document. Note that like in Microsoft Word,
            // the empty document has one section, body and one paragraph in it.
            Aspose.Words.Document doc = new Aspose.Words.Document();

            // This truly makes the document empty. No sections (not possible in Microsoft Word).
            doc.RemoveAllChildren();

            // Create a new section node.
            // Note that the section has not yet been added to the document,
            // but we have to specify the parent document.
            Aspose.Words.Section section = new Aspose.Words.Section(doc);

            // Append the section to the document.
            doc.AppendChild(section);

            // Lets set some properties for the section.
            section.PageSetup.SectionStart = SectionStart.NewPage;
            section.PageSetup.PaperSize    = PaperSize.Letter;


            // The section that we created is empty, lets populate it. The section needs at least the Body node.
            Body body = new Body(doc);

            section.AppendChild(body);


            // The body needs to have at least one paragraph.
            // Note that the paragraph has not yet been added to the document,
            // but we have to specify the parent document.
            // The parent document is needed so the paragraph can correctly work
            // with styles and other document-wide information.
            Paragraph para = new Paragraph(doc);

            body.AppendChild(para);

            // We can set some formatting for the paragraph
            para.ParagraphFormat.StyleName = "Heading 1";
            para.ParagraphFormat.Alignment = ParagraphAlignment.Center;


            // So far we have one empty paragraph in the document.
            // The document is valid and can be saved, but lets add some text before saving.
            // Create a new run of text and add it to our paragraph.
            Run run = new Run(doc);

            run.Text       = "Hello World!";
            run.Font.Color = System.Drawing.Color.Red;
            para.AppendChild(run);


            // As a matter of interest, you can retrieve text of the whole document and
            // see that \x000c is automatically appended. \x000c is the end of section character.
            Console.WriteLine("Hello World!\x000c", doc.GetText());

            // Save the document.
            doc.Save(MyDir + "Section.CreateFromScratch Out.doc");
            //ExEnd

            Assert.AreEqual("Hello World!\x000c", doc.GetText());
        }
Esempio n. 16
0
        //ExStart
        //ExFor:Range.Replace(Regex,IReplacingCallback,Boolean)
        //ExFor:ReplacingArgs.Replacement
        //ExFor:IReplacingCallback
        //ExFor:IReplacingCallback.Replacing
        //ExFor:ReplacingArgs
        //ExFor:DocumentBuilder.InsertHtml(string)
        //ExSummary:Replaces text specified with regular expression with HTML.
        public void ReplaceWithInsertHtml()
        {
            // Open the document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Range.ReplaceWithInsertHtml.doc");

            doc.Range.Replace(new Regex(@"<CustomerName>"), new ReplaceWithHtmlEvaluator(), false);

            // Save the modified document.
            doc.Save(MyDir + "Range.ReplaceWithInsertHtml Out.doc");

            Assert.AreEqual("Hello James Bond,\r\x000c", doc.GetText());  //ExSkip
        }
        public void StringFormat()
        {
            Aspose.Words.Document doc = DocumentHelper.CreateSimpleDocument("<<[s.Name]:lower>> says: <<[s.Message]:upper>>, <<[s.Message]:caps>>, <<[s.Message]:firstCap>>");

            MessageTestClass sender = new MessageTestClass("LINQ Reporting Engine", "hello world");

            BuildReport(doc, sender, "s");

            MemoryStream dstStream = new MemoryStream();

            doc.Save(dstStream, SaveFormat.Docx);

            Assert.AreEqual("linq reporting engine says: HELLO WORLD, Hello World, Hello world\f", doc.GetText());
        }
        public void IndexOf()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "ReportingEngine.TestIndexOf.docx");

            BuildReport(doc, Common.GetManagers(), "Managers");

            MemoryStream dstStream = new MemoryStream();

            doc.Save(dstStream, SaveFormat.Docx);

            Assert.AreEqual("The names are: John Smith, Tony Anderson, July James\f", doc.GetText());
        }
Esempio n. 19
0
        public void OpenFromStream()
        {
            //ExStart
            //ExFor:Document.#ctor(Stream)
            //ExId:OpenFromStream
            //ExSummary:Opens a document from a stream.
            // Open the stream. Read only access is enough for Aspose.Words to load a document.
            Stream stream = File.OpenRead(MyDir + "Document.doc");

            // Load the entire document into memory.
            Aspose.Words.Document doc = new Aspose.Words.Document(stream);

            // You can close the stream now, it is no longer needed because the document is in memory.
            stream.Close();

            // ... do something with the document
            //ExEnd

            Assert.AreEqual("Hello World!\x000c", doc.GetText());
        }
Esempio n. 20
0
        public string getWordContent()
        {
            string content = oDoc.GetText();

            return(content);
        }
Esempio n. 21
0
        public void DocumentGetText_ToString()
        {
            //ExStart
            //ExFor:CompositeNode.GetText
            //ExFor:Node.ToString(SaveFormat)
            //ExId:NodeTxtExportDifferences
            //ExSummary:Shows the difference between calling the GetText and ToString methods on a node.
            Aspose.Words.Document doc = new Aspose.Words.Document();

            // Enter a dummy field into the document.
            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.InsertField("MERGEFIELD Field");

            // GetText will retrieve all field codes and special characters
            Console.WriteLine("GetText() Result: " + doc.GetText());

            // ToString will export the node to the specified format. When converted to text it will not retrieve fields code
            // or special characters, but will still contain some natural formatting characters such as paragraph markers etc.
            // This is the same as "viewing" the document as if it was opened in a text editor.
            Console.WriteLine("ToString() Result: " + doc.ToString(SaveFormat.Text));
            //ExEnd
        }
Esempio n. 22
0
        public void ReplaceSimple()
        {
            //ExStart
            //ExFor:Range.Replace(String,String,Boolean,Boolean)
            //ExSummary:Simple find and replace operation.
            // Open the document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Range.ReplaceSimple.doc");

            // Check the document contains what we are about to test.
            Console.WriteLine(doc.FirstSection.Body.Paragraphs[0].GetText());

            // Replace the text in the document.
            doc.Range.Replace("_CustomerName_", "James Bond", false, false);

            // Save the modified document.
            doc.Save(MyDir + "Range.ReplaceSimple Out.doc");
            //ExEnd

            Assert.AreEqual("Hello James Bond,\r\x000c", doc.GetText());
        }
Esempio n. 23
0
        public void DocumentByteArray()
        {
            //ExStart
            //ExId:DocumentToFromByteArray
            //ExSummary:Shows how to convert a document object to an array of bytes and back into a document object again.
            // Load the document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Document.doc");

            // Create a new memory stream.
            MemoryStream outStream = new MemoryStream();
            // Save the document to stream.
            doc.Save(outStream, SaveFormat.Docx);

            // Convert the document to byte form.
            byte[] docBytes = outStream.ToArray();

            // The bytes are now ready to be stored/transmitted.

            // Now reverse the steps to load the bytes back into a document object.
            MemoryStream inStream = new MemoryStream(docBytes);

            // Load the stream into a new document object.
            Aspose.Words.Document loadDoc = new Aspose.Words.Document(inStream);
            //ExEnd

            Assert.AreEqual(doc.GetText(), loadDoc.GetText());
        }
Esempio n. 24
-1
        public void CreateFromScratch()
        {
            //ExStart
            //ExFor:Node.GetText
            //ExFor:CompositeNode.RemoveAllChildren
            //ExFor:CompositeNode.AppendChild
            //ExFor:Section
            //ExFor:Section.#ctor
            //ExFor:Section.PageSetup
            //ExFor:PageSetup.SectionStart
            //ExFor:PageSetup.PaperSize
            //ExFor:SectionStart
            //ExFor:PaperSize
            //ExFor:Body
            //ExFor:Body.#ctor
            //ExFor:Paragraph
            //ExFor:Paragraph.#ctor
            //ExFor:Paragraph.ParagraphFormat
            //ExFor:ParagraphFormat
            //ExFor:ParagraphFormat.StyleName
            //ExFor:ParagraphFormat.Alignment
            //ExFor:ParagraphAlignment
            //ExFor:Run
            //ExFor:Run.#ctor(DocumentBase)
            //ExFor:Run.Text
            //ExFor:Inline.Font
            //ExSummary:Creates a simple document from scratch using the Aspose.Words object model.

            // Create an "empty" document. Note that like in Microsoft Word,
            // the empty document has one section, body and one paragraph in it.
            Aspose.Words.Document doc = new Aspose.Words.Document();

            // This truly makes the document empty. No sections (not possible in Microsoft Word).
            doc.RemoveAllChildren();

            // Create a new section node.
            // Note that the section has not yet been added to the document,
            // but we have to specify the parent document.
            Aspose.Words.Section section = new Aspose.Words.Section(doc);

            // Append the section to the document.
            doc.AppendChild(section);

            // Lets set some properties for the section.
            section.PageSetup.SectionStart = SectionStart.NewPage;
            section.PageSetup.PaperSize = PaperSize.Letter;

            // The section that we created is empty, lets populate it. The section needs at least the Body node.
            Body body = new Body(doc);
            section.AppendChild(body);

            // The body needs to have at least one paragraph.
            // Note that the paragraph has not yet been added to the document,
            // but we have to specify the parent document.
            // The parent document is needed so the paragraph can correctly work
            // with styles and other document-wide information.
            Paragraph para = new Paragraph(doc);
            body.AppendChild(para);

            // We can set some formatting for the paragraph
            para.ParagraphFormat.StyleName = "Heading 1";
            para.ParagraphFormat.Alignment = ParagraphAlignment.Center;

            // So far we have one empty paragraph in the document.
            // The document is valid and can be saved, but lets add some text before saving.
            // Create a new run of text and add it to our paragraph.
            Run run = new Run(doc);
            run.Text = "Hello World!";
            run.Font.Color = System.Drawing.Color.Red;
            para.AppendChild(run);

            // As a matter of interest, you can retrieve text of the whole document and
            // see that \x000c is automatically appended. \x000c is the end of section character.
            Console.WriteLine("Hello World!\x000c", doc.GetText());

            // Save the document.
            doc.Save(ExDir + "Section.CreateFromScratch Out.doc");
            //ExEnd

            Assert.AreEqual("Hello World!\x000c", doc.GetText());
        }