asposewordsjavaforruby 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/Gempackage +2 -2
  3. data/LICENSE +20 -20
  4. data/README.md +28 -2
  5. data/Rakefile +2 -2
  6. data/asposewordsjavaforruby.gemspec +27 -27
  7. data/config/aspose.yml +5 -5
  8. data/data/LoadTxt.txt +14 -14
  9. data/lib/asposewordsjavaforruby.rb +71 -71
  10. data/lib/asposewordsjavaforruby/addwatermark.rb +84 -84
  11. data/lib/asposewordsjavaforruby/appenddoc.rb +24 -24
  12. data/lib/asposewordsjavaforruby/appenddocument.rb +229 -229
  13. data/lib/asposewordsjavaforruby/applylicense.rb +16 -16
  14. data/lib/asposewordsjavaforruby/asposewordsjava.rb +23 -23
  15. data/lib/asposewordsjavaforruby/autofittables.rb +123 -123
  16. data/lib/asposewordsjavaforruby/bookmarks.rb +132 -132
  17. data/lib/asposewordsjavaforruby/checkformat.rb +70 -70
  18. data/lib/asposewordsjavaforruby/compressimages.rb +53 -53
  19. data/lib/asposewordsjavaforruby/doc2pdf.rb +15 -15
  20. data/lib/asposewordsjavaforruby/doctohtml.rb +26 -26
  21. data/lib/asposewordsjavaforruby/extractcontent.rb +395 -395
  22. data/lib/asposewordsjavaforruby/findandreplace.rb +29 -29
  23. data/lib/asposewordsjavaforruby/helloworld.rb +26 -26
  24. data/lib/asposewordsjavaforruby/imagetopdf.rb +71 -71
  25. data/lib/asposewordsjavaforruby/insertnestedfields.rb +39 -39
  26. data/lib/asposewordsjavaforruby/loadandsavetodisk.rb +20 -20
  27. data/lib/asposewordsjavaforruby/loadandsavetostream.rb +32 -32
  28. data/lib/asposewordsjavaforruby/loadtxt.rb +14 -14
  29. data/lib/asposewordsjavaforruby/mergefield.rb +45 -45
  30. data/lib/asposewordsjavaforruby/nodes.rb +29 -29
  31. data/lib/asposewordsjavaforruby/processcomments.rb +72 -72
  32. data/lib/asposewordsjavaforruby/removebreaks.rb +65 -65
  33. data/lib/asposewordsjavaforruby/removefield.rb +23 -23
  34. data/lib/asposewordsjavaforruby/saveasmultipagetiff.rb +26 -26
  35. data/lib/asposewordsjavaforruby/simplemailmerge.rb +23 -23
  36. data/lib/asposewordsjavaforruby/styles.rb +77 -77
  37. data/lib/asposewordsjavaforruby/updatefields.rb +62 -62
  38. data/lib/asposewordsjavaforruby/version.rb +3 -3
  39. metadata +18 -28
@@ -1,16 +1,16 @@
1
- module Asposewordsjavaforruby
2
- module ApplyLicense
3
- def initialize()
4
- apply_license()
5
- end
6
-
7
- def apply_license()
8
- # This line attempts to set a license from several locations relative to the executable and Aspose.Words.dll.
9
- # You can also use the additional overload to load a license from a stream, this is useful for instance when the
10
- # license is stored as an embedded resource
11
- license = Rjb::import('com.aspose.words.License').new()
12
- license.setLicense('Aspose.Words.lic')
13
- end
14
-
15
- end
16
- end
1
+ module Asposewordsjavaforruby
2
+ module ApplyLicense
3
+ def initialize()
4
+ apply_license()
5
+ end
6
+
7
+ def apply_license()
8
+ # This line attempts to set a license from several locations relative to the executable and Aspose.Words.dll.
9
+ # You can also use the additional overload to load a license from a stream, this is useful for instance when the
10
+ # license is stored as an embedded resource
11
+ license = Rjb::import('com.aspose.words.License').new()
12
+ license.setLicense('Aspose.Words.lic')
13
+ end
14
+
15
+ end
16
+ end
@@ -1,24 +1,24 @@
1
- require_relative 'helloworld'
2
- require_relative 'appenddoc'
3
- require_relative 'applylicense'
4
- require_relative 'findandreplace'
5
- require_relative 'loadandsavetodisk'
6
- require_relative 'loadandsavetostream'
7
- require_relative 'simplemailmerge'
8
- require_relative 'updatefields'
9
- require_relative 'nodes'
10
- require_relative 'processcomments'
11
- require_relative 'addwatermark'
12
- require_relative 'autofittables'
13
- require_relative 'bookmarks'
14
- require_relative 'compressimages'
15
- require_relative 'insertnestedfields'
16
- require_relative 'appenddocument'
17
- require_relative 'styles'
18
- require_relative 'removebreaks'
19
- require_relative 'extractcontent'
20
- require_relative 'checkformat'
21
- require_relative 'loadtxt'
22
- require_relative 'saveasmultipagetiff'
23
- require_relative 'mergefield'
1
+ require_relative 'helloworld'
2
+ require_relative 'appenddoc'
3
+ require_relative 'applylicense'
4
+ require_relative 'findandreplace'
5
+ require_relative 'loadandsavetodisk'
6
+ require_relative 'loadandsavetostream'
7
+ require_relative 'simplemailmerge'
8
+ require_relative 'updatefields'
9
+ require_relative 'nodes'
10
+ require_relative 'processcomments'
11
+ require_relative 'addwatermark'
12
+ require_relative 'autofittables'
13
+ require_relative 'bookmarks'
14
+ require_relative 'compressimages'
15
+ require_relative 'insertnestedfields'
16
+ require_relative 'appenddocument'
17
+ require_relative 'styles'
18
+ require_relative 'removebreaks'
19
+ require_relative 'extractcontent'
20
+ require_relative 'checkformat'
21
+ require_relative 'loadtxt'
22
+ require_relative 'saveasmultipagetiff'
23
+ require_relative 'mergefield'
24
24
  require_relative 'doctohtml'
@@ -1,123 +1,123 @@
1
- module Asposewordsjavaforruby
2
- module AutoFitTables
3
- def initialize()
4
- # The path to the documents directory.
5
- @data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
6
-
7
- # Demonstrate autofitting a table to the window.
8
- autofit_table_to_window()
9
-
10
- # Demonstrate autofitting a table to its contents.
11
- autofit_table_to_contents()
12
-
13
- # Demonstrate autofitting a table to fixed column widths.
14
- autofit_table_to_fixed_column_widths()
15
- end
16
-
17
- =begin
18
- ExStart
19
- ExFor:Table.AutoFit
20
- ExFor:AutoFitBehavior
21
- ExId:FitTableToPageWidth
22
- ExSummary:Autofits a table to fit the page width.
23
- =end
24
- def autofit_table_to_window()
25
- #data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
26
- # Open the document
27
- doc = Rjb::import('com.aspose.words.Document').new(@data_dir + "TestFile.doc")
28
-
29
- node_type = Rjb::import('com.aspose.words.NodeType')
30
- table = doc.getChild(node_type.TABLE, 0, true)
31
-
32
- # Autofit the first table to the page width.
33
- autofit_behavior = Rjb::import("com.aspose.words.AutoFitBehavior")
34
- table.autoFit(autofit_behavior.AUTO_FIT_TO_WINDOW)
35
-
36
- # Save the document to disk.
37
- doc.save(@data_dir + "TestFile.AutoFitToWindow Out.doc")
38
- # ExEnd
39
- preferred_width_type = Rjb::import("com.aspose.words.PreferredWidthType")
40
-
41
- if (doc.getFirstSection().getBody().getTables().get(0).getPreferredWidth().getType() == preferred_width_type.PERCENT) then
42
- puts "PreferredWidth type is not percent."
43
- end
44
-
45
- if (doc.getFirstSection().getBody().getTables().get(0).getPreferredWidth().getValue() == 100) then
46
- puts "PreferredWidth value is different than 100."
47
- end
48
- end
49
-
50
- =begin
51
- ExStart
52
- ExFor:Table.AutoFit
53
- ExFor:AutoFitBehavior
54
- ExId:FitTableToContents
55
- ExSummary:Autofits a table in the document to its contents.
56
- =end
57
- def autofit_table_to_contents()
58
- # Open the document
59
- doc = Rjb::import('com.aspose.words.Document').new(@data_dir + "TestFile.doc")
60
-
61
- node_type = Rjb::import('com.aspose.words.NodeType')
62
- table = doc.getChild(node_type.TABLE, 0, true)
63
-
64
- # Autofit the table to the cell contents
65
- autofit_behavior = Rjb::import("com.aspose.words.AutoFitBehavior")
66
- table.autoFit(autofit_behavior.AUTO_FIT_TO_CONTENTS)
67
-
68
- # Save the document to disk.
69
- doc.save(@data_dir + "TestFile.AutoFitToContents Out.doc")
70
- # ExEnd
71
- preferred_width_type = Rjb::import("com.aspose.words.PreferredWidthType")
72
-
73
- if (doc.getFirstSection().getBody().getTables().get(0).getPreferredWidth().getType() == preferred_width_type.AUTO) then
74
- puts "PreferredWidth type is not auto."
75
- end
76
-
77
- if (doc.getFirstSection().getBody().getTables().get(0).getFirstRow().getFirstCell().getCellFormat().getPreferredWidth().getType() == preferred_width_type.AUTO) then
78
- puts "PrefferedWidth on cell is not auto."
79
- end
80
-
81
- if(doc.getFirstSection().getBody().getTables().get(0).getFirstRow().getFirstCell().getCellFormat().getPreferredWidth().getValue() == 0) then
82
- puts "PreferredWidth value is not 0."
83
- end
84
- end
85
-
86
- =begin
87
- ExStart
88
- ExFor:Table.AutoFit
89
- ExFor:AutoFitBehavior
90
- ExId:DisableAutoFitAndUseFixedWidths
91
- ExSummary:Disables autofitting and enables fixed widths for the specified table.
92
- =end
93
- def autofit_table_to_fixed_column_widths()
94
- # Open the document
95
- doc = Rjb::import('com.aspose.words.Document').new(@data_dir + "TestFile.doc")
96
-
97
- node_type = Rjb::import('com.aspose.words.NodeType')
98
- table = doc.getChild(node_type.TABLE, 0, true)
99
-
100
- # Disable autofitting on this table.
101
- autofit_behavior = Rjb::import("com.aspose.words.AutoFitBehavior")
102
- table.autoFit(autofit_behavior.AUTO_FIT_TO_CONTENTS)
103
-
104
- # Save the document to disk.
105
- doc.save(@data_dir + "TestFile.FixedWidth Out.doc")
106
- # ExEnd
107
- preferred_width_type = Rjb::import("com.aspose.words.PreferredWidthType")
108
-
109
- if (doc.getFirstSection().getBody().getTables().get(0).getPreferredWidth().getType() == preferred_width_type.AUTO) then
110
- puts "PreferredWidth type is not auto."
111
- end
112
-
113
- if (doc.getFirstSection().getBody().getTables().get(0).getPreferredWidth().getValue() == 0) then
114
- puts "PreferredWidth value is not 0."
115
- end
116
-
117
- if (doc.getFirstSection().getBody().getTables().get(0).getFirstRow().getFirstCell().getCellFormat().getWidth() == 0) then
118
- puts "Cell width is not correct."
119
- end
120
- end
121
-
122
- end
123
- end
1
+ module Asposewordsjavaforruby
2
+ module AutoFitTables
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ @data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
6
+
7
+ # Demonstrate autofitting a table to the window.
8
+ autofit_table_to_window()
9
+
10
+ # Demonstrate autofitting a table to its contents.
11
+ autofit_table_to_contents()
12
+
13
+ # Demonstrate autofitting a table to fixed column widths.
14
+ autofit_table_to_fixed_column_widths()
15
+ end
16
+
17
+ =begin
18
+ ExStart
19
+ ExFor:Table.AutoFit
20
+ ExFor:AutoFitBehavior
21
+ ExId:FitTableToPageWidth
22
+ ExSummary:Autofits a table to fit the page width.
23
+ =end
24
+ def autofit_table_to_window()
25
+ #data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
26
+ # Open the document
27
+ doc = Rjb::import('com.aspose.words.Document').new(@data_dir + "TestFile.doc")
28
+
29
+ node_type = Rjb::import('com.aspose.words.NodeType')
30
+ table = doc.getChild(node_type.TABLE, 0, true)
31
+
32
+ # Autofit the first table to the page width.
33
+ autofit_behavior = Rjb::import("com.aspose.words.AutoFitBehavior")
34
+ table.autoFit(autofit_behavior.AUTO_FIT_TO_WINDOW)
35
+
36
+ # Save the document to disk.
37
+ doc.save(@data_dir + "TestFile.AutoFitToWindow Out.doc")
38
+ # ExEnd
39
+ preferred_width_type = Rjb::import("com.aspose.words.PreferredWidthType")
40
+
41
+ if (doc.getFirstSection().getBody().getTables().get(0).getPreferredWidth().getType() == preferred_width_type.PERCENT) then
42
+ puts "PreferredWidth type is not percent."
43
+ end
44
+
45
+ if (doc.getFirstSection().getBody().getTables().get(0).getPreferredWidth().getValue() == 100) then
46
+ puts "PreferredWidth value is different than 100."
47
+ end
48
+ end
49
+
50
+ =begin
51
+ ExStart
52
+ ExFor:Table.AutoFit
53
+ ExFor:AutoFitBehavior
54
+ ExId:FitTableToContents
55
+ ExSummary:Autofits a table in the document to its contents.
56
+ =end
57
+ def autofit_table_to_contents()
58
+ # Open the document
59
+ doc = Rjb::import('com.aspose.words.Document').new(@data_dir + "TestFile.doc")
60
+
61
+ node_type = Rjb::import('com.aspose.words.NodeType')
62
+ table = doc.getChild(node_type.TABLE, 0, true)
63
+
64
+ # Autofit the table to the cell contents
65
+ autofit_behavior = Rjb::import("com.aspose.words.AutoFitBehavior")
66
+ table.autoFit(autofit_behavior.AUTO_FIT_TO_CONTENTS)
67
+
68
+ # Save the document to disk.
69
+ doc.save(@data_dir + "TestFile.AutoFitToContents Out.doc")
70
+ # ExEnd
71
+ preferred_width_type = Rjb::import("com.aspose.words.PreferredWidthType")
72
+
73
+ if (doc.getFirstSection().getBody().getTables().get(0).getPreferredWidth().getType() == preferred_width_type.AUTO) then
74
+ puts "PreferredWidth type is not auto."
75
+ end
76
+
77
+ if (doc.getFirstSection().getBody().getTables().get(0).getFirstRow().getFirstCell().getCellFormat().getPreferredWidth().getType() == preferred_width_type.AUTO) then
78
+ puts "PrefferedWidth on cell is not auto."
79
+ end
80
+
81
+ if(doc.getFirstSection().getBody().getTables().get(0).getFirstRow().getFirstCell().getCellFormat().getPreferredWidth().getValue() == 0) then
82
+ puts "PreferredWidth value is not 0."
83
+ end
84
+ end
85
+
86
+ =begin
87
+ ExStart
88
+ ExFor:Table.AutoFit
89
+ ExFor:AutoFitBehavior
90
+ ExId:DisableAutoFitAndUseFixedWidths
91
+ ExSummary:Disables autofitting and enables fixed widths for the specified table.
92
+ =end
93
+ def autofit_table_to_fixed_column_widths()
94
+ # Open the document
95
+ doc = Rjb::import('com.aspose.words.Document').new(@data_dir + "TestFile.doc")
96
+
97
+ node_type = Rjb::import('com.aspose.words.NodeType')
98
+ table = doc.getChild(node_type.TABLE, 0, true)
99
+
100
+ # Disable autofitting on this table.
101
+ autofit_behavior = Rjb::import("com.aspose.words.AutoFitBehavior")
102
+ table.autoFit(autofit_behavior.AUTO_FIT_TO_CONTENTS)
103
+
104
+ # Save the document to disk.
105
+ doc.save(@data_dir + "TestFile.FixedWidth Out.doc")
106
+ # ExEnd
107
+ preferred_width_type = Rjb::import("com.aspose.words.PreferredWidthType")
108
+
109
+ if (doc.getFirstSection().getBody().getTables().get(0).getPreferredWidth().getType() == preferred_width_type.AUTO) then
110
+ puts "PreferredWidth type is not auto."
111
+ end
112
+
113
+ if (doc.getFirstSection().getBody().getTables().get(0).getPreferredWidth().getValue() == 0) then
114
+ puts "PreferredWidth value is not 0."
115
+ end
116
+
117
+ if (doc.getFirstSection().getBody().getTables().get(0).getFirstRow().getFirstCell().getCellFormat().getWidth() == 0) then
118
+ puts "Cell width is not correct."
119
+ end
120
+ end
121
+
122
+ end
123
+ end
@@ -1,132 +1,132 @@
1
- module Asposewordsjavaforruby
2
- module Bookmarks
3
- def initialize()
4
- # The path to the documents directory.
5
- @data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/bookmarks/'
6
-
7
- # Open the document.
8
- doc = Rjb::import('com.aspose.words.Document').new(@data_dir + 'TestDefect1352.doc')
9
-
10
- append_bookmark_text()
11
-
12
- # This perform the custom task of putting the row bookmark ends into the same row with the bookmark starts.
13
- untangle_row_bookmark(doc)
14
-
15
- # Now we can easily delete rows by a bookmark without damaging any other row's bookmarks.
16
- delete_row_by_bookmark(doc, 'ROW2')
17
- end
18
-
19
- def append_bookmark_text()
20
- data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/bookmarks/'
21
-
22
- # Load the source document.
23
- src_doc = Rjb::import('com.aspose.words.Document').new(data_dir + "Template.doc")
24
-
25
- # This is the bookmark whose content we want to copy.
26
- src_bookmark = src_doc.getRange().getBookmarks().get("ntf010145060")
27
-
28
- # We will be adding to this document.
29
- dst_doc = Rjb::import('com.aspose.words.Document').new()
30
-
31
- # Let's say we will be appending to the end of the body of the last section.
32
- #node_type = Rjb::import('com.aspose.words.NodeType')
33
- dst_node = dst_doc.getLastSection().getBody()
34
-
35
- # It is a good idea to use this import context object because multiple nodes are being imported.
36
- # If you import multiple times without a single context, it will result in many styles created.
37
- import_format_mode = Rjb::import('com.aspose.words.ImportFormatMode')
38
- importer = Rjb::import("com.aspose.words.NodeImporter").new(src_doc, dst_doc, import_format_mode.KEEP_SOURCE_FORMATTING)
39
-
40
- # This is the paragraph that contains the beginning of the bookmark.
41
- start_para = src_bookmark.getBookmarkStart().getParentNode()
42
-
43
- # This is the paragraph that contains the end of the bookmark.
44
- end_para = src_bookmark.getBookmarkEnd().getParentNode()
45
-
46
- if (start_para == "" || end_para == "") then
47
- raise "Parent of the bookmark start or end is not a paragraph, cannot handle this scenario yet."
48
- end
49
-
50
- util = Rjb::import("java.io.InputStream")
51
- # Limit ourselves to a reasonably simple scenario.
52
- spara = (start_para.getParentNode()).to_string
53
- epara = (end_para.getParentNode()).to_string
54
- #p spara.strip
55
- #abort('spara')
56
-
57
-
58
- if spara.strip != epara.strip then
59
- #if (start_para.getParentNode() != end_para.getParentNode()) then
60
- raise "Start and end paragraphs have different parents, cannot handle this scenario yet."
61
- end
62
-
63
- # We want to copy all paragraphs from the start paragraph up to (and including) the end paragraph,
64
- # therefore the node at which we stop is one after the end paragraph.
65
- endNode = end_para.getNextSibling()
66
-
67
- # This is the loop to go through all paragraph-level nodes in the bookmark.
68
- curNode = start_para
69
- cNode = curNode
70
- eNode = endNode
71
-
72
- while (cNode != eNode) do
73
- # This creates a copy of the current node and imports it (makes it valid) in the context
74
- # of the destination document. Importing means adjusting styles and list identifiers correctly.
75
- newNode = importer.importNode(curNode, true)
76
- curNode = curNode.getNextSibling()
77
- cNode = curNode
78
- dst_node.appendChild(newNode)
79
- end
80
-
81
- # Save the finished document.
82
- dst_doc.save(data_dir + "Template Out.doc");
83
- end
84
-
85
- def untangle_row_bookmark(doc)
86
- bookmarks = doc.getRange().getBookmarks()
87
- bookmarks_count = bookmarks.getCount()
88
-
89
- i = 0
90
- while i < bookmarks_count do
91
- bookmark = bookmarks.get(i)
92
- row1 = bookmark.getBookmarkStart().getAncestor(Rjb::import("com.aspose.words.Row"))
93
- row2 = bookmark.getBookmarkEnd().getAncestor(Rjb::import("com.aspose.words.Row"))
94
-
95
- # If both rows are found okay and the bookmark start and end are contained
96
- # in adjacent rows, then just move the bookmark end node to the end
97
- # of the last paragraph in the last cell of the top row.
98
- if ((row1 != "") && (row2 != "") && (row1.getNextSibling() == row2)) then
99
- row1.getLastCell().getLastParagraph().appendChild(bookmark.getBookmarkEnd())
100
- end
101
- $i +=1
102
- end
103
-
104
- # Save the document.
105
- doc.save(@data_dir + "TestDefect1352 Out.doc")
106
- end
107
-
108
- def delete_row_by_bookmark(doc, bookmark_name)
109
- raise 'bookmark_name not specified.' if bookmark_name.empty?
110
-
111
- bookmark = doc.getRange().getBookmarks().get(bookmark_name)
112
-
113
- if bookmark.nil? then
114
- return
115
- end
116
-
117
- # Get the parent row of the bookmark. Exit if the bookmark is not in a row.
118
- row = bookmark.getBookmarkStart().getAncestor(Rjb::import('com.aspose.words.Row'))
119
-
120
- if row.nil? then
121
- return
122
- end
123
-
124
- # Remove the row.
125
- row.remove()
126
-
127
- # Save the document.
128
- doc.save(@data_dir + "TestDefect1352 Out.doc")
129
- end
130
-
131
- end
132
- end
1
+ module Asposewordsjavaforruby
2
+ module Bookmarks
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ @data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/bookmarks/'
6
+
7
+ # Open the document.
8
+ doc = Rjb::import('com.aspose.words.Document').new(@data_dir + 'TestDefect1352.doc')
9
+
10
+ append_bookmark_text()
11
+
12
+ # This perform the custom task of putting the row bookmark ends into the same row with the bookmark starts.
13
+ untangle_row_bookmark(doc)
14
+
15
+ # Now we can easily delete rows by a bookmark without damaging any other row's bookmarks.
16
+ delete_row_by_bookmark(doc, 'ROW2')
17
+ end
18
+
19
+ def append_bookmark_text()
20
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/bookmarks/'
21
+
22
+ # Load the source document.
23
+ src_doc = Rjb::import('com.aspose.words.Document').new(data_dir + "Template.doc")
24
+
25
+ # This is the bookmark whose content we want to copy.
26
+ src_bookmark = src_doc.getRange().getBookmarks().get("ntf010145060")
27
+
28
+ # We will be adding to this document.
29
+ dst_doc = Rjb::import('com.aspose.words.Document').new()
30
+
31
+ # Let's say we will be appending to the end of the body of the last section.
32
+ #node_type = Rjb::import('com.aspose.words.NodeType')
33
+ dst_node = dst_doc.getLastSection().getBody()
34
+
35
+ # It is a good idea to use this import context object because multiple nodes are being imported.
36
+ # If you import multiple times without a single context, it will result in many styles created.
37
+ import_format_mode = Rjb::import('com.aspose.words.ImportFormatMode')
38
+ importer = Rjb::import("com.aspose.words.NodeImporter").new(src_doc, dst_doc, import_format_mode.KEEP_SOURCE_FORMATTING)
39
+
40
+ # This is the paragraph that contains the beginning of the bookmark.
41
+ start_para = src_bookmark.getBookmarkStart().getParentNode()
42
+
43
+ # This is the paragraph that contains the end of the bookmark.
44
+ end_para = src_bookmark.getBookmarkEnd().getParentNode()
45
+
46
+ if (start_para == "" || end_para == "") then
47
+ raise "Parent of the bookmark start or end is not a paragraph, cannot handle this scenario yet."
48
+ end
49
+
50
+ util = Rjb::import("java.io.InputStream")
51
+ # Limit ourselves to a reasonably simple scenario.
52
+ spara = (start_para.getParentNode()).to_string
53
+ epara = (end_para.getParentNode()).to_string
54
+ #p spara.strip
55
+ #abort('spara')
56
+
57
+
58
+ if spara.strip != epara.strip then
59
+ #if (start_para.getParentNode() != end_para.getParentNode()) then
60
+ raise "Start and end paragraphs have different parents, cannot handle this scenario yet."
61
+ end
62
+
63
+ # We want to copy all paragraphs from the start paragraph up to (and including) the end paragraph,
64
+ # therefore the node at which we stop is one after the end paragraph.
65
+ endNode = end_para.getNextSibling()
66
+
67
+ # This is the loop to go through all paragraph-level nodes in the bookmark.
68
+ curNode = start_para
69
+ cNode = curNode
70
+ eNode = endNode
71
+
72
+ while (cNode != eNode) do
73
+ # This creates a copy of the current node and imports it (makes it valid) in the context
74
+ # of the destination document. Importing means adjusting styles and list identifiers correctly.
75
+ newNode = importer.importNode(curNode, true)
76
+ curNode = curNode.getNextSibling()
77
+ cNode = curNode
78
+ dst_node.appendChild(newNode)
79
+ end
80
+
81
+ # Save the finished document.
82
+ dst_doc.save(data_dir + "Template Out.doc");
83
+ end
84
+
85
+ def untangle_row_bookmark(doc)
86
+ bookmarks = doc.getRange().getBookmarks()
87
+ bookmarks_count = bookmarks.getCount()
88
+
89
+ i = 0
90
+ while i < bookmarks_count do
91
+ bookmark = bookmarks.get(i)
92
+ row1 = bookmark.getBookmarkStart().getAncestor(Rjb::import("com.aspose.words.Row"))
93
+ row2 = bookmark.getBookmarkEnd().getAncestor(Rjb::import("com.aspose.words.Row"))
94
+
95
+ # If both rows are found okay and the bookmark start and end are contained
96
+ # in adjacent rows, then just move the bookmark end node to the end
97
+ # of the last paragraph in the last cell of the top row.
98
+ if ((row1 != "") && (row2 != "") && (row1.getNextSibling() == row2)) then
99
+ row1.getLastCell().getLastParagraph().appendChild(bookmark.getBookmarkEnd())
100
+ end
101
+ $i +=1
102
+ end
103
+
104
+ # Save the document.
105
+ doc.save(@data_dir + "TestDefect1352 Out.doc")
106
+ end
107
+
108
+ def delete_row_by_bookmark(doc, bookmark_name)
109
+ raise 'bookmark_name not specified.' if bookmark_name.empty?
110
+
111
+ bookmark = doc.getRange().getBookmarks().get(bookmark_name)
112
+
113
+ if bookmark.nil? then
114
+ return
115
+ end
116
+
117
+ # Get the parent row of the bookmark. Exit if the bookmark is not in a row.
118
+ row = bookmark.getBookmarkStart().getAncestor(Rjb::import('com.aspose.words.Row'))
119
+
120
+ if row.nil? then
121
+ return
122
+ end
123
+
124
+ # Remove the row.
125
+ row.remove()
126
+
127
+ # Save the document.
128
+ doc.save(@data_dir + "TestDefect1352 Out.doc")
129
+ end
130
+
131
+ end
132
+ end