Module: Asposewordsjavaforruby::FindAndReplace
- Defined in:
- lib/asposewordsjavaforruby/findandreplace.rb
Instance Method Summary collapse
Instance Method Details
#initialize ⇒ Object
3 4 5 6 |
# File 'lib/asposewordsjavaforruby/findandreplace.rb', line 3 def initialize() # Find and replace text in document. replace_text() end |
#replace_text ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/asposewordsjavaforruby/findandreplace.rb', line 8 def replace_text() # The path to the documents directory. data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/quickstart/' # Open the document. doc = Rjb::import('com.aspose.words.Document').new(data_dir + "ReplaceSimple.doc") # Check the text of the document. puts "Original document text: " + doc.getRange().getText() # Replace the text in the document. doc.getRange().replace("_CustomerName_", "James Bond", false, false) # Check the replacement was made. puts "Document text after replace: " + doc.getRange().getText() # Save the modified document. doc.save(data_dir + "ReplaceSimple Out.doc") end |