ooxml_parser 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (223) hide show
  1. checksums.yaml +7 -0
  2. data/.overcommit.yml +35 -0
  3. data/Changelog.md +25 -0
  4. data/LICENSE.txt +661 -0
  5. data/README.md +26 -0
  6. data/circle.yml +3 -0
  7. data/lib/ooxml_parser/common_parser/common_data/alingment.rb +56 -0
  8. data/lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content.rb +34 -0
  9. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb +123 -0
  10. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_axis.rb +34 -0
  11. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_axis_title.rb +38 -0
  12. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_cells_range.rb +23 -0
  13. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_legend.rb +33 -0
  14. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_point.rb +11 -0
  15. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_style/office_2007_chart_style.rb +17 -0
  16. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_style/office_2010_chart_style.rb +17 -0
  17. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/display_labels_properties.rb +26 -0
  18. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/docx_drawing.rb +49 -0
  19. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_distance_from_text.rb +23 -0
  20. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_position.rb +35 -0
  21. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_properties.rb +11 -0
  22. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_wrap_drawing.rb +39 -0
  23. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb +32 -0
  24. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/docx_graphic.rb +34 -0
  25. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/group/docx_group_element.rb +10 -0
  26. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/group/docx_grouped_drawing.rb +34 -0
  27. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip.rb +27 -0
  28. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_picture.rb +26 -0
  29. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape.rb +25 -0
  30. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_body_properties/ooxml_shape_body_properties/preset_text_warp.rb +16 -0
  31. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_body_properties/ooxml_shape_body_properties.rb +30 -0
  32. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/docx_color_scheme.rb +37 -0
  33. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/docx_pattern_fill.rb +20 -0
  34. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/gradient_color/docx_gradient_color.rb +30 -0
  35. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/gradient_color/docx_single_gradient_color.rb +6 -0
  36. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/solid_color/docx_solid_color.rb +10 -0
  37. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/custom_geometry/docx_custom_geometry/docx_shape_line_element.rb +10 -0
  38. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/custom_geometry/docx_custom_geometry/docx_shape_line_path.rb +44 -0
  39. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/custom_geometry/ooxml_custom_geometry.rb +23 -0
  40. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_color.rb +43 -0
  41. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_line.rb +54 -0
  42. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties/text_box.rb +25 -0
  43. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties.rb +40 -0
  44. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_size.rb +31 -0
  45. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/line/line_end/line_size.rb +20 -0
  46. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/line/line_end.rb +21 -0
  47. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_style/docx_shape_style.rb +5 -0
  48. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/group/old_docx_group.rb +31 -0
  49. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/group/old_docx_group_element.rb +10 -0
  50. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/group/old_docx_group_properties.rb +6 -0
  51. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/old_docx_picture.rb +26 -0
  52. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape.rb +24 -0
  53. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape_fill.rb +26 -0
  54. data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape_properties.rb +24 -0
  55. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/common_non_visual_properties.rb +25 -0
  56. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/non_visual_properties.rb +19 -0
  57. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/non_visual_shape_properties.rb +20 -0
  58. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/shape.rb +28 -0
  59. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/shape_placeholder.rb +18 -0
  60. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/shape_properties/ooxml_shift.rb +15 -0
  61. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/shape_properties/transform_effect.rb +28 -0
  62. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/shape_properties.rb +13 -0
  63. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/text_body/ooxml_text_box.rb +26 -0
  64. data/lib/ooxml_parser/common_parser/common_data/alternate_content/shape/text_body/text_body.rb +23 -0
  65. data/lib/ooxml_parser/common_parser/common_data/borders_properties.rb +58 -0
  66. data/lib/ooxml_parser/common_parser/common_data/color.rb +473 -0
  67. data/lib/ooxml_parser/common_parser/common_data/colors/color_alpha_channel.rb +14 -0
  68. data/lib/ooxml_parser/common_parser/common_data/colors/color_properties.rb +21 -0
  69. data/lib/ooxml_parser/common_parser/common_data/colors/hsl_color.rb +150 -0
  70. data/lib/ooxml_parser/common_parser/common_data/colors/image/fill_rectangle.rb +22 -0
  71. data/lib/ooxml_parser/common_parser/common_data/colors/image/stretching.rb +11 -0
  72. data/lib/ooxml_parser/common_parser/common_data/colors/image_fill.rb +32 -0
  73. data/lib/ooxml_parser/common_parser/common_data/colors/image_properties.rb +16 -0
  74. data/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color/gradient_stop.rb +15 -0
  75. data/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color/linear_gradient.rb +10 -0
  76. data/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color.rb +35 -0
  77. data/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/presentation_pattern.rb +22 -0
  78. data/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill.rb +33 -0
  79. data/lib/ooxml_parser/common_parser/common_data/colors/scheme_color.rb +14 -0
  80. data/lib/ooxml_parser/common_parser/common_data/colors/theme_colors.rb +22 -0
  81. data/lib/ooxml_parser/common_parser/common_data/colors/tile.rb +21 -0
  82. data/lib/ooxml_parser/common_parser/common_data/coordinates.rb +127 -0
  83. data/lib/ooxml_parser/common_parser/common_data/font_style.rb +101 -0
  84. data/lib/ooxml_parser/common_parser/common_data/hyperlink.rb +53 -0
  85. data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +87 -0
  86. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb +48 -0
  87. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/outline.rb +23 -0
  88. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/strikeout.rb +16 -0
  89. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties.rb +79 -0
  90. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run.rb +24 -0
  91. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/numbering/numbering_properties/numbering_level.rb +25 -0
  92. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/numbering/numbering_properties.rb +69 -0
  93. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/numbering.rb +18 -0
  94. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb +115 -0
  95. data/lib/ooxml_parser/common_parser/common_data/paragraph.rb +35 -0
  96. data/lib/ooxml_parser/common_parser/common_data/table/margins/paragraph_margins.rb +35 -0
  97. data/lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb +47 -0
  98. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_cell_margin.rb +20 -0
  99. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_element.rb +20 -0
  100. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_look.rb +43 -0
  101. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_position.rb +49 -0
  102. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style.rb +83 -0
  103. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_elements.rb +21 -0
  104. data/lib/ooxml_parser/common_parser/common_data/table/properties/whole_table/line_join.rb +19 -0
  105. data/lib/ooxml_parser/common_parser/common_data/table/properties/whole_table/table_cell_style.rb +20 -0
  106. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/cell.rb +43 -0
  107. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/cell_properties.rb +142 -0
  108. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/merge.rb +18 -0
  109. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/border.rb +25 -0
  110. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/borders.rb +125 -0
  111. data/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/table_cell_line.rb +35 -0
  112. data/lib/ooxml_parser/common_parser/common_data/table/row/row/table_row_properties.rb +22 -0
  113. data/lib/ooxml_parser/common_parser/common_data/table/row/row.rb +33 -0
  114. data/lib/ooxml_parser/common_parser/common_data/table/table_grid.rb +9 -0
  115. data/lib/ooxml_parser/common_parser/common_data/table/table_properties.rb +77 -0
  116. data/lib/ooxml_parser/common_parser/common_data/table.rb +41 -0
  117. data/lib/ooxml_parser/common_parser/common_data/underline.rb +40 -0
  118. data/lib/ooxml_parser/common_parser/common_document_structure.rb +7 -0
  119. data/lib/ooxml_parser/configuration.rb +20 -0
  120. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comment.rb +28 -0
  121. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb +10 -0
  122. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_properties.rb +21 -0
  123. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb +70 -0
  124. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/accent.rb +11 -0
  125. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/bar.rb +10 -0
  126. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/box.rb +11 -0
  127. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/delimeter.rb +12 -0
  128. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/fraction.rb +11 -0
  129. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/function.rb +11 -0
  130. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/group_char.rb +13 -0
  131. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/index.rb +12 -0
  132. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/limit.rb +12 -0
  133. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/matrix/matrix_row.rb +10 -0
  134. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/matrix.rb +10 -0
  135. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/operator.rb +13 -0
  136. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/radical.rb +11 -0
  137. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula.rb +203 -0
  138. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape/offset.rb +10 -0
  139. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape/shadow.rb +10 -0
  140. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape/shape_properties/shape_margins.rb +11 -0
  141. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape/shape_properties/shape_size.rb +10 -0
  142. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape/shape_properties/stroke.rb +10 -0
  143. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape/shape_properties.rb +16 -0
  144. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb +40 -0
  145. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/text_fill.rb +13 -0
  146. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/text_outline.rb +22 -0
  147. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb +388 -0
  148. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/frame_properties.rb +46 -0
  149. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb +87 -0
  150. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style/bookmark.rb +10 -0
  151. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style/paragraph_tab.rb +19 -0
  152. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style/style_parametres.rb +35 -0
  153. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style.rb +56 -0
  154. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph.rb +324 -0
  155. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb +37 -0
  156. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/image.rb +15 -0
  157. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/columns/column.rb +10 -0
  158. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/columns.rb +37 -0
  159. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/document_grid.rb +29 -0
  160. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb +49 -0
  161. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_margins.rb +42 -0
  162. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb +88 -0
  163. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/size.rb +84 -0
  164. data/lib/ooxml_parser/docx_parser/docx_data/document_structure.rb +232 -0
  165. data/lib/ooxml_parser/docx_parser/docx_parser.rb +16 -0
  166. data/lib/ooxml_parser/helpers/string_helper.rb +22 -0
  167. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_comment/presentation_comment_author.rb +25 -0
  168. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_comment.rb +31 -0
  169. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme/theme_color.rb +40 -0
  170. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme.rb +44 -0
  171. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/background.rb +19 -0
  172. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/graphic_frame/graphic_frame.rb +34 -0
  173. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/presentation_alternate_content.rb +25 -0
  174. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shape/non_visual_shape_properties/hyperlinks/hyperlink_for_hover.rb +23 -0
  175. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shape/shape_properties/extents.rb +10 -0
  176. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shape/shape_properties/offset.rb +10 -0
  177. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shape/text_body/paragraph.rb +10 -0
  178. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shape/text_body/text_field.rb +18 -0
  179. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shapes_grouping/shapes_grouping.rb +9 -0
  180. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/shapes_grouping/grouping_properties.rb +16 -0
  181. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/shapes_grouping.rb +30 -0
  182. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/animation_effect/animation_effect.rb +22 -0
  183. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/set_time_node/behavior/behavior.rb +28 -0
  184. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/set_time_node/behavior/target_element.rb +31 -0
  185. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/set_time_node/set_time_node.rb +20 -0
  186. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node/common_timing/condition.rb +26 -0
  187. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node/common_timing.rb +33 -0
  188. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node.rb +52 -0
  189. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing.rb +23 -0
  190. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/sound_action/sound/sound.rb +18 -0
  191. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/sound_action/sound_action.rb +18 -0
  192. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/transition.rb +43 -0
  193. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/transition_properties/transition_properties.rb +9 -0
  194. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb +110 -0
  195. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide_size.rb +20 -0
  196. data/lib/ooxml_parser/pptx_parser/pptx_data/presentation.rb +62 -0
  197. data/lib/ooxml_parser/pptx_parser/pptx_parser.rb +15 -0
  198. data/lib/ooxml_parser/version.rb +6 -0
  199. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments/excel_comment/excel_comment_character/excel_comment_character_properties.rb +27 -0
  200. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments/excel_comment/excel_comment_character.rb +25 -0
  201. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments/excel_comment.rb +20 -0
  202. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments.rb +43 -0
  203. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_format_properties.rb +21 -0
  204. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view/pane.rb +23 -0
  205. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view.rb +18 -0
  206. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb +24 -0
  207. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing/xlsx_drawing_position/xlsx_drawing_position_parameters.rb +22 -0
  208. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing/xlsx_drawing_position.rb +22 -0
  209. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing/xlsx_shape_grouping.rb +37 -0
  210. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing.rb +49 -0
  211. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style/alignment.rb +30 -0
  212. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style/foreground_color.rb +25 -0
  213. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style/ooxml_font.rb +38 -0
  214. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb +95 -0
  215. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb +47 -0
  216. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row.rb +19 -0
  217. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_table.rb +30 -0
  218. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb +74 -0
  219. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb +108 -0
  220. data/lib/ooxml_parser/xlsx_parser/xlsx_parser.rb +15 -0
  221. data/lib/ooxml_parser.rb +35 -0
  222. data/ooxml_parser.gemspec +30 -0
  223. metadata +310 -0
@@ -0,0 +1,32 @@
1
+ require_relative 'tile'
2
+ require_relative 'image_properties'
3
+ require_relative 'image/stretching'
4
+ module OoxmlParser
5
+ class ImageFill < OOXMLDocumentObject
6
+ attr_accessor :path, :stretch, :tile, :properties
7
+
8
+ alias path_to_media_file path
9
+
10
+ def initialize(path = '')
11
+ @path = path
12
+ end
13
+
14
+ def self.parse(blip_fill_node)
15
+ image = ImageFill.new
16
+ blip_fill_node.xpath('*').each do |blip_fill_node_child|
17
+ case blip_fill_node_child.name
18
+ when 'blip'
19
+ path_to_original_image = OOXMLDocumentObject.get_link_from_rels(blip_fill_node_child.attribute('embed').value)
20
+ FileUtils.copy(dir + path_to_original_image, OOXMLDocumentObject.media_folder + File.basename(path_to_original_image))
21
+ image.path = OOXMLDocumentObject.media_folder + File.basename(path_to_original_image)
22
+ image.properties = ImageProperties.parse(blip_fill_node_child)
23
+ when 'stretch'
24
+ image.stretch = Stretching.parse(blip_fill_node_child) # !blip_fill_node_child.xpath('a:fillRect').first.nil?
25
+ when 'tile'
26
+ image.tile = Tile.parse(blip_fill_node_child)
27
+ end
28
+ end
29
+ image
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,16 @@
1
+ module OoxmlParser
2
+ class ImageProperties
3
+ attr_accessor :alpha_modulate_fixed_effect
4
+
5
+ def self.parse(blip_properties_node)
6
+ properties = ImageProperties.new
7
+ blip_properties_node.xpath('*').each do |property_node|
8
+ case property_node.name
9
+ when 'alphaModFix'
10
+ properties.alpha_modulate_fixed_effect = (property_node.attribute('amt').value.to_f / 1_000.0).round(1)
11
+ end
12
+ end
13
+ properties
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module OoxmlParser
2
+ class GradientStop < OOXMLDocumentObject
3
+ attr_accessor :position, :color
4
+
5
+ def initialize(position)
6
+ @position = position
7
+ end
8
+
9
+ def self.parse(gs_node)
10
+ gradient_stop = GradientStop.new(gs_node.attribute('pos').value.to_i / 1_000)
11
+ gs_node.xpath('*').each { |color_node| gradient_stop.color = Color.parse_color(color_node) }
12
+ gradient_stop
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module OoxmlParser
2
+ class LinearGradient
3
+ attr_accessor :angle, :scaled
4
+
5
+ def initialize(angle = nil, scaled = nil)
6
+ @angle = angle
7
+ @scaled = scaled
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,35 @@
1
+ require_relative 'gradient_color/gradient_stop'
2
+ require_relative 'gradient_color/linear_gradient'
3
+ module OoxmlParser
4
+ class GradientColor
5
+ attr_accessor :gradient_stops, :path
6
+
7
+ def initialize(colors = [])
8
+ @gradient_stops = colors
9
+ end
10
+
11
+ def self.parse(gradient_fill_node)
12
+ gradient_color = GradientColor.new
13
+ gradient_fill_node.xpath('*').each do |gradient_fill_node_child|
14
+ case gradient_fill_node_child.name
15
+ when 'gsLst'
16
+ begin
17
+ gradient_fill_node_child.xpath('//a:gs')
18
+ namespace = 'a'
19
+ rescue Nokogiri::XML::XPath::SyntaxError
20
+ namespace = 'w14'
21
+ end
22
+ gradient_fill_node_child.xpath("#{namespace}:gs").each do |gradient_stop_node|
23
+ gradient_color.gradient_stops << GradientStop.parse(gradient_stop_node)
24
+ end
25
+ when 'path'
26
+ gradient_color.path = gradient_fill_node_child.attribute('path').value.to_sym
27
+ when 'lin'
28
+ gradient_color.path = LinearGradient.new(gradient_fill_node_child.attribute('ang').value.to_f / 100_000.0,
29
+ gradient_fill_node_child.attribute('scaled').value.to_i)
30
+ end
31
+ end
32
+ gradient_color
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ module OoxmlParser
2
+ class PresentationPattern < OOXMLDocumentObject
3
+ attr_accessor :preset, :foreground_color, :background_color
4
+
5
+ def initialize(preset = nil)
6
+ @preset = preset
7
+ end
8
+
9
+ def self.parse(pattern_node)
10
+ pattern = PresentationPattern.new(pattern_node.attribute('prst').value.to_sym)
11
+ pattern_node.xpath('*').each do |color_node|
12
+ case color_node.name
13
+ when 'fgClr'
14
+ pattern.foreground_color = Color.parse_color(color_node.xpath('*').first)
15
+ when 'bgClr'
16
+ pattern.background_color = Color.parse_color(color_node.xpath('*').first)
17
+ end
18
+ end
19
+ pattern
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'image_fill'
2
+ require_relative 'presentation_fill/gradient_color'
3
+ require_relative 'presentation_fill/presentation_pattern'
4
+ module OoxmlParser
5
+ class PresentationFill < OOXMLDocumentObject
6
+ attr_accessor :type, :image, :color, :pattern
7
+
8
+ def self.parse(parent_fill_node)
9
+ fill = PresentationFill.new
10
+ return nil if parent_fill_node.xpath('*').empty?
11
+ parent_fill_node.xpath('*').each do |fill_node|
12
+ case fill_node.name
13
+ when 'gradFill'
14
+ fill.type = :gradient
15
+ fill.color = GradientColor.parse(fill_node)
16
+ when 'solidFill'
17
+ fill.type = :solid
18
+ fill.color = Color.parse_color(fill_node.xpath('*').first)
19
+ when 'blipFill'
20
+ fill.type = :image
21
+ fill.image = ImageFill.parse(fill_node)
22
+ when 'pattFill'
23
+ fill.type = :pattern
24
+ fill.pattern = PresentationPattern.parse(fill_node)
25
+ when 'noFill'
26
+ fill.type = :noneColor
27
+ fill.color = :none
28
+ end
29
+ end
30
+ fill
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,14 @@
1
+ module OoxmlParser
2
+ class SchemeColor
3
+ attr_accessor :value, :properties, :converted_color
4
+
5
+ def initialize(value = nil, converted_color = 0)
6
+ @value = value
7
+ @converted_color = converted_color
8
+ end
9
+
10
+ def to_s
11
+ @converted_color.to_s
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ # Class for hold ThemeColors list
2
+ module OoxmlParser
3
+ class ThemeColors
4
+ class << self
5
+ # @return [Hash] list of colors
6
+ attr_accessor :list
7
+
8
+ def parse_color_theme(color_theme_node)
9
+ themes_array = ThemeColors.list.to_a
10
+ # TODO: if no swap performed - incorrect color parsing. But don't know why it needed
11
+ themes_array[0], themes_array[1] = themes_array[1], themes_array[0]
12
+ themes_array[2], themes_array[3] = themes_array[3], themes_array[2]
13
+ hls = HSLColor.rgb_to_hsl(themes_array[color_theme_node.attribute('theme').value.to_i][1])
14
+ tint = 0
15
+ unless color_theme_node.attribute('tint').nil?
16
+ tint = color_theme_node.attribute('tint').value.to_f
17
+ end
18
+ hls.calculate_rgb_with_tint(tint)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ module OoxmlParser
2
+ class Tile < OOXMLDocumentObject
3
+ attr_accessor :offset, :ratio, :flip, :align
4
+
5
+ def initialize(offset = nil, ratio = nil)
6
+ @offset = offset
7
+ @ratio = ratio
8
+ end
9
+
10
+ def self.parse(tile_node)
11
+ tile = Tile.new(OOXMLShift.parse(tile_node, 'tx', 'ty'), OOXMLShift.parse(tile_node, 'sx', 'sy'))
12
+ tile_node.attributes.each do |key, value|
13
+ case key
14
+ when 'algn'
15
+ tile.align = Alignment.parse(value)
16
+ end
17
+ end
18
+ tile
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,127 @@
1
+ module OoxmlParser
2
+ class Coordinates
3
+ attr_accessor :row, :column, :list
4
+
5
+ def initialize(row = nil, column = nil, list = nil)
6
+ @row = row.nil? ? row : row.to_i
7
+ @column = column
8
+ @list = list
9
+ end
10
+
11
+ class << self
12
+ # @param [String] string to parse
13
+ # @return [Coordinates]
14
+ def parse_coordinates_from_string(string)
15
+ coordinates = Coordinates.new
16
+ begin
17
+ coordinates.list = string.match(/'\w+'/)[0].delete("''")
18
+ rescue StandardError
19
+ 'Raise Exception'
20
+ end
21
+ string = string.split('!').last
22
+ if coordinates?(string)
23
+ coordinates.row = string.scan(/[0-9]/).join('').to_i
24
+ coordinates.column = string.scan(/[A-Z]/).join('')
25
+ end
26
+ coordinates
27
+ end
28
+
29
+ def parser_coordinates_range(arguments_string)
30
+ sheet_name = 'Sheet1'
31
+
32
+ if arguments_string.include?('!')
33
+ sheet_name, arguments_string = arguments_string.split('!')
34
+ end
35
+
36
+ range = arguments_string.split(':')
37
+
38
+ difference = []
39
+ symbols_from = range.first.scan(/[a-zA-z]/).join
40
+ symbols_to = range.last.scan(/[a-zA-z]/).join
41
+ digits_from = range.first.scan(/[0-9]/).join
42
+ digits_to = range.last.scan(/[0-9]/).join
43
+
44
+ difference[0] = [symbols_from, symbols_to] unless symbols_from == symbols_to
45
+ difference[1] = [digits_from, digits_to] unless digits_from == digits_to
46
+ arguments_array = []
47
+ case difference.length
48
+ when 0
49
+ arguments_array << Coordinates.new(digits_from, symbols_from)
50
+ when 1
51
+ (difference.first.first..difference.first.last).each do |symbol|
52
+ arguments_array << Coordinates.new(digits_from, symbol, sheet_name)
53
+ end
54
+ when 2
55
+ case difference.first
56
+ when nil
57
+ (difference.last.first..difference.last.last).each do |digit|
58
+ arguments_array << Coordinates.new(digit, symbols_from, sheet_name)
59
+ end
60
+ else
61
+ (difference.first.first..difference.first.last).each do |symbol|
62
+ (difference.last.first..difference.last.last).each do |digit|
63
+ arguments_array << Coordinates.new(digit, symbol, sheet_name)
64
+ end
65
+ end
66
+ end
67
+ else
68
+ raise 'Wrong arguments format'
69
+ end
70
+ arguments_array
71
+ end
72
+
73
+ # This method check is argument contains coordinate
74
+ # @param [String] string
75
+ def coordinates?(string)
76
+ !/^([A-Z]+)(\d+)$/.match(string).nil?
77
+ end
78
+
79
+ # @param [String or Fixnum] number to convert
80
+ # @return [String] column's name
81
+ # This method takes string like '12' or '45' etc.
82
+ # and converts into spreadsheet column's name
83
+ # StringHelper.get_column_name('12') #=> "L"
84
+ # StringHelper.get_column_name('45') #=> "AS"
85
+ # StringHelper.get_column_name('287') #=> "KA"
86
+ def get_column_name(number)
87
+ (number.to_i > 0 ? ('A'..'Z').to_a[(number.to_i - 1) % 26] + get_column_name((number.to_i - 1) / 26).reverse : '').reverse
88
+ end
89
+ end
90
+
91
+ # get_column_number -> integer
92
+ # @return [Integer] number of column
93
+ # This method takes @column string
94
+ # and converts into integer
95
+ def get_column_number
96
+ @column.reverse.each_char.reduce(0) do |result, char|
97
+ result + (char.downcase.ord - 96) * (26**@column.reverse.index(char))
98
+ end
99
+ end
100
+
101
+ # Compares rows of two cells
102
+ # @param [Coordinates] other_cell other cell coordinates
103
+ # @return [true, false] true, if row greater, than other row
104
+ def row_greater_that_other?(other_cell)
105
+ @row > other_cell.row
106
+ end
107
+
108
+ # Compares columns of two cells
109
+ # @param [Coordinates] other_cell other cell coordinates
110
+ # @return [true, false] true, if column greater, than other row
111
+ def column_greater_that_other?(other_cell)
112
+ get_column_number > other_cell.get_column_number
113
+ end
114
+
115
+ def to_s
116
+ "#{@column}#{@row} #{@list ? "list: #{@list}" : ''}"
117
+ end
118
+
119
+ def nil?
120
+ @column.nil? && @list.nil? && @row.nil?
121
+ end
122
+
123
+ def ==(other)
124
+ other.is_a?(Coordinates) ? (@row == other.row && @column == other.column) : false
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,101 @@
1
+ require_relative 'underline'
2
+ # @author Pavel.Lobashov
3
+ # Class for working with font styles (bold,italic,underlined,strike)
4
+ # noinspection RubyClassMethodNamingConvention
5
+ module OoxmlParser
6
+ class FontStyle
7
+ # @return [false,true] is bold?
8
+ attr_accessor :bold
9
+ # @return [false,true] is bold?
10
+ attr_accessor :italic
11
+ # @return [Underline] underline type
12
+ attr_accessor :underlined
13
+ # @return [Strike] strike type
14
+ attr_accessor :strike
15
+
16
+ # Default constructor
17
+ # @param [true, false] bold is bold?
18
+ # @param [true, false] italic is italic?
19
+ # @param [true, false, String] underlined if not false or nil - default Underline, else none
20
+ # @param [Symbol] strike string with strike type
21
+ # @return [FontStyle] new font style
22
+ def initialize(bold = false, italic = false, underlined = Underline.new(:none), strike = :none)
23
+ @bold = bold
24
+ @italic = italic
25
+ @underlined = (underlined == false || underlined.nil?) ? Underline.new(:none) : underlined
26
+ @strike = strike
27
+ end
28
+
29
+ class << self
30
+ # Generate all possible combination of styles without parameter stoke (8)
31
+ # @return [Array] with all FontStyle
32
+ def generate_all_styles_without_stroke
33
+ styles_array = []
34
+ styles_array << FontStyle.new(true, true, Underline.new(:single), :none)
35
+ styles_array << FontStyle.new(true, true, nil, :none)
36
+ styles_array << FontStyle.new(true, false, Underline.new(:single), :none)
37
+ styles_array << FontStyle.new(true, false, nil, :none)
38
+
39
+ styles_array << FontStyle.new(false, true, Underline.new(:single), :none)
40
+ styles_array << FontStyle.new(false, true, nil, :none)
41
+ styles_array << FontStyle.new(false, false, Underline.new(:single), :none)
42
+ styles_array << FontStyle.new(false, false, nil, :none)
43
+ end
44
+
45
+ # Generate all possible combination of styles (16)
46
+ # @return [Array] with all FontStyle
47
+ def generate_all_styles
48
+ styles_array = []
49
+ styles_array << generate_all_styles_without_stroke
50
+
51
+ styles_array << FontStyle.new(true, true, Underline.new(:single), :single)
52
+ styles_array << FontStyle.new(true, true, nil, :single)
53
+ styles_array << FontStyle.new(true, false, Underline.new(:single), :single)
54
+ styles_array << FontStyle.new(false, true, Underline.new(:single), :single)
55
+
56
+ styles_array << FontStyle.new(true, false, nil, :single)
57
+ styles_array << FontStyle.new(false, false, Underline.new(:single), :single)
58
+ styles_array << FontStyle.new(false, true, nil, :single)
59
+ styles_array << FontStyle.new(false, false, nil, :single)
60
+ styles_array.flatten
61
+ end
62
+ end
63
+
64
+ # Default == operator
65
+ # @return [true, false] true if two same, false if different
66
+ def ==(other)
67
+ (@bold == other.bold) && (@italic == other.italic) && (@underlined == other.underlined) && (@strike == other.strike)
68
+ end
69
+
70
+ # Default + operator
71
+ # @return [FontStyle] the result of overlapping of two styles
72
+ def +(other)
73
+ result = FontStyle.new
74
+ result.bold = (other.bold == @bold) ? @bold : other.bold
75
+ result.italic = (other.italic == @italic) ? @italic : other.italic
76
+ result.underlined = (other.underlined == @underlined) ? @underlined : other.underlined
77
+ result.strike = (other.strike == @strike) ? @strike : other.strike
78
+ result
79
+ end
80
+
81
+ # Default to_s operator
82
+ # @return [String] with text representation
83
+ def to_s
84
+ "Bold: #{@bold}, Italic: #{@italic}, Underlined: #{@underlined}, Strike: #{@strike}"
85
+ end
86
+
87
+ def copy
88
+ return dup if underlined.nil?
89
+ other = FontStyle.new
90
+ instance_variables.each do |variable|
91
+ case variable
92
+ when @underlined
93
+ other.instance_variable_set(variable, underlined.copy)
94
+ else
95
+ other.instance_variable_set(variable, instance_variable_get(variable))
96
+ end
97
+ end
98
+ other
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,53 @@
1
+ module OoxmlParser
2
+ class Hyperlink < OOXMLDocumentObject
3
+ attr_accessor :url, :tooltip, :coordinates, :id, :highlight_click, :action
4
+
5
+ def initialize(link = nil, tooltip = nil, coordinates = nil)
6
+ @url = link
7
+ @tooltip = tooltip
8
+ @coordinates = coordinates
9
+ end
10
+
11
+ alias link url
12
+ alias link_to url
13
+ alias link= url=
14
+ alias link_to= url=
15
+
16
+ def self.parse(on_click_hyperlink_node)
17
+ hyperlink = Hyperlink.new
18
+ on_click_hyperlink_node.attributes.each do |key, value|
19
+ case key
20
+ when 'location'
21
+ hyperlink.url = Coordinates.parse_coordinates_from_string(value.value)
22
+ when 'id'
23
+ hyperlink.url = OOXMLDocumentObject.get_link_from_rels(on_click_hyperlink_node.attribute('id').value)
24
+ when 'tooltip'
25
+ hyperlink.tooltip = value.value
26
+ when 'ref'
27
+ hyperlink.coordinates = Coordinates.parse_coordinates_from_string(value.value)
28
+ end
29
+ end
30
+ action = on_click_hyperlink_node.attribute('action').value unless on_click_hyperlink_node.attribute('action').nil?
31
+ case action
32
+ when 'ppaction://hlinkshowjump?jump=previousslide'
33
+ hyperlink.action = :previous_slide
34
+ when 'ppaction://hlinkshowjump?jump=nextslide'
35
+ hyperlink.action = :next_slide
36
+ when 'ppaction://hlinkshowjump?jump=firstslide'
37
+ hyperlink.action = :first_slide
38
+ when 'ppaction://hlinkshowjump?jump=lastslide'
39
+ hyperlink.action = :last_slide
40
+ when 'ppaction://hlinksldjump'
41
+ hyperlink.action = :slide
42
+ hyperlink.link_to = OOXMLDocumentObject.get_link_from_rels(on_click_hyperlink_node.attribute('id').value).scan(/\d+/).join('').to_i
43
+ else
44
+ unless on_click_hyperlink_node.attribute('id').nil?
45
+ hyperlink.action = :external_link
46
+ hyperlink.link_to = OOXMLDocumentObject.get_link_from_rels(on_click_hyperlink_node.attribute('id').value)
47
+ end
48
+ end
49
+ hyperlink.highlight_click = StringHelper.to_bool(on_click_hyperlink_node.attribute('highlightClick').value) unless on_click_hyperlink_node.attribute('highlightClick').nil?
50
+ hyperlink
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,87 @@
1
+ require 'securerandom'
2
+ require 'nokogiri'
3
+ require 'xmlsimple'
4
+ require 'zip'
5
+
6
+ module OoxmlParser
7
+ class OOXMLDocumentObject
8
+ DEFAULT_DIRECTORY_FOR_MEDIA = '/tmp'.freeze
9
+
10
+ class << self
11
+ attr_accessor :namespace_prefix
12
+ attr_accessor :root_subfolder
13
+ attr_accessor :theme
14
+ attr_accessor :xmls_stack
15
+ attr_accessor :path_to_folder
16
+
17
+ def copy_file_and_rename_to_zip(path)
18
+ file_name = File.basename(path)
19
+ tmp_folder = "/tmp/office_open_xml_parser_#{SecureRandom.uuid}"
20
+ file_path = "#{tmp_folder}/#{file_name}"
21
+ FileUtils.rm_rf(tmp_folder) if File.directory?(tmp_folder)
22
+ FileUtils.mkdir_p(tmp_folder)
23
+ path = "#{Dir.pwd}/#{path}" unless path[0] == '/'
24
+ raise "Cannot find file by path #{path}" unless File.exist?(path)
25
+ FileUtils.cp path, tmp_folder
26
+ file_path
27
+ end
28
+
29
+ def unzip_file(path_to_file, destination)
30
+ Zip.warn_invalid_date = false
31
+ Zip::File.open(path_to_file) do |zip_file|
32
+ raise LoadError, "There is no files in zip #{path_to_file}" if zip_file.entries.empty?
33
+ zip_file.each do |file|
34
+ file_path = File.join(destination, file.name)
35
+ FileUtils.mkdir_p(File.dirname(file_path))
36
+ zip_file.extract(file, file_path) unless File.exist?(file_path)
37
+ end
38
+ end
39
+ end
40
+
41
+ def dir
42
+ OOXMLDocumentObject.path_to_folder + File.dirname(OOXMLDocumentObject.xmls_stack.last) + '/'
43
+ end
44
+
45
+ def current_xml
46
+ OOXMLDocumentObject.path_to_folder + OOXMLDocumentObject.xmls_stack.last
47
+ end
48
+
49
+ def add_to_xmls_stack(path)
50
+ OOXMLDocumentObject.xmls_stack << if path.include?('..')
51
+ "#{File.dirname(OOXMLDocumentObject.xmls_stack.last)}/#{path}"
52
+ else
53
+ path
54
+ end
55
+ end
56
+
57
+ def get_link_from_rels(id)
58
+ rels_path = dir + "_rels/#{File.basename(OOXMLDocumentObject.xmls_stack.last)}.rels"
59
+ raise LoadError, "Cannot find .rels file by path: #{rels_path}" unless File.exist?(rels_path)
60
+ relationships = XmlSimple.xml_in(File.open(rels_path))
61
+ relationships['Relationship'].each { |relationship| return relationship['Target'] if id == relationship['Id'] }
62
+ end
63
+
64
+ def media_folder
65
+ path = "#{DEFAULT_DIRECTORY_FOR_MEDIA}/media_from_#{@file_name}"
66
+ FileUtils.mkdir(path) unless File.exist?(path)
67
+ path + '/'
68
+ end
69
+
70
+ def option_enabled?(node, attribute_name = 'val')
71
+ return true if node.to_s == '1'
72
+ return false if node.to_s == '0'
73
+ return false if node.attribute(attribute_name).nil?
74
+ status = node.attribute(attribute_name).value
75
+ status == 'true' || status == 'on' || status == '1'
76
+ end
77
+
78
+ def copy_media_file(path_to_file)
79
+ folder_to_save_media = '/tmp/media_from_' + File.basename(OOXMLDocumentObject.path_to_folder)
80
+ path_to_copied_file = folder_to_save_media + '/' + File.basename(path_to_file)
81
+ FileUtils.mkdir(folder_to_save_media) unless File.exist?(folder_to_save_media)
82
+ FileUtils.copy_file(OOXMLDocumentObject.path_to_folder + path_to_file, path_to_copied_file)
83
+ path_to_copied_file
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,48 @@
1
+ require_relative 'paragrpah_properties/spacing'
2
+ require_relative 'paragrpah_properties/numbering'
3
+ module OoxmlParser
4
+ class ParagraphProperties < OOXMLDocumentObject
5
+ attr_accessor :align, :numbering, :level, :spacing, :spacing_before, :spacing_after, :indent, :margin_left, :margin_right,
6
+ :tabs
7
+
8
+ def initialize(numbering = Numbering.new)
9
+ @numbering = numbering
10
+ @spacing = Spacing.new(0, 0, 1, :multiple)
11
+ end
12
+
13
+ def self.parse(paragraph_props_node)
14
+ paragraph_properties = ParagraphProperties.new
15
+ paragraph_properties.spacing.parse(paragraph_props_node)
16
+ paragraph_props_node.attributes.each do |key, value|
17
+ case key
18
+ when 'algn'
19
+ paragraph_properties.align = Alignment.parse(value)
20
+ when 'lvl'
21
+ paragraph_properties.level = value.value.to_i
22
+ when 'indent'
23
+ paragraph_properties.indent = (value.value.to_f / 360_000.0).round(2)
24
+ when 'marR'
25
+ paragraph_properties.margin_right = (value.value.to_f / 360_000.0).round(2)
26
+ when 'marL'
27
+ paragraph_properties.margin_left = (value.value.to_f / 360_000.0).round(2)
28
+ end
29
+ end
30
+ paragraph_props_node.xpath('*').each do |properties_element|
31
+ case properties_element.name
32
+ when 'buSzPct'
33
+ paragraph_properties.numbering.size = properties_element.attribute('val').value
34
+ when 'buFont'
35
+ paragraph_properties.numbering.font = properties_element.attribute('typeface').value
36
+ when 'buChar'
37
+ paragraph_properties.numbering.symbol = properties_element.attribute('char').value
38
+ when 'buAutoNum'
39
+ paragraph_properties.numbering.type = properties_element.attribute('type').value.to_sym
40
+ paragraph_properties.numbering.start_at = properties_element.attribute('startAt').value
41
+ when 'tabLst'
42
+ paragraph_properties.tabs = ParagraphTab.parse(properties_element)
43
+ end
44
+ end
45
+ paragraph_properties
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,23 @@
1
+ # Class for parsing Run Outline properties
2
+ module OoxmlParser
3
+ class Outline < OOXMLDocumentObject
4
+ attr_accessor :width
5
+ attr_accessor :color_scheme
6
+
7
+ def initialize
8
+ @width = 0
9
+ end
10
+
11
+ def self.parse(node)
12
+ outline = Outline.new
13
+ node.attributes.each do |key, value|
14
+ case key
15
+ when 'w'
16
+ outline.width = (value.value.to_f / 12_699.3).round(2)
17
+ end
18
+ end
19
+ outline.color_scheme = DocxColorScheme.parse(node)
20
+ outline
21
+ end
22
+ end
23
+ end