rubyXL 3.3.29 → 3.4.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (466) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +60 -0
  3. data/.rubocop.yml +124 -0
  4. data/CHANGELOG.md +12 -0
  5. data/Gemfile +11 -8
  6. data/LICENSE.txt +1 -1
  7. data/README.rdoc +57 -19
  8. data/Rakefile +29 -29
  9. data/VERSION +1 -1
  10. data/lib/rubyXL/cell.rb +2 -29
  11. data/lib/rubyXL/convenience_methods/cell.rb +276 -0
  12. data/lib/rubyXL/convenience_methods/color.rb +156 -0
  13. data/lib/rubyXL/convenience_methods/font.rb +63 -0
  14. data/lib/rubyXL/convenience_methods/workbook.rb +137 -0
  15. data/lib/rubyXL/convenience_methods/worksheet.rb +734 -0
  16. data/lib/rubyXL/convenience_methods.rb +5 -1122
  17. data/lib/rubyXL/objects/border.rb +0 -3
  18. data/lib/rubyXL/objects/calculation_chain.rb +2 -2
  19. data/lib/rubyXL/objects/cell_style.rb +4 -6
  20. data/lib/rubyXL/objects/chartsheet.rb +8 -12
  21. data/lib/rubyXL/objects/color.rb +4 -6
  22. data/lib/rubyXL/objects/column_range.rb +16 -15
  23. data/lib/rubyXL/objects/comments.rb +1 -4
  24. data/lib/rubyXL/objects/connection.rb +175 -0
  25. data/lib/rubyXL/objects/container_nodes.rb +1 -5
  26. data/lib/rubyXL/objects/content_types.rb +3 -6
  27. data/lib/rubyXL/objects/data_validation.rb +2 -2
  28. data/lib/rubyXL/objects/document_properties.rb +12 -15
  29. data/lib/rubyXL/objects/extensions.rb +0 -2
  30. data/lib/rubyXL/objects/external_links.rb +38 -8
  31. data/lib/rubyXL/objects/fill.rb +2 -5
  32. data/lib/rubyXL/objects/filters.rb +5 -7
  33. data/lib/rubyXL/objects/font.rb +2 -7
  34. data/lib/rubyXL/objects/formula.rb +3 -5
  35. data/lib/rubyXL/objects/ooxml_object.rb +40 -31
  36. data/lib/rubyXL/objects/query_table.rb +106 -0
  37. data/lib/rubyXL/objects/reference.rb +26 -17
  38. data/lib/rubyXL/objects/relationships.rb +14 -14
  39. data/lib/rubyXL/objects/root.rb +0 -2
  40. data/lib/rubyXL/objects/shared_strings.rb +4 -7
  41. data/lib/rubyXL/objects/sheet_common.rb +1 -3
  42. data/lib/rubyXL/objects/sheet_data.rb +44 -17
  43. data/lib/rubyXL/objects/simple_types.rb +19 -2
  44. data/lib/rubyXL/objects/storage.rb +60 -49
  45. data/lib/rubyXL/objects/stylesheet.rb +9 -17
  46. data/lib/rubyXL/objects/text.rb +6 -8
  47. data/lib/rubyXL/objects/theme.rb +23 -9
  48. data/lib/rubyXL/objects/workbook.rb +144 -36
  49. data/lib/rubyXL/objects/worksheet.rb +48 -34
  50. data/lib/rubyXL/parser.rb +1 -3
  51. data/lib/rubyXL/worksheet.rb +86 -86
  52. data/lib/rubyXL.rb +1 -1
  53. data/rdoc/README_rdoc.html +212 -153
  54. data/rdoc/RubyXL/AExtension.html +33 -69
  55. data/rdoc/RubyXL/AExtensionStorageArea.html +12 -18
  56. data/rdoc/RubyXL/ActiveX.html +26 -52
  57. data/rdoc/RubyXL/ActiveXBinary.html +12 -23
  58. data/rdoc/RubyXL/AdjustHandleList.html +13 -20
  59. data/rdoc/RubyXL/Alignment.html +13 -20
  60. data/rdoc/RubyXL/AlternateContent.html +12 -18
  61. data/rdoc/RubyXL/AlternateUrls.html +99 -0
  62. data/rdoc/RubyXL/Authors.html +13 -20
  63. data/rdoc/RubyXL/AutoFilter.html +13 -20
  64. data/rdoc/RubyXL/AutoFilterColumn.html +13 -20
  65. data/rdoc/RubyXL/BinaryImageFile.html +12 -26
  66. data/rdoc/RubyXL/BodyProperties.html +13 -20
  67. data/rdoc/RubyXL/BooleanNode.html +12 -18
  68. data/rdoc/RubyXL/BooleanValue.html +12 -18
  69. data/rdoc/RubyXL/Border.html +49 -101
  70. data/rdoc/RubyXL/BorderEdge.html +32 -61
  71. data/rdoc/RubyXL/Borders.html +25 -44
  72. data/rdoc/RubyXL/Break.html +13 -20
  73. data/rdoc/RubyXL/BreakList.html +13 -20
  74. data/rdoc/RubyXL/CT_AdjPoint2D.html +13 -20
  75. data/rdoc/RubyXL/CT_AlphaBiLevelEffect.html +13 -20
  76. data/rdoc/RubyXL/CT_AlphaModulateEffect.html +13 -20
  77. data/rdoc/RubyXL/CT_AlphaModulateFixedEffect.html +13 -20
  78. data/rdoc/RubyXL/CT_AlphaOutsetEffect.html +13 -20
  79. data/rdoc/RubyXL/CT_AlphaReplaceEffect.html +13 -20
  80. data/rdoc/RubyXL/CT_Backdrop.html +13 -20
  81. data/rdoc/RubyXL/CT_Bevel.html +13 -20
  82. data/rdoc/RubyXL/CT_BiLevelEffect.html +13 -20
  83. data/rdoc/RubyXL/CT_BlendEffect.html +13 -20
  84. data/rdoc/RubyXL/CT_Blip.html +13 -20
  85. data/rdoc/RubyXL/CT_BlipFillProperties.html +13 -20
  86. data/rdoc/RubyXL/CT_BlurEffect.html +13 -20
  87. data/rdoc/RubyXL/CT_Camera.html +13 -20
  88. data/rdoc/RubyXL/CT_Color.html +13 -20
  89. data/rdoc/RubyXL/CT_ColorChangeEffect.html +13 -20
  90. data/rdoc/RubyXL/CT_ColorMapping.html +13 -20
  91. data/rdoc/RubyXL/CT_ColorScheme.html +13 -20
  92. data/rdoc/RubyXL/CT_ColorSchemeAndMapping.html +13 -20
  93. data/rdoc/RubyXL/CT_ConnectionSite.html +13 -20
  94. data/rdoc/RubyXL/CT_ConnectionSiteList.html +13 -20
  95. data/rdoc/RubyXL/CT_DashStop.html +13 -20
  96. data/rdoc/RubyXL/CT_DashStopList.html +13 -20
  97. data/rdoc/RubyXL/CT_DefaultShapeDefinition.html +13 -20
  98. data/rdoc/RubyXL/CT_DuotoneEffect.html +13 -20
  99. data/rdoc/RubyXL/CT_EffectContainer.html +13 -20
  100. data/rdoc/RubyXL/CT_EffectList.html +13 -20
  101. data/rdoc/RubyXL/CT_EffectReference.html +13 -20
  102. data/rdoc/RubyXL/CT_EffectStyleItem.html +13 -20
  103. data/rdoc/RubyXL/CT_EffectStyleList.html +13 -20
  104. data/rdoc/RubyXL/CT_EmbeddedWAVAudioFile.html +13 -20
  105. data/rdoc/RubyXL/CT_FillEffect.html +13 -20
  106. data/rdoc/RubyXL/CT_FillOverlayEffect.html +13 -20
  107. data/rdoc/RubyXL/CT_FillStyleList.html +13 -20
  108. data/rdoc/RubyXL/CT_FlatText.html +13 -20
  109. data/rdoc/RubyXL/CT_FontCollection.html +13 -20
  110. data/rdoc/RubyXL/CT_FontReference.html +13 -20
  111. data/rdoc/RubyXL/CT_GeomGuideList.html +13 -20
  112. data/rdoc/RubyXL/CT_GlowEffect.html +13 -20
  113. data/rdoc/RubyXL/CT_GradientFillProperties.html +13 -20
  114. data/rdoc/RubyXL/CT_GradientStop.html +13 -20
  115. data/rdoc/RubyXL/CT_GradientStopList.html +13 -20
  116. data/rdoc/RubyXL/CT_HSLEffect.html +13 -20
  117. data/rdoc/RubyXL/CT_HslColor.html +13 -20
  118. data/rdoc/RubyXL/CT_Hyperlink.html +13 -20
  119. data/rdoc/RubyXL/CT_InnerShadowEffect.html +13 -20
  120. data/rdoc/RubyXL/CT_LightRig.html +13 -20
  121. data/rdoc/RubyXL/CT_LineEndProperties.html +13 -20
  122. data/rdoc/RubyXL/CT_LineJoinMiterProperties.html +13 -20
  123. data/rdoc/RubyXL/CT_LineProperties.html +13 -20
  124. data/rdoc/RubyXL/CT_LineStyleList.html +13 -20
  125. data/rdoc/RubyXL/CT_LinearShadeProperties.html +13 -20
  126. data/rdoc/RubyXL/CT_LuminanceEffect.html +13 -20
  127. data/rdoc/RubyXL/CT_ObjectStyleDefaults.html +13 -20
  128. data/rdoc/RubyXL/CT_OuterShadowEffect.html +13 -20
  129. data/rdoc/RubyXL/CT_Path2D.html +13 -20
  130. data/rdoc/RubyXL/CT_Path2DArcTo.html +13 -20
  131. data/rdoc/RubyXL/CT_Path2DCubicBezierTo.html +13 -20
  132. data/rdoc/RubyXL/CT_Path2DList.html +13 -20
  133. data/rdoc/RubyXL/CT_Path2DQuadBezierTo.html +13 -20
  134. data/rdoc/RubyXL/CT_Path2DTo.html +13 -20
  135. data/rdoc/RubyXL/CT_PathShadeProperties.html +13 -20
  136. data/rdoc/RubyXL/CT_PatternFillProperties.html +13 -20
  137. data/rdoc/RubyXL/CT_Point3D.html +13 -20
  138. data/rdoc/RubyXL/CT_PolarAdjustHandle.html +13 -20
  139. data/rdoc/RubyXL/CT_PresetColor.html +13 -20
  140. data/rdoc/RubyXL/CT_PresetLineDashProperties.html +13 -20
  141. data/rdoc/RubyXL/CT_PresetShadowEffect.html +13 -20
  142. data/rdoc/RubyXL/CT_PresetTextShape.html +13 -20
  143. data/rdoc/RubyXL/CT_ReflectionEffect.html +13 -20
  144. data/rdoc/RubyXL/CT_RelativeOffsetEffect.html +13 -20
  145. data/rdoc/RubyXL/CT_RelativeRect.html +13 -20
  146. data/rdoc/RubyXL/CT_SRgbColor.html +13 -20
  147. data/rdoc/RubyXL/CT_ScRgbColor.html +13 -20
  148. data/rdoc/RubyXL/CT_Scene3D.html +13 -20
  149. data/rdoc/RubyXL/CT_SchemeColor.html +13 -20
  150. data/rdoc/RubyXL/CT_Shape3D.html +13 -20
  151. data/rdoc/RubyXL/CT_ShapeStyle.html +13 -20
  152. data/rdoc/RubyXL/CT_SoftEdgesEffect.html +13 -20
  153. data/rdoc/RubyXL/CT_SphereCoords.html +13 -20
  154. data/rdoc/RubyXL/CT_StretchInfoProperties.html +13 -20
  155. data/rdoc/RubyXL/CT_StyleMatrix.html +13 -20
  156. data/rdoc/RubyXL/CT_StyleMatrixReference.html +13 -20
  157. data/rdoc/RubyXL/CT_SupplementalFont.html +13 -20
  158. data/rdoc/RubyXL/CT_SystemColor.html +13 -20
  159. data/rdoc/RubyXL/CT_TextAutonumberBullet.html +13 -20
  160. data/rdoc/RubyXL/CT_TextBlipBullet.html +13 -20
  161. data/rdoc/RubyXL/CT_TextCharBullet.html +13 -20
  162. data/rdoc/RubyXL/CT_TextCharacterProperties.html +13 -20
  163. data/rdoc/RubyXL/CT_TextFont.html +13 -20
  164. data/rdoc/RubyXL/CT_TextListStyle.html +13 -20
  165. data/rdoc/RubyXL/CT_TextNormalAutofit.html +13 -20
  166. data/rdoc/RubyXL/CT_TextParagraphProperties.html +13 -20
  167. data/rdoc/RubyXL/CT_TextSpacing.html +13 -20
  168. data/rdoc/RubyXL/CT_TextTabStop.html +13 -20
  169. data/rdoc/RubyXL/CT_TextTabStopList.html +13 -20
  170. data/rdoc/RubyXL/CT_TileInfoProperties.html +13 -20
  171. data/rdoc/RubyXL/CT_TintEffect.html +13 -20
  172. data/rdoc/RubyXL/CT_Transform2D.html +13 -20
  173. data/rdoc/RubyXL/CT_TransformEffect.html +13 -20
  174. data/rdoc/RubyXL/CT_Vector3D.html +13 -20
  175. data/rdoc/RubyXL/CT_XYAdjustHandle.html +13 -20
  176. data/rdoc/RubyXL/CalculationChain.html +23 -50
  177. data/rdoc/RubyXL/CalculationChainCell.html +13 -20
  178. data/rdoc/RubyXL/CalculationProperties.html +13 -20
  179. data/rdoc/RubyXL/Cell.html +210 -258
  180. data/rdoc/RubyXL/CellConvenienceMethods.html +438 -572
  181. data/rdoc/RubyXL/CellExt.html +13 -20
  182. data/rdoc/RubyXL/CellSmartTag.html +13 -20
  183. data/rdoc/RubyXL/CellSmartTagProperty.html +13 -20
  184. data/rdoc/RubyXL/CellSmartTags.html +13 -20
  185. data/rdoc/RubyXL/CellStyle.html +13 -20
  186. data/rdoc/RubyXL/CellStyleXFs.html +25 -44
  187. data/rdoc/RubyXL/CellStyles.html +25 -44
  188. data/rdoc/RubyXL/CellValue.html +24 -43
  189. data/rdoc/RubyXL/CellWatch.html +13 -20
  190. data/rdoc/RubyXL/CellWatches.html +13 -20
  191. data/rdoc/RubyXL/CellXFs.html +26 -48
  192. data/rdoc/RubyXL/ChartColorsFile.html +12 -26
  193. data/rdoc/RubyXL/ChartFile.html +25 -54
  194. data/rdoc/RubyXL/ChartStyleFile.html +12 -26
  195. data/rdoc/RubyXL/ChartUserShapesFile.html +12 -26
  196. data/rdoc/RubyXL/Chartsheet.html +26 -73
  197. data/rdoc/RubyXL/ChartsheetPageSetup.html +13 -20
  198. data/rdoc/RubyXL/ChartsheetProperties.html +13 -20
  199. data/rdoc/RubyXL/ChartsheetProtection.html +13 -20
  200. data/rdoc/RubyXL/ChartsheetView.html +13 -20
  201. data/rdoc/RubyXL/ChartsheetViews.html +13 -20
  202. data/rdoc/RubyXL/Color.html +24 -48
  203. data/rdoc/RubyXL/ColorConvenienceClasses/HlsColor.html +246 -0
  204. data/rdoc/RubyXL/ColorConvenienceClasses/RgbColor.html +285 -0
  205. data/rdoc/RubyXL/ColorConvenienceClasses.html +91 -0
  206. data/rdoc/RubyXL/ColorConvenienceMethods.html +139 -0
  207. data/rdoc/RubyXL/ColorFilter.html +13 -20
  208. data/rdoc/RubyXL/ColorScale.html +13 -20
  209. data/rdoc/RubyXL/ColorSet.html +13 -20
  210. data/rdoc/RubyXL/Colors.html +13 -20
  211. data/rdoc/RubyXL/ColumnRange.html +76 -91
  212. data/rdoc/RubyXL/ColumnRanges.html +54 -106
  213. data/rdoc/RubyXL/Comment.html +13 -20
  214. data/rdoc/RubyXL/CommentList.html +13 -20
  215. data/rdoc/RubyXL/CommentsFile.html +24 -56
  216. data/rdoc/RubyXL/ConditionalFormatValue.html +13 -20
  217. data/rdoc/RubyXL/ConditionalFormatting.html +13 -20
  218. data/rdoc/RubyXL/ConditionalFormattingRule.html +13 -20
  219. data/rdoc/RubyXL/Connection.html +99 -0
  220. data/rdoc/RubyXL/ConnectionTable.html +99 -0
  221. data/rdoc/RubyXL/ConnectionTables.html +99 -0
  222. data/rdoc/RubyXL/ConnectionTextField.html +99 -0
  223. data/rdoc/RubyXL/ConnectionTextFields.html +99 -0
  224. data/rdoc/RubyXL/Connections.html +149 -0
  225. data/rdoc/RubyXL/ContentTypeDefault.html +12 -18
  226. data/rdoc/RubyXL/ContentTypeOverride.html +12 -18
  227. data/rdoc/RubyXL/ContentTypes.html +35 -72
  228. data/rdoc/RubyXL/ControlPropertiesFile.html +14 -23
  229. data/rdoc/RubyXL/CorePropertiesFile.html +89 -208
  230. data/rdoc/RubyXL/CustomColor.html +13 -20
  231. data/rdoc/RubyXL/CustomColorList.html +13 -20
  232. data/rdoc/RubyXL/CustomFilter.html +13 -20
  233. data/rdoc/RubyXL/CustomFilters.html +13 -20
  234. data/rdoc/RubyXL/CustomGeometry.html +13 -20
  235. data/rdoc/RubyXL/CustomProperties.html +13 -20
  236. data/rdoc/RubyXL/CustomPropertiesFile.html +12 -26
  237. data/rdoc/RubyXL/CustomProperty.html +13 -20
  238. data/rdoc/RubyXL/CustomPropertyFile.html +108 -0
  239. data/rdoc/RubyXL/CustomSheetView.html +13 -20
  240. data/rdoc/RubyXL/CustomSheetViews.html +13 -20
  241. data/rdoc/RubyXL/CustomWorkbookView.html +13 -20
  242. data/rdoc/RubyXL/CustomWorkbookViews.html +13 -20
  243. data/rdoc/RubyXL/CustomXMLFile.html +12 -23
  244. data/rdoc/RubyXL/DXF.html +13 -20
  245. data/rdoc/RubyXL/DXFs.html +13 -20
  246. data/rdoc/RubyXL/DataBar.html +13 -20
  247. data/rdoc/RubyXL/DataConsolidate.html +13 -20
  248. data/rdoc/RubyXL/DataConsolidationReference.html +13 -20
  249. data/rdoc/RubyXL/DataConsolidationReferences.html +13 -20
  250. data/rdoc/RubyXL/DataType.html +11 -40
  251. data/rdoc/RubyXL/DataValidation.html +13 -20
  252. data/rdoc/RubyXL/DataValidations.html +13 -20
  253. data/rdoc/RubyXL/DateGroupItem.html +13 -20
  254. data/rdoc/RubyXL/DefinedName.html +13 -20
  255. data/rdoc/RubyXL/DefinedNameExt.html +13 -20
  256. data/rdoc/RubyXL/DefinedNames.html +13 -20
  257. data/rdoc/RubyXL/DefinedNamesExt.html +13 -20
  258. data/rdoc/RubyXL/DocumentPropertiesFile.html +34 -76
  259. data/rdoc/RubyXL/DrawingFile.html +25 -54
  260. data/rdoc/RubyXL/DynamicFilter.html +13 -20
  261. data/rdoc/RubyXL/EmbeddedControl.html +13 -20
  262. data/rdoc/RubyXL/EmbeddedControls.html +13 -20
  263. data/rdoc/RubyXL/Extension.html +13 -20
  264. data/rdoc/RubyXL/ExtensionStorageArea.html +13 -20
  265. data/rdoc/RubyXL/Extents.html +13 -20
  266. data/rdoc/RubyXL/ExternalBook.html +13 -20
  267. data/rdoc/RubyXL/ExternalLinksFile.html +25 -54
  268. data/rdoc/RubyXL/ExternalReference.html +13 -20
  269. data/rdoc/RubyXL/ExternalReferences.html +13 -20
  270. data/rdoc/RubyXL/ExtraColorSchemeList.html +13 -20
  271. data/rdoc/RubyXL/FieldItem.html +13 -20
  272. data/rdoc/RubyXL/FileRecoveryProperties.html +13 -20
  273. data/rdoc/RubyXL/FileSharing.html +13 -20
  274. data/rdoc/RubyXL/FileVersion.html +13 -20
  275. data/rdoc/RubyXL/Fill.html +25 -44
  276. data/rdoc/RubyXL/Fills.html +25 -44
  277. data/rdoc/RubyXL/FilterContainer.html +13 -20
  278. data/rdoc/RubyXL/FloatNode.html +12 -18
  279. data/rdoc/RubyXL/FloatValue.html +12 -18
  280. data/rdoc/RubyXL/Font.html +28 -64
  281. data/rdoc/RubyXL/FontConvenienceMethods.html +133 -294
  282. data/rdoc/RubyXL/FontScheme.html +13 -20
  283. data/rdoc/RubyXL/Fonts.html +25 -44
  284. data/rdoc/RubyXL/Formula.html +13 -20
  285. data/rdoc/RubyXL/FunctionGroup.html +13 -20
  286. data/rdoc/RubyXL/FunctionGroups.html +13 -20
  287. data/rdoc/RubyXL/GenericStorageObject.html +41 -98
  288. data/rdoc/RubyXL/GradientFill.html +13 -20
  289. data/rdoc/RubyXL/HeaderFooterSettings.html +13 -20
  290. data/rdoc/RubyXL/Hyperlink.html +13 -20
  291. data/rdoc/RubyXL/HyperlinkRelFile.html +12 -23
  292. data/rdoc/RubyXL/Hyperlinks.html +13 -20
  293. data/rdoc/RubyXL/IconFilter.html +13 -20
  294. data/rdoc/RubyXL/IconSet.html +13 -20
  295. data/rdoc/RubyXL/IgnoredError.html +13 -20
  296. data/rdoc/RubyXL/IgnoredErrors.html +13 -20
  297. data/rdoc/RubyXL/IndexedColors.html +13 -20
  298. data/rdoc/RubyXL/InputCells.html +13 -20
  299. data/rdoc/RubyXL/IntegerNode.html +12 -18
  300. data/rdoc/RubyXL/IntegerValue.html +12 -18
  301. data/rdoc/RubyXL/LegacyCell.html +20 -71
  302. data/rdoc/RubyXL/LegacyWorksheet.html +77 -126
  303. data/rdoc/RubyXL/MRUColors.html +13 -20
  304. data/rdoc/RubyXL/MacrosFile.html +12 -26
  305. data/rdoc/RubyXL/MergedCell.html +13 -20
  306. data/rdoc/RubyXL/MergedCells.html +13 -20
  307. data/rdoc/RubyXL/NumFmt.html +13 -20
  308. data/rdoc/RubyXL/NumberFormat.html +25 -44
  309. data/rdoc/RubyXL/NumberFormats.html +25 -50
  310. data/rdoc/RubyXL/OLEObject.html +13 -20
  311. data/rdoc/RubyXL/OLEObjectFile.html +12 -26
  312. data/rdoc/RubyXL/OLEObjects.html +13 -20
  313. data/rdoc/RubyXL/OLESize.html +13 -20
  314. data/rdoc/RubyXL/OOXMLContainerObject.html +72 -157
  315. data/rdoc/RubyXL/OOXMLIgnored.html +32 -62
  316. data/rdoc/RubyXL/OOXMLObject.html +15 -26
  317. data/rdoc/RubyXL/OOXMLObjectClassMethods.html +126 -203
  318. data/rdoc/RubyXL/OOXMLObjectInstanceMethods.html +104 -226
  319. data/rdoc/RubyXL/OOXMLRelationshipsFile.html +109 -242
  320. data/rdoc/RubyXL/OOXMLTopLevelObject.html +67 -154
  321. data/rdoc/RubyXL/OdbcOleDbProperties.html +99 -0
  322. data/rdoc/RubyXL/Offset.html +13 -20
  323. data/rdoc/RubyXL/OlapProperties.html +99 -0
  324. data/rdoc/RubyXL/OleItem.html +99 -0
  325. data/rdoc/RubyXL/OleItems.html +99 -0
  326. data/rdoc/RubyXL/OleLink.html +99 -0
  327. data/rdoc/RubyXL/OutlineProperties.html +13 -20
  328. data/rdoc/RubyXL/PageMargins.html +13 -20
  329. data/rdoc/RubyXL/PageSetup.html +13 -20
  330. data/rdoc/RubyXL/PageSetupProperties.html +13 -20
  331. data/rdoc/RubyXL/Pane.html +13 -20
  332. data/rdoc/RubyXL/Parser.html +35 -65
  333. data/rdoc/RubyXL/PatternFill.html +13 -20
  334. data/rdoc/RubyXL/PersonMetadata.html +108 -0
  335. data/rdoc/RubyXL/PhoneticProperties.html +13 -20
  336. data/rdoc/RubyXL/PhoneticRun.html +13 -20
  337. data/rdoc/RubyXL/PivotArea.html +13 -20
  338. data/rdoc/RubyXL/PivotCache.html +13 -20
  339. data/rdoc/RubyXL/PivotCacheDefinitionFile.html +14 -31
  340. data/rdoc/RubyXL/PivotCacheRecordsFile.html +12 -26
  341. data/rdoc/RubyXL/PivotCaches.html +13 -20
  342. data/rdoc/RubyXL/PivotReference.html +13 -20
  343. data/rdoc/RubyXL/PivotReferences.html +13 -20
  344. data/rdoc/RubyXL/PivotTableFile.html +14 -31
  345. data/rdoc/RubyXL/PivotTableSelection.html +13 -20
  346. data/rdoc/RubyXL/PresetGeometry.html +13 -20
  347. data/rdoc/RubyXL/PrintOptions.html +13 -20
  348. data/rdoc/RubyXL/PrinterSettingsFile.html +12 -26
  349. data/rdoc/RubyXL/ProtectedRange.html +13 -20
  350. data/rdoc/RubyXL/ProtectedRanges.html +13 -20
  351. data/rdoc/RubyXL/Protection.html +13 -20
  352. data/rdoc/RubyXL/QueryParameter.html +99 -0
  353. data/rdoc/RubyXL/QueryParameters.html +99 -0
  354. data/rdoc/RubyXL/QueryTable.html +157 -0
  355. data/rdoc/RubyXL/QueryTableDeletedField.html +99 -0
  356. data/rdoc/RubyXL/QueryTableDeletedFields.html +99 -0
  357. data/rdoc/RubyXL/QueryTableField.html +99 -0
  358. data/rdoc/RubyXL/QueryTableFields.html +99 -0
  359. data/rdoc/RubyXL/QueryTableRefresh.html +99 -0
  360. data/rdoc/RubyXL/RID.html +12 -18
  361. data/rdoc/RubyXL/RawOOXML.html +33 -69
  362. data/rdoc/RubyXL/Reference.html +156 -286
  363. data/rdoc/RubyXL/Relationship.html +12 -18
  364. data/rdoc/RubyXL/RelationshipSupport/ClassMehods.html +20 -37
  365. data/rdoc/RubyXL/RelationshipSupport.html +62 -145
  366. data/rdoc/RubyXL/RevisionPointer.html +13 -23
  367. data/rdoc/RubyXL/RichText.html +27 -45
  368. data/rdoc/RubyXL/RichTextRun.html +24 -43
  369. data/rdoc/RubyXL/Row.html +88 -205
  370. data/rdoc/RubyXL/RowExt.html +13 -20
  371. data/rdoc/RubyXL/RunProperties.html +13 -20
  372. data/rdoc/RubyXL/Scenario.html +13 -20
  373. data/rdoc/RubyXL/Scenarios.html +13 -20
  374. data/rdoc/RubyXL/Selection.html +23 -42
  375. data/rdoc/RubyXL/ShapeGuide.html +13 -20
  376. data/rdoc/RubyXL/ShapeTextRectangle.html +13 -20
  377. data/rdoc/RubyXL/SharedStringsTable.html +81 -177
  378. data/rdoc/RubyXL/Sheet.html +13 -20
  379. data/rdoc/RubyXL/SheetCalculationProperties.html +13 -20
  380. data/rdoc/RubyXL/SheetData.html +32 -62
  381. data/rdoc/RubyXL/SheetDataExt.html +13 -20
  382. data/rdoc/RubyXL/SheetDataSet.html +13 -20
  383. data/rdoc/RubyXL/SheetMetadata.html +108 -0
  384. data/rdoc/RubyXL/SheetName.html +13 -20
  385. data/rdoc/RubyXL/SheetNames.html +13 -20
  386. data/rdoc/RubyXL/Sheets.html +13 -20
  387. data/rdoc/RubyXL/SlicerCacheFile.html +12 -26
  388. data/rdoc/RubyXL/SlicerFile.html +12 -26
  389. data/rdoc/RubyXL/SmartTagProperties.html +13 -20
  390. data/rdoc/RubyXL/SmartTagType.html +13 -20
  391. data/rdoc/RubyXL/SmartTagTypes.html +13 -20
  392. data/rdoc/RubyXL/SmartTags.html +13 -20
  393. data/rdoc/RubyXL/SortCondition.html +13 -20
  394. data/rdoc/RubyXL/SortState.html +13 -20
  395. data/rdoc/RubyXL/Sqref.html +33 -63
  396. data/rdoc/RubyXL/Stop.html +13 -20
  397. data/rdoc/RubyXL/StringNode.html +12 -18
  398. data/rdoc/RubyXL/StringNodeW3C.html +33 -63
  399. data/rdoc/RubyXL/StringValue.html +12 -18
  400. data/rdoc/RubyXL/Stylesheet.html +65 -138
  401. data/rdoc/RubyXL/TableFile.html +12 -26
  402. data/rdoc/RubyXL/TableParts.html +12 -18
  403. data/rdoc/RubyXL/TableStyle.html +13 -20
  404. data/rdoc/RubyXL/TableStyles.html +13 -20
  405. data/rdoc/RubyXL/Text.html +35 -76
  406. data/rdoc/RubyXL/TextImportSettings.html +99 -0
  407. data/rdoc/RubyXL/Theme.html +72 -72
  408. data/rdoc/RubyXL/ThemeElements.html +13 -20
  409. data/rdoc/RubyXL/ThumbnailFile.html +12 -26
  410. data/rdoc/RubyXL/Top10.html +13 -20
  411. data/rdoc/RubyXL/VMLDrawingFile.html +15 -33
  412. data/rdoc/RubyXL/Variant.html +13 -20
  413. data/rdoc/RubyXL/Vector.html +24 -43
  414. data/rdoc/RubyXL/VectorValue.html +12 -18
  415. data/rdoc/RubyXL/VisualProperties.html +13 -20
  416. data/rdoc/RubyXL/WebPublishObject.html +13 -20
  417. data/rdoc/RubyXL/WebPublishObjects.html +13 -20
  418. data/rdoc/RubyXL/WebPublishingItem.html +13 -20
  419. data/rdoc/RubyXL/WebPublishingItems.html +13 -20
  420. data/rdoc/RubyXL/WebPublishingProperties.html +13 -20
  421. data/rdoc/RubyXL/WebQueryProperties.html +99 -0
  422. data/rdoc/RubyXL/Workbook.html +581 -266
  423. data/rdoc/RubyXL/WorkbookConvenienceMethods.html +226 -951
  424. data/rdoc/RubyXL/WorkbookProperties.html +13 -20
  425. data/rdoc/RubyXL/WorkbookProtection.html +13 -20
  426. data/rdoc/RubyXL/WorkbookRoot.html +58 -135
  427. data/rdoc/RubyXL/WorkbookView.html +13 -20
  428. data/rdoc/RubyXL/WorkbookViews.html +13 -20
  429. data/rdoc/RubyXL/Worksheet.html +122 -137
  430. data/rdoc/RubyXL/WorksheetConvenienceMethods.html +717 -1373
  431. data/rdoc/RubyXL/WorksheetDimensions.html +13 -20
  432. data/rdoc/RubyXL/WorksheetFormatProperties.html +12 -18
  433. data/rdoc/RubyXL/WorksheetProperties.html +13 -20
  434. data/rdoc/RubyXL/WorksheetProtection.html +13 -20
  435. data/rdoc/RubyXL/WorksheetView.html +13 -20
  436. data/rdoc/RubyXL/WorksheetViews.html +13 -20
  437. data/rdoc/RubyXL/XF.html +13 -20
  438. data/rdoc/RubyXL.html +46 -306
  439. data/rdoc/created.rid +45 -38
  440. data/rdoc/css/rdoc.css +109 -12
  441. data/rdoc/fonts/SourceCodePro-Bold.ttf +0 -0
  442. data/rdoc/fonts/SourceCodePro-Regular.ttf +0 -0
  443. data/rdoc/index.html +403 -726
  444. data/rdoc/js/darkfish.js +33 -97
  445. data/rdoc/js/navigation.js +12 -49
  446. data/rdoc/js/navigation.js.gz +0 -0
  447. data/rdoc/js/search.js +35 -34
  448. data/rdoc/js/search_index.js +1 -1
  449. data/rdoc/js/search_index.js.gz +0 -0
  450. data/rdoc/js/searcher.js +6 -6
  451. data/rdoc/js/searcher.js.gz +0 -0
  452. data/rdoc/table_of_contents.html +287 -45
  453. data/rubyXL.gemspec +77 -43
  454. data/spec/lib/cell_spec.rb +119 -6
  455. data/spec/lib/color_spec.rb +9 -1
  456. data/spec/lib/parser_spec.rb +28 -28
  457. data/spec/lib/reference_spec.rb +41 -5
  458. data/spec/lib/rgb_color_spec.rb +29 -0
  459. data/spec/lib/stylesheet_spec.rb +10 -11
  460. data/spec/lib/text_spec.rb +4 -6
  461. data/spec/lib/workbook_spec.rb +31 -8
  462. data/spec/lib/worksheet_spec.rb +886 -480
  463. data/spec/spec_helper.rb +2 -0
  464. data/test/test_parse_write.rb +15 -15
  465. metadata +76 -10
  466. data/rdoc/js/jquery.js +0 -4
@@ -1,457 +1,470 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
4
+ require 'rubyXL/convenience_methods/worksheet'
2
5
 
3
- describe RubyXL::Worksheet do
4
- before do
5
- @workbook = RubyXL::Workbook.new
6
- @worksheet = @workbook.add_worksheet
6
+ SKIP_ROW_COL = 3
7
7
 
8
- (0..10).each do |i|
9
- (0..10).each do |j|
10
- @worksheet.add_cell(i, j, "#{i}:#{j}", "F#{i}:#{j}")
8
+ describe RubyXL::Worksheet do
9
+ subject do
10
+ workbook = RubyXL::Workbook.new
11
+ worksheet = workbook.add_worksheet
12
+
13
+ 11.times do |y|
14
+ 11.times do |x|
15
+ next if y == SKIP_ROW_COL || x == SKIP_ROW_COL # Skip some rows/cells
16
+ worksheet.add_cell(y, x, "#{x}:#{y}", "F#{x}:#{y}")
11
17
  end
12
18
  end
13
19
 
14
- @old_cell = @worksheet[0][0]
15
- @old_cell_value = @worksheet[0][0].value.to_s
16
- @old_cell_formula = @worksheet[0][0].formula.expression.to_s
20
+ worksheet
21
+ end
22
+
23
+ describe 'addressing cells' do
24
+ it 'should be able to address cells by row and column indices' do
25
+ expect(subject[2][4].value).to eq('4:2')
26
+ end
27
+
28
+ it 'should be able to address cells by reference' do
29
+ expect(subject.cell_at('B5').value).to eq('1:4')
30
+ end
17
31
  end
18
32
 
19
33
  describe '.change_row_fill' do
20
34
  it 'should raise error if hex color code not passed' do
21
35
  expect {
22
- @worksheet.change_row_fill(0, 'G')
36
+ subject.change_row_fill(0, 'G')
23
37
  }.to raise_error(RuntimeError)
24
38
  end
25
39
 
26
40
  it 'should raise error if hex color code includes # character' do
27
41
  expect {
28
- @worksheet.change_row_fill(3, '#FFF000')
42
+ subject.change_row_fill(3, '#FFF000')
29
43
  }.to raise_error(RuntimeError)
30
44
  end
31
45
 
32
46
  it 'should make row and cell fill colors equal hex color code passed' do
33
- @worksheet.change_row_fill(0, '111111')
34
- expect(@worksheet.get_row_fill(0)).to eq('111111')
35
- expect(@worksheet[0][5].fill_color).to eq('111111')
47
+ subject.change_row_fill(0, '111111')
48
+ expect(subject.get_row_fill(0)).to eq('111111')
49
+ expect(subject[0][5].fill_color).to eq('111111')
36
50
  end
37
51
 
38
52
  it 'should cause error if a negative argument is passed in' do
39
53
  expect {
40
- @worksheet.change_row_fill(-1, '111111')
54
+ subject.change_row_fill(-1, '111111')
41
55
  }.to raise_error(RuntimeError)
42
56
  end
43
57
 
44
58
  it 'should create a new row if it did not exist before' do
45
- expect(@worksheet.sheet_data[11]).to be_nil
46
- @worksheet.change_row_fill(11, '111111')
47
- expect(@worksheet.sheet_data[11]).to be_a(RubyXL::Row)
48
- expect(@worksheet.get_row_fill(11)).to eq('111111')
59
+ expect(subject.sheet_data[11]).to be_nil
60
+ subject.change_row_fill(11, '111111')
61
+ expect(subject.sheet_data[11]).to be_a(RubyXL::Row)
62
+ expect(subject.get_row_fill(11)).to eq('111111')
49
63
  end
50
64
  end
51
65
 
52
66
  describe '.change_row_font_name' do
53
67
  it 'should make row and cell font names equal font name passed' do
54
- @worksheet.change_row_font_name(0, 'Arial')
55
- expect(@worksheet.get_row_font_name(0)).to eq('Arial')
56
- expect(@worksheet[0][5].font_name).to eq('Arial')
68
+ subject.change_row_font_name(0, 'Arial')
69
+ expect(subject.get_row_font_name(0)).to eq('Arial')
70
+ expect(subject[0][5].font_name).to eq('Arial')
57
71
  end
58
72
 
59
73
  it 'should cause error if a negative argument is passed in' do
60
74
  expect {
61
- @worksheet.change_row_font_name(-1, 'Arial')
75
+ subject.change_row_font_name(-1, 'Arial')
62
76
  }.to raise_error(RuntimeError)
63
77
  end
64
78
 
65
79
  it 'should create a new row if it did not exist before' do
66
- expect(@worksheet.sheet_data[11]).to be_nil
67
- @worksheet.change_row_font_name(11, 'Arial')
68
- expect(@worksheet.sheet_data[11]).to be_a(RubyXL::Row)
69
- expect(@worksheet.get_row_font_name(11)).to eq("Arial")
80
+ expect(subject.sheet_data[11]).to be_nil
81
+ subject.change_row_font_name(11, 'Arial')
82
+ expect(subject.sheet_data[11]).to be_a(RubyXL::Row)
83
+ expect(subject.get_row_font_name(11)).to eq('Arial')
70
84
  end
71
85
  end
72
86
 
73
87
  describe '.change_row_font_size' do
74
88
  it 'should make row and cell font sizes equal font number passed' do
75
- @worksheet.change_row_font_size(0, 20)
76
- expect(@worksheet.get_row_font_size(0)).to eq(20)
77
- expect(@worksheet[0][5].font_size).to eq(20)
89
+ subject.change_row_font_size(0, 20)
90
+ expect(subject.get_row_font_size(0)).to eq(20)
91
+ expect(subject[0][5].font_size).to eq(20)
78
92
  end
79
93
 
80
94
  it 'should cause an error if a string passed' do
81
95
  expect {
82
- @worksheet.change_row_font_size(0, '20')
96
+ subject.change_row_font_size(0, '20')
83
97
  }.to raise_error(RuntimeError)
84
98
  end
85
99
 
86
100
  it 'should cause error if a negative argument is passed in' do
87
101
  expect {
88
- @worksheet.change_row_font_size(-1,20)
102
+ subject.change_row_font_size(-1, 20)
89
103
  }.to raise_error(RuntimeError)
90
104
  end
91
105
 
92
106
  it 'should create a new row if it did not exist before' do
93
- expect(@worksheet.sheet_data[11]).to be_nil
94
- @worksheet.change_row_font_size(11,20)
95
- expect(@worksheet.sheet_data[11]).to be_a(RubyXL::Row)
96
- expect(@worksheet.get_row_font_size(11)).to eq(20)
107
+ expect(subject.sheet_data[11]).to be_nil
108
+ subject.change_row_font_size(11, 20)
109
+ expect(subject.sheet_data[11]).to be_a(RubyXL::Row)
110
+ expect(subject.get_row_font_size(11)).to eq(20)
97
111
  end
98
112
  end
99
113
 
100
114
  describe '.change_row_font_color' do
101
115
  it 'should make row and cell font colors equal to font color passed' do
102
- @worksheet.change_row_font_color(0, '0f0f0f')
103
- expect(@worksheet.get_row_font_color(0)).to eq('0f0f0f')
104
- expect(@worksheet[0][5].font_color).to eq('0f0f0f')
116
+ subject.change_row_font_color(0, '0f0f0f')
117
+ expect(subject.get_row_font_color(0)).to eq('0f0f0f')
118
+ expect(subject[0][5].font_color).to eq('0f0f0f')
105
119
  end
106
120
 
107
121
  it 'should raise error if hex color code not passed' do
108
122
  expect {
109
- @worksheet.change_row_font_color(0, 'G')
123
+ subject.change_row_font_color(0, 'G')
110
124
  }.to raise_error(RuntimeError)
111
125
  end
112
126
 
113
127
  it 'should raise error if hex color code includes # character' do
114
128
  expect {
115
- @worksheet.change_row_font_color(3, '#FFF000')
129
+ subject.change_row_font_color(3, '#FFF000')
116
130
  }.to raise_error(RuntimeError)
117
131
  end
118
132
 
119
133
  it 'should cause error if a negative argument is passed in' do
120
134
  expect {
121
- @worksheet.change_row_font_color(-1, '0f0f0f')
135
+ subject.change_row_font_color(-1, '0f0f0f')
122
136
  }.to raise_error(RuntimeError)
123
137
  end
124
138
 
125
139
  it 'should create a new row if it did not exist before' do
126
- expect(@worksheet.sheet_data[11]).to be_nil
127
- @worksheet.change_row_font_color(11, '0f0f0f')
128
- expect(@worksheet.sheet_data[11]).to be_a(RubyXL::Row)
129
- expect(@worksheet.get_row_font_color(11)).to eq('0f0f0f')
140
+ expect(subject.sheet_data[11]).to be_nil
141
+ subject.change_row_font_color(11, '0f0f0f')
142
+ expect(subject.sheet_data[11]).to be_a(RubyXL::Row)
143
+ expect(subject.get_row_font_color(11)).to eq('0f0f0f')
130
144
  end
131
145
  end
132
146
 
133
147
  describe '.change_row_italics' do
134
148
  it 'should make row and cell fonts italicized when true is passed' do
135
- @worksheet.change_row_italics(0, true)
136
- expect(@worksheet.is_row_italicized(0)).to eq(true)
137
- expect(@worksheet[0][5].is_italicized).to eq(true)
149
+ subject.change_row_italics(0, true)
150
+ expect(subject.is_row_italicized(0)).to eq(true)
151
+ expect(subject[0][5].is_italicized).to eq(true)
138
152
  end
139
153
 
140
154
  it 'should cause error if a negative argument is passed in' do
141
155
  expect {
142
- @worksheet.change_row_italics(-1, false)
156
+ subject.change_row_italics(-1, false)
143
157
  }.to raise_error(RuntimeError)
144
158
  end
145
159
 
146
160
  it 'should create a new row if it did not exist before' do
147
- expect(@worksheet.sheet_data[11]).to be_nil
148
- @worksheet.change_row_italics(11,true)
149
- expect(@worksheet.sheet_data[11]).to be_a(RubyXL::Row)
150
- expect(@worksheet.is_row_italicized(11)).to eq(true)
161
+ expect(subject.sheet_data[11]).to be_nil
162
+ subject.change_row_italics(11, true)
163
+ expect(subject.sheet_data[11]).to be_a(RubyXL::Row)
164
+ expect(subject.is_row_italicized(11)).to eq(true)
151
165
  end
152
166
  end
153
167
 
154
168
  describe '.change_row_bold' do
155
169
  it 'should make row and cell fonts bolded when true is passed' do
156
- @worksheet.change_row_bold(0, true)
157
- expect(@worksheet.is_row_bolded(0)).to eq(true)
158
- expect(@worksheet[0][5].is_bolded).to eq(true)
170
+ subject.change_row_bold(0, true)
171
+ expect(subject.is_row_bolded(0)).to eq(true)
172
+ expect(subject[0][5].is_bolded).to eq(true)
159
173
  end
160
174
 
161
175
  it 'should cause error if a negative argument is passed in' do
162
176
  expect {
163
- @worksheet.change_row_bold(-1, false)
177
+ subject.change_row_bold(-1, false)
164
178
  }.to raise_error(RuntimeError)
165
179
  end
166
180
 
167
181
  it 'should create a new row if it did not exist before' do
168
- expect(@worksheet.sheet_data[11]).to be_nil
169
- @worksheet.change_row_bold(11, true)
170
- expect(@worksheet.sheet_data[11]).to be_a(RubyXL::Row)
171
- expect(@worksheet.is_row_bolded(11)).to eq(true)
182
+ expect(subject.sheet_data[11]).to be_nil
183
+ subject.change_row_bold(11, true)
184
+ expect(subject.sheet_data[11]).to be_a(RubyXL::Row)
185
+ expect(subject.is_row_bolded(11)).to eq(true)
172
186
  end
173
187
  end
174
188
 
175
189
  describe '.change_row_underline' do
176
190
  it 'should make row and cell fonts underlined when true is passed' do
177
- @worksheet.change_row_underline(0, true)
178
- expect(@worksheet.is_row_underlined(0)).to eq(true)
179
- expect(@worksheet[0][5].is_underlined).to eq(true)
191
+ subject.change_row_underline(0, true)
192
+ expect(subject.is_row_underlined(0)).to eq(true)
193
+ expect(subject[0][5].is_underlined).to eq(true)
180
194
  end
181
195
 
182
196
  it 'should cause error if a negative argument is passed in' do
183
197
  expect {
184
- @worksheet.change_row_underline(-1, false)
198
+ subject.change_row_underline(-1, false)
185
199
  }.to raise_error(RuntimeError)
186
200
  end
187
201
 
188
202
  it 'should create a new row if it did not exist before' do
189
- expect(@worksheet.sheet_data[11]).to be_nil
190
- @worksheet.change_row_underline(11,true)
191
- expect(@worksheet.sheet_data[11]).to be_a(RubyXL::Row)
192
- expect(@worksheet.is_row_underlined(11)).to eq(true)
203
+ expect(subject.sheet_data[11]).to be_nil
204
+ subject.change_row_underline(11, true)
205
+ expect(subject.sheet_data[11]).to be_a(RubyXL::Row)
206
+ expect(subject.is_row_underlined(11)).to eq(true)
193
207
  end
194
208
  end
195
209
 
196
210
  describe '.change_row_strikethrough' do
197
211
  it 'should make row and cell fonts struckthrough when true is passed' do
198
- @worksheet.change_row_strikethrough(0, true)
199
- expect(@worksheet.is_row_struckthrough(0)).to eq(true)
200
- expect(@worksheet[0][5].is_struckthrough).to eq(true)
212
+ subject.change_row_strikethrough(0, true)
213
+ expect(subject.is_row_struckthrough(0)).to eq(true)
214
+ expect(subject[0][5].is_struckthrough).to eq(true)
201
215
  end
202
216
 
203
217
  it 'should cause error if a negative argument is passed in' do
204
218
  expect {
205
- @worksheet.change_row_strikethrough(-1, false)
219
+ subject.change_row_strikethrough(-1, false)
206
220
  }.to raise_error(RuntimeError)
207
221
  end
208
222
 
209
223
  it 'should create a new row if it did not exist before' do
210
- expect(@worksheet.sheet_data[11]).to be_nil
211
- @worksheet.change_row_strikethrough(11,true)
212
- expect(@worksheet.sheet_data[11]).to be_a(RubyXL::Row)
213
- expect(@worksheet.is_row_struckthrough(11)).to eq(true)
224
+ expect(subject.sheet_data[11]).to be_nil
225
+ subject.change_row_strikethrough(11, true)
226
+ expect(subject.sheet_data[11]).to be_a(RubyXL::Row)
227
+ expect(subject.is_row_struckthrough(11)).to eq(true)
214
228
  end
215
229
  end
216
230
 
217
231
  describe '.change_row_height' do
218
232
  it 'should make row height match number which is passed' do
219
- @worksheet.change_row_height(0,30.0002)
220
- expect(@worksheet.get_row_height(0)).to eq(30.0002)
233
+ subject.change_row_height(0, 30.0002)
234
+ expect(subject.get_row_height(0)).to eq(30.0002)
221
235
  end
222
236
 
223
237
  it 'should make row height a number equivalent of the string passed if it is a string which is a number' do
224
- @worksheet.change_row_height(0, 30.0002)
225
- expect(@worksheet.get_row_height(0)).to eq(30.0002)
238
+ subject.change_row_height(0, 30.0002)
239
+ expect(subject.get_row_height(0)).to eq(30.0002)
226
240
  end
227
241
 
228
242
  it 'should cause error if a negative argument is passed in' do
229
243
  expect {
230
- @worksheet.change_row_height(-1, 30)
244
+ subject.change_row_height(-1, 30)
231
245
  }.to raise_error(RuntimeError)
232
246
  end
233
247
 
234
248
  it 'should create a new row if it did not exist before' do
235
- expect(@worksheet.sheet_data[11]).to be_nil
236
- @worksheet.change_row_height(11, 30)
237
- expect(@worksheet.sheet_data[11]).to be_a(RubyXL::Row)
238
- expect(@worksheet.get_row_height(11)).to eq(30)
249
+ expect(subject.sheet_data[11]).to be_nil
250
+ subject.change_row_height(11, 30)
251
+ expect(subject.sheet_data[11]).to be_a(RubyXL::Row)
252
+ expect(subject.get_row_height(11)).to eq(30)
239
253
  end
240
254
  end
241
255
 
242
256
  describe '.change_row_horizontal_alignment' do
243
257
  it 'should cause row and cells to horizontally align as specified by the passed in string' do
244
- @worksheet.change_row_horizontal_alignment(0, 'center')
245
- expect(@worksheet.get_row_alignment(0, true)).to eq('center')
246
- expect(@worksheet[0][5].horizontal_alignment).to eq('center')
258
+ subject.change_row_horizontal_alignment(0, 'center')
259
+ expect(subject.get_row_alignment(0, true)).to eq('center')
260
+ expect(subject[0][5].horizontal_alignment).to eq('center')
247
261
  end
248
262
 
249
263
  it 'should cause error if a negative argument is passed in' do
250
264
  expect {
251
- @worksheet.change_row_horizontal_alignment(-1, 'center')
265
+ subject.change_row_horizontal_alignment(-1, 'center')
252
266
  }.to raise_error(RuntimeError)
253
267
  end
254
268
 
255
269
  it 'should create a new row if it did not exist before' do
256
- expect(@worksheet.sheet_data[11]).to be_nil
257
- @worksheet.change_row_horizontal_alignment(11, 'center')
258
- expect(@worksheet.sheet_data[11]).to be_a(RubyXL::Row)
259
- expect(@worksheet.get_row_alignment(11, true)).to eq('center')
270
+ expect(subject.sheet_data[11]).to be_nil
271
+ subject.change_row_horizontal_alignment(11, 'center')
272
+ expect(subject.sheet_data[11]).to be_a(RubyXL::Row)
273
+ expect(subject.get_row_alignment(11, true)).to eq('center')
260
274
  end
261
275
  end
262
276
 
263
277
  describe '.change_row_vertical_alignment' do
264
278
  it 'should cause row and cells to vertically align as specified by the passed in string' do
265
- @worksheet.change_row_vertical_alignment(0, 'center')
266
- expect(@worksheet.get_row_alignment(0, false)).to eq('center')
267
- expect(@worksheet[0][5].vertical_alignment).to eq('center')
279
+ subject.change_row_vertical_alignment(0, 'center')
280
+ expect(subject.get_row_alignment(0, false)).to eq('center')
281
+ expect(subject[0][5].vertical_alignment).to eq('center')
268
282
  end
269
283
 
270
284
  it 'should cause error if a negative argument is passed in' do
271
285
  expect {
272
- @worksheet.change_row_vertical_alignment(-1, 'center')
286
+ subject.change_row_vertical_alignment(-1, 'center')
273
287
  }.to raise_error(RuntimeError)
274
288
  end
275
289
 
276
290
  it 'should create a new row if it did not exist before' do
277
- expect(@worksheet.sheet_data[11]).to be_nil
278
- @worksheet.change_row_vertical_alignment(11, 'center')
279
- expect(@worksheet.sheet_data[11]).to be_a(RubyXL::Row)
280
- expect(@worksheet.get_row_alignment(11, false)).to eq('center')
291
+ expect(subject.sheet_data[11]).to be_nil
292
+ subject.change_row_vertical_alignment(11, 'center')
293
+ expect(subject.sheet_data[11]).to be_a(RubyXL::Row)
294
+ expect(subject.get_row_alignment(11, false)).to eq('center')
281
295
  end
282
296
  end
283
297
 
284
298
  describe '.change_row_border' do
285
-
286
299
  it 'should cause error if a negative argument is passed in' do
287
300
  expect {
288
- @worksheet.change_row_border(-1, :left, 'thin')
301
+ subject.change_row_border(-1, :left, 'thin')
289
302
  }.to raise_error(RuntimeError)
290
303
  end
291
304
 
292
305
  it 'should create a new row if it did not exist before' do
293
- expect(@worksheet.sheet_data[11]).to be_nil
294
- @worksheet.change_row_border(11, :left, 'thin')
295
- expect(@worksheet.sheet_data[11]).to be_a(RubyXL::Row)
296
- expect(@worksheet.get_row_border(11, :left)).to eq('thin')
306
+ expect(subject.sheet_data[11]).to be_nil
307
+ subject.change_row_border(11, :left, 'thin')
308
+ expect(subject.sheet_data[11]).to be_a(RubyXL::Row)
309
+ expect(subject.get_row_border(11, :left)).to eq('thin')
297
310
  end
298
311
 
299
312
  it 'should cause row and cells to have border at top of specified weight' do
300
- @worksheet.change_row_border(0, :top, 'thin')
301
- expect(@worksheet.get_row_border(0, :top)).to eq('thin')
302
- expect(@worksheet[0][5].get_border(:top)).to eq('thin')
313
+ subject.change_row_border(0, :top, 'thin')
314
+ expect(subject.get_row_border(0, :top)).to eq('thin')
315
+ expect(subject[0][5].get_border(:top)).to eq('thin')
303
316
  end
304
317
 
305
318
  it 'should cause row and cells to have border at left of specified weight' do
306
- @worksheet.change_row_border(0, :left, 'thin')
307
- expect(@worksheet.get_row_border(0, :left)).to eq('thin')
308
- expect(@worksheet[0][5].get_border(:left)).to eq('thin')
319
+ subject.change_row_border(0, :left, 'thin')
320
+ expect(subject.get_row_border(0, :left)).to eq('thin')
321
+ expect(subject[0][5].get_border(:left)).to eq('thin')
309
322
  end
310
323
 
311
324
  it 'should cause row and cells to have border at right of specified weight' do
312
- @worksheet.change_row_border(0, :right, 'thin')
313
- expect(@worksheet.get_row_border(0, :right)).to eq('thin')
314
- expect(@worksheet[0][5].get_border(:right)).to eq('thin')
325
+ subject.change_row_border(0, :right, 'thin')
326
+ expect(subject.get_row_border(0, :right)).to eq('thin')
327
+ expect(subject[0][5].get_border(:right)).to eq('thin')
315
328
  end
316
329
 
317
330
  it 'should cause row to have border at bottom of specified weight' do
318
- @worksheet.change_row_border(0, :bottom, 'thin')
319
- expect(@worksheet.get_row_border(0, :bottom)).to eq('thin')
320
- expect(@worksheet[0][5].get_border(:bottom)).to eq('thin')
331
+ subject.change_row_border(0, :bottom, 'thin')
332
+ expect(subject.get_row_border(0, :bottom)).to eq('thin')
333
+ expect(subject[0][5].get_border(:bottom)).to eq('thin')
321
334
  end
322
335
 
323
336
  it 'should cause row to have border at diagonal of specified weight' do
324
- @worksheet.change_row_border(0, :diagonal, 'thin')
325
- expect(@worksheet.get_row_border(0, :diagonal)).to eq('thin')
326
- expect(@worksheet[0][5].get_border(:diagonal)).to eq('thin')
337
+ subject.change_row_border(0, :diagonal, 'thin')
338
+ expect(subject.get_row_border(0, :diagonal)).to eq('thin')
339
+ expect(subject[0][5].get_border(:diagonal)).to eq('thin')
327
340
  end
328
341
  end
329
342
 
330
343
  describe '.change_column_font_name' do
331
344
  it 'should cause column and cell font names to match string passed in' do
332
- @worksheet.change_column_font_name(0, 'Arial')
333
- expect(@worksheet.get_column_font_name(0)).to eq('Arial')
334
- expect(@worksheet[5][0].font_name).to eq('Arial')
345
+ subject.change_column_font_name(0, 'Arial')
346
+ expect(subject.get_column_font_name(0)).to eq('Arial')
347
+ expect(subject[5][0].font_name).to eq('Arial')
335
348
  end
336
349
 
337
350
  it 'should cause error if a negative argument is passed in' do
338
351
  expect {
339
- @worksheet.change_column_font_name(-1, 'Arial')
352
+ subject.change_column_font_name(-1, 'Arial')
340
353
  }.to raise_error(RuntimeError)
341
354
  end
342
355
  end
343
356
 
344
357
  describe '.change_column_font_size' do
345
358
  it 'should make column and cell font sizes equal font number passed' do
346
- @worksheet.change_column_font_size(0, 20)
347
- expect(@worksheet.get_column_font_size(0)).to eq(20)
348
- expect(@worksheet[5][0].font_size).to eq(20)
359
+ subject.change_column_font_size(0, 20)
360
+ expect(subject.get_column_font_size(0)).to eq(20)
361
+ expect(subject[5][0].font_size).to eq(20)
349
362
  end
350
363
 
351
364
  it 'should cause an error if a string passed' do
352
365
  expect {
353
- @worksheet.change_column_font_size(0, '20')
366
+ subject.change_column_font_size(0, '20')
354
367
  }.to raise_error(RuntimeError)
355
368
  end
356
369
 
357
370
  it 'should cause error if a negative argument is passed in' do
358
371
  expect {
359
- @worksheet.change_column_font_size(-1, 20)
372
+ subject.change_column_font_size(-1, 20)
360
373
  }.to raise_error(RuntimeError)
361
374
  end
362
375
  end
363
376
 
364
377
  describe '.change_column_font_color' do
365
378
  it 'should make column and cell font colors equal to font color passed' do
366
- @worksheet.change_column_font_color(0, '0f0f0f')
367
- expect(@worksheet.get_column_font_color(0)).to eq('0f0f0f')
368
- expect(@worksheet[5][0].font_color).to eq('0f0f0f')
379
+ subject.change_column_font_color(0, '0f0f0f')
380
+ expect(subject.get_column_font_color(0)).to eq('0f0f0f')
381
+ expect(subject[5][0].font_color).to eq('0f0f0f')
369
382
  end
370
383
 
371
384
  it 'should raise error if hex color code not passed' do
372
385
  expect {
373
- @worksheet.change_column_font_color(0, 'G')
386
+ subject.change_column_font_color(0, 'G')
374
387
  }.to raise_error(RuntimeError)
375
388
  end
376
389
 
377
390
  it 'should raise error if hex color code includes # character' do
378
391
  expect {
379
- @worksheet.change_column_font_color(0, '#FFF000')
392
+ subject.change_column_font_color(0, '#FFF000')
380
393
  }.to raise_error(RuntimeError)
381
394
  end
382
395
 
383
396
  it 'should cause error if a negative argument is passed in' do
384
397
  expect {
385
- @worksheet.change_column_font_color(-1, '0f0f0f')
398
+ subject.change_column_font_color(-1, '0f0f0f')
386
399
  }.to raise_error(RuntimeError)
387
400
  end
388
401
  end
389
402
 
390
403
  describe '.change_column_italics' do
391
404
  it 'should make column and cell fonts italicized when true is passed' do
392
- @worksheet.change_column_italics(0, true)
393
- expect(@worksheet.is_column_italicized(0)).to eq(true)
394
- expect(@worksheet[5][0].is_italicized).to eq(true)
405
+ subject.change_column_italics(0, true)
406
+ expect(subject.is_column_italicized(0)).to eq(true)
407
+ expect(subject[5][0].is_italicized).to eq(true)
395
408
  end
396
409
 
397
410
  it 'should cause error if a negative argument is passed in' do
398
411
  expect {
399
- @worksheet.change_column_italics(-1, false)
412
+ subject.change_column_italics(-1, false)
400
413
  }.to raise_error(RuntimeError)
401
414
  end
402
415
  end
403
416
 
404
417
  describe '.change_column_bold' do
405
418
  it 'should make column and cell fonts bolded when true is passed' do
406
- @worksheet.change_column_bold(0, true)
407
- expect(@worksheet.is_column_bolded(0)).to eq(true)
408
- expect(@worksheet[5][0].is_bolded).to eq(true)
419
+ subject.change_column_bold(0, true)
420
+ expect(subject.is_column_bolded(0)).to eq(true)
421
+ expect(subject[5][0].is_bolded).to eq(true)
409
422
  end
410
423
 
411
424
  it 'should cause error if a negative argument is passed in' do
412
425
  expect {
413
- @worksheet.change_column_bold(-1, false)
426
+ subject.change_column_bold(-1, false)
414
427
  }.to raise_error(RuntimeError)
415
428
  end
416
429
  end
417
430
 
418
431
  describe '.change_column_underline' do
419
432
  it 'should make column and cell fonts underlined when true is passed' do
420
- @worksheet.change_column_underline(0, true)
421
- expect(@worksheet.is_column_underlined(0)).to eq(true)
422
- expect(@worksheet[5][0].is_underlined).to eq(true)
433
+ subject.change_column_underline(0, true)
434
+ expect(subject.is_column_underlined(0)).to eq(true)
435
+ expect(subject[5][0].is_underlined).to eq(true)
423
436
  end
424
437
 
425
438
  it 'should cause error if a negative argument is passed in' do
426
439
  expect {
427
- @worksheet.change_column_underline(-1, false)
440
+ subject.change_column_underline(-1, false)
428
441
  }.to raise_error(RuntimeError)
429
442
  end
430
443
  end
431
444
 
432
445
  describe '.change_column_strikethrough' do
433
446
  it 'should make column and cell fonts struckthrough when true is passed' do
434
- @worksheet.change_column_strikethrough(0, true)
435
- expect(@worksheet.is_column_struckthrough(0)).to eq(true)
436
- expect(@worksheet[5][0].is_struckthrough).to eq(true)
447
+ subject.change_column_strikethrough(0, true)
448
+ expect(subject.is_column_struckthrough(0)).to eq(true)
449
+ expect(subject[5][0].is_struckthrough).to eq(true)
437
450
  end
438
451
 
439
452
  it 'should cause error if a negative argument is passed in' do
440
453
  expect {
441
- @worksheet.change_column_strikethrough(-1, false)
454
+ subject.change_column_strikethrough(-1, false)
442
455
  }.to raise_error(RuntimeError)
443
456
  end
444
457
  end
445
458
 
446
459
  describe '.change_column_width_raw' do
447
460
  it 'should make column width match number which is passed' do
448
- @worksheet.change_column_width_raw(0, 30.0002)
449
- expect(@worksheet.get_column_width_raw(0)).to eq(30.0002)
461
+ subject.change_column_width_raw(0, 30.0002)
462
+ expect(subject.get_column_width_raw(0)).to eq(30.0002)
450
463
  end
451
464
 
452
465
  it 'should cause error if a negative argument is passed in' do
453
466
  expect {
454
- @worksheet.change_column_width_raw(-1, 10)
467
+ subject.change_column_width_raw(-1, 10)
455
468
  }.to raise_error(RuntimeError)
456
469
  end
457
470
  end
@@ -459,314 +472,632 @@ describe RubyXL::Worksheet do
459
472
  describe '.change_column_fill' do
460
473
  it 'should raise error if hex color code not passed' do
461
474
  expect {
462
- @worksheet.change_column_fill(0, 'G')
475
+ subject.change_column_fill(0, 'G')
463
476
  }.to raise_error(RuntimeError)
464
477
  end
465
478
 
466
479
  it 'should raise error if hex color code includes # character' do
467
480
  expect {
468
- @worksheet.change_column_fill(3, '#FFF000')
481
+ subject.change_column_fill(3, '#FFF000')
469
482
  }.to raise_error(RuntimeError)
470
483
  end
471
484
 
472
485
  it 'should make column and cell fill colors equal hex color code passed' do
473
- @worksheet.change_column_fill(0, '111111')
474
- expect(@worksheet.get_column_fill(0)).to eq('111111')
475
- expect(@worksheet[5][0].fill_color).to eq('111111')
486
+ subject.change_column_fill(0, '111111')
487
+ expect(subject.get_column_fill(0)).to eq('111111')
488
+ expect(subject[5][0].fill_color).to eq('111111')
476
489
  end
477
490
 
478
491
  it 'should cause error if a negative argument is passed in' do
479
492
  expect {
480
- @worksheet.change_column_fill(-1, '111111')
493
+ subject.change_column_fill(-1, '111111')
481
494
  }.to raise_error(RuntimeError)
482
495
  end
483
496
  end
484
497
 
485
498
  describe '.change_column_horizontal_alignment' do
486
499
  it 'should cause column and cell to horizontally align as specified by the passed in string' do
487
- @worksheet.change_column_horizontal_alignment(0, 'center')
488
- expect(@worksheet.get_column_alignment(0, :horizontal)).to eq('center')
489
- expect(@worksheet[5][0].horizontal_alignment).to eq('center')
500
+ subject.change_column_horizontal_alignment(0, 'center')
501
+ expect(subject.get_column_alignment(0, :horizontal)).to eq('center')
502
+ expect(subject[5][0].horizontal_alignment).to eq('center')
490
503
  end
491
504
 
492
505
  it 'should cause error if a negative argument is passed in' do
493
506
  expect {
494
- @worksheet.change_column_horizontal_alignment(-1, 'center')
507
+ subject.change_column_horizontal_alignment(-1, 'center')
495
508
  }.to raise_error(RuntimeError)
496
509
  end
497
510
  end
498
511
 
499
512
  describe '.change_column_vertical_alignment' do
500
513
  it 'should cause column and cell to vertically align as specified by the passed in string' do
501
- @worksheet.change_column_vertical_alignment(0, 'center')
502
- expect(@worksheet.get_column_alignment(0, :vertical)).to eq('center')
503
- expect(@worksheet[5][0].vertical_alignment).to eq('center')
514
+ subject.change_column_vertical_alignment(0, 'center')
515
+ expect(subject.get_column_alignment(0, :vertical)).to eq('center')
516
+ expect(subject[5][0].vertical_alignment).to eq('center')
504
517
  end
505
518
 
506
519
  it 'should cause error if a negative argument is passed in' do
507
520
  expect {
508
- @worksheet.change_column_vertical_alignment(-1, 'center')
521
+ subject.change_column_vertical_alignment(-1, 'center')
509
522
  }.to raise_error(RuntimeError)
510
523
  end
511
524
 
512
525
  it 'should set column width if column alignment is changed' do
513
526
  test_column = 2
514
- expect(@worksheet.get_column_alignment(test_column, :vertical)).to be_nil
515
- expect(@worksheet.get_column_width_raw(test_column)).to be_nil
516
- expect(@worksheet.get_column_width(test_column)).to eq(RubyXL::ColumnRange::DEFAULT_WIDTH)
517
- @worksheet.change_column_vertical_alignment(test_column, 'top')
518
- expect(@worksheet.get_column_width_raw(test_column)).not_to be_nil
519
- expect(@worksheet.get_column_width(test_column)).to eq(RubyXL::ColumnRange::DEFAULT_WIDTH)
520
- expect(@worksheet.get_column_alignment(test_column, :vertical)).to eq('top')
527
+ expect(subject.get_column_alignment(test_column, :vertical)).to be_nil
528
+ expect(subject.get_column_width_raw(test_column)).to be_nil
529
+ expect(subject.get_column_width(test_column)).to eq(RubyXL::ColumnRange::DEFAULT_WIDTH)
530
+ subject.change_column_vertical_alignment(test_column, 'top')
531
+ expect(subject.get_column_width_raw(test_column)).not_to be_nil
532
+ expect(subject.get_column_width(test_column)).to eq(RubyXL::ColumnRange::DEFAULT_WIDTH)
533
+ expect(subject.get_column_alignment(test_column, :vertical)).to eq('top')
521
534
  end
522
535
  end
523
536
 
524
537
  describe '.change_column_border' do
525
538
  it 'should cause error if a negative argument is passed in' do
526
539
  expect {
527
- @worksheet.change_column_border(-1, :top, 'thin')
540
+ subject.change_column_border(-1, :top, 'thin')
528
541
  }.to raise_error(RuntimeError)
529
542
  end
530
543
 
531
544
  it 'should cause column and cells within to have border at top of specified weight' do
532
- @worksheet.change_column_border(0, :top, 'thin')
533
- expect(@worksheet.get_column_border(0, :top)).to eq('thin')
534
- expect(@worksheet[5][0].get_border(:top)).to eq('thin')
545
+ subject.change_column_border(0, :top, 'thin')
546
+ expect(subject.get_column_border(0, :top)).to eq('thin')
547
+ expect(subject[5][0].get_border(:top)).to eq('thin')
535
548
  end
536
549
 
537
550
  it 'should cause column and cells within to have border at left of specified weight' do
538
- @worksheet.change_column_border(0, :left, 'thin')
539
- expect(@worksheet.get_column_border(0, :left)).to eq('thin')
540
- expect(@worksheet[5][0].get_border(:left)).to eq('thin')
551
+ subject.change_column_border(0, :left, 'thin')
552
+ expect(subject.get_column_border(0, :left)).to eq('thin')
553
+ expect(subject[5][0].get_border(:left)).to eq('thin')
541
554
  end
542
555
 
543
556
  it 'should cause column and cells within to have border at right of specified weight' do
544
- @worksheet.change_column_border(0, :right, 'thin')
545
- expect(@worksheet.get_column_border(0, :right)).to eq('thin')
546
- expect(@worksheet[5][0].get_border(:right)).to eq('thin')
557
+ subject.change_column_border(0, :right, 'thin')
558
+ expect(subject.get_column_border(0, :right)).to eq('thin')
559
+ expect(subject[5][0].get_border(:right)).to eq('thin')
547
560
  end
548
561
 
549
562
  it 'should cause column and cells within to have border at bottom of specified weight' do
550
- @worksheet.change_column_border(0, :bottom, 'thin')
551
- expect(@worksheet.get_column_border(0, :bottom)).to eq('thin')
552
- expect(@worksheet[5][0].get_border(:bottom)).to eq('thin')
563
+ subject.change_column_border(0, :bottom, 'thin')
564
+ expect(subject.get_column_border(0, :bottom)).to eq('thin')
565
+ expect(subject[5][0].get_border(:bottom)).to eq('thin')
553
566
  end
554
567
 
555
568
  it 'should cause column and cells within to have border at diagonal of specified weight' do
556
- @worksheet.change_column_border(0, :diagonal, 'thin')
557
- expect(@worksheet.get_column_border(0, :diagonal)).to eq('thin')
558
- expect(@worksheet[5][0].get_border(:diagonal)).to eq('thin')
569
+ subject.change_column_border(0, :diagonal, 'thin')
570
+ expect(subject.get_column_border(0, :diagonal)).to eq('thin')
571
+ expect(subject[5][0].get_border(:diagonal)).to eq('thin')
559
572
  end
560
573
  end
561
574
 
562
575
  describe '.merge_cells' do
563
576
  it 'should merge cells in any valid range specified by indices' do
564
- @worksheet.merge_cells(0, 0, 1, 1)
565
- expect(@worksheet.merged_cells.collect{ |r| r.ref.to_s }).to eq(["A1:B2"])
577
+ subject.merge_cells(0, 1, 2, 3)
578
+ expect(subject.merged_cells.collect{ |r| r.ref.to_s }).to eq(['B1:D3'])
579
+ end
580
+
581
+ it 'should merge cells in any valid range specified by Reference' do
582
+ subject.merge_cells('A1:FF99')
583
+ expect(subject.merged_cells.collect{ |r| r.ref.to_s }).to eq(['A1:FF99'])
584
+ end
585
+
586
+ it 'should merge cells in any valid range specified by named params' do
587
+ subject.merge_cells(row_from: 0, row_to: 1, col_from: 2, col_to: 3)
588
+ expect(subject.merged_cells.collect{ |r| r.ref.to_s }).to eq(['C1:D2'])
566
589
  end
567
590
  end
568
591
 
569
592
  describe '.add_cell' do
570
593
  it 'should add new cell where specified, even if a cell is already there (default)' do
571
- @worksheet.add_cell(0,0, 'TEST')
572
- expect(@worksheet[0][0].value).not_to eq(@old_cell_value)
573
- expect(@worksheet[0][0].value).to eq('TEST')
594
+ old_cell = subject[0][0]
595
+ old_cell_value = old_cell.value.to_s
596
+
597
+ subject.add_cell(0, 0, 'TEST')
598
+ expect(subject[0][0].value).not_to eq(old_cell_value)
599
+ expect(subject[0][0].value).to eq('TEST')
574
600
  end
575
601
 
576
602
  it 'should add a new cell below nil rows that might exist' do
577
- @worksheet.sheet_data.rows << nil << nil
578
- @worksheet.add_cell(15,0, 'TEST')
579
- expect(@worksheet[15][0].value).to eq('TEST')
603
+ subject.sheet_data.rows << nil << nil
604
+ subject.add_cell(15, 0, 'TEST')
605
+ expect(subject[15][0].value).to eq('TEST')
580
606
  end
581
607
 
582
608
  it 'should add new cell where specified with formula, even if a cell is already there (default)' do
583
- @worksheet.add_cell(0,0, '', 'SUM(A2:A10)')
584
- expect(@worksheet[0][0].value).not_to eq(@old_cell_value)
585
- expect(@worksheet[0][0].formula).not_to eq(@old_cell_formula)
586
- expect(@worksheet[0][0].value).to eq('')
587
- expect(@worksheet[0][0].formula.expression).to eq('SUM(A2:A10)')
609
+ old_cell = subject[0][0]
610
+ old_cell_value = old_cell.value.to_s
611
+ old_cell_formula = old_cell.formula.expression.to_s
612
+
613
+ subject.add_cell(0, 0, '', 'SUM(A2:A10)')
614
+ expect(subject[0][0].value).not_to eq(old_cell_value)
615
+ expect(subject[0][0].formula).not_to eq(old_cell_formula)
616
+ expect(subject[0][0].value).to eq('')
617
+ expect(subject[0][0].formula.expression).to eq('SUM(A2:A10)')
588
618
  end
589
619
 
590
620
  it 'should not overwrite when a cell is present when overwrite is specified to be false' do
591
- @worksheet.add_cell(0,0, 'TEST', 'B2',false)
592
- expect(@worksheet[0][0].value).to eq(@old_cell_value)
593
- expect(@worksheet[0][0].formula.expression.to_s).to eq(@old_cell_formula)
621
+ old_cell = subject[0][0]
622
+ old_cell_value = old_cell.value.to_s
623
+ old_cell_formula = old_cell.formula.expression.to_s
624
+
625
+ subject.add_cell(0, 0, 'TEST', 'B2', false)
626
+ expect(subject[0][0].value).to eq(old_cell_value)
627
+ expect(subject[0][0].formula.expression.to_s).to eq(old_cell_formula)
594
628
  end
595
629
 
596
630
  it 'should still add a new cell when there is no cell to be overwritten' do
597
- @worksheet.add_cell(11,11, 'TEST', 'B2',false)
598
- expect(@worksheet[11][11].value).to eq('TEST')
599
- expect(@worksheet[11][11].formula.expression).to eq('B2')
631
+ subject.add_cell(11, 11, 'TEST', 'B2', false)
632
+ expect(subject[11][11].value).to eq('TEST')
633
+ expect(subject[11][11].formula.expression).to eq('B2')
600
634
  end
601
635
 
602
636
  it 'should cause error if a negative argument is passed in' do
603
637
  expect {
604
- @worksheet.add_cell(-1,-1, '')
638
+ subject.add_cell(-1, -1, '')
605
639
  }.to raise_error(RuntimeError)
606
640
  end
607
641
  end
608
642
 
609
643
  describe '.delete_row' do
610
644
  it 'should delete a row at index specified, "pushing" everything else "up"' do
611
- @worksheet.delete_row(0)
612
- expect(@worksheet[0][0].value).to eq("1:0")
613
- expect(@worksheet[0][0].formula.expression.to_s).to eq("F1:0")
614
- expect(@worksheet[0][0].row).to eq(0)
615
- expect(@worksheet[0][0].column).to eq(0)
645
+ subject.delete_row(0)
646
+ expect(subject[0][0].value).to eq('0:1')
647
+ expect(subject[0][0].formula.expression.to_s).to eq('F0:1')
648
+ expect(subject[0][0].row).to eq(0)
649
+ expect(subject[0][0].column).to eq(0)
616
650
  end
617
651
 
618
652
  it 'should delete a row at index specified, adjusting styles for other rows' do
619
- @worksheet.change_row_font_name(1,"Courier")
620
- @worksheet.delete_row(0)
621
- expect(@worksheet.get_row_font_name(0)).to eq("Courier")
653
+ subject.change_row_font_name(1, 'Courier')
654
+ subject.delete_row(0)
655
+ expect(subject.get_row_font_name(0)).to eq('Courier')
622
656
  end
623
657
 
624
658
  it 'should preserve (rather than fix) formulas that reference cells in "pushed up" rows' do
625
- @worksheet.add_cell(11, 0, nil, 'SUM(A1:A10)')
626
- @worksheet.delete_row(0)
627
- expect(@worksheet[10][0].formula.expression).to eq('SUM(A1:A10)')
659
+ subject.add_cell(11, 0, nil, 'SUM(A1:A10)')
660
+ subject.delete_row(0)
661
+ expect(subject[10][0].formula.expression).to eq('SUM(A1:A10)')
628
662
  end
629
663
 
630
664
  it 'should cause error if a negative argument is passed in' do
631
665
  expect {
632
- @worksheet.delete_row(-1)
666
+ subject.delete_row(-1)
633
667
  }.to raise_error(RuntimeError)
634
668
  end
635
669
 
636
- it 'should properly reindex the cells' do
637
- @worksheet.sheet_data.rows.each_with_index { |row, r|
638
- row.cells.each_with_index { |cell, c|
639
- expect(cell.row).to eq(r)
640
- expect(cell.column).to eq(c)
641
- }
670
+ it 'should properly reindex the cells' do
671
+ subject.sheet_data.rows.each_with_index { |row, r|
672
+ if (r == SKIP_ROW_COL) then
673
+ expect(row).to be_nil
674
+ else
675
+ row.cells.each_with_index { |cell, c|
676
+ if (c == SKIP_ROW_COL) then
677
+ expect(cell).to be_nil
678
+ else
679
+ expect(cell.row).to eq(r)
680
+ expect(cell.column).to eq(c)
681
+ end
682
+ }
683
+ end
642
684
  }
643
685
  end
686
+
687
+ describe 'merged_cells updating' do
688
+ context 'merged cells in the row' do
689
+ # | A1 | B1 | C1 | D1 | E1 |
690
+ # | A2 | MERGED | E2 |
691
+ # | A3 | B3 | C3 | D3 | E3 |
692
+ before do
693
+ subject.merge_cells(1, 1, 1, 3)
694
+ expect(subject.merged_cells.size).to eq 1
695
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:D2'
696
+ end
697
+ it 'should delete merged cell' do
698
+ subject.delete_row(1)
699
+ expect(subject.merged_cells.size).to eq 0
700
+ end
701
+ end
702
+ context 'merged vertical two cells' do
703
+ # | A1 | B1 | C1 |
704
+ # | A2 | MERGED | C2 |
705
+ # | A3 | | C3 |
706
+ # | A4 | B4 | C4 |
707
+ before do
708
+ subject.merge_cells(1, 1, 2, 1)
709
+ expect(subject.merged_cells.size).to eq 1
710
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:B3'
711
+ end
712
+ it 'should delete merged cell' do
713
+ subject.delete_row(1)
714
+ expect(subject.merged_cells.size).to eq 0
715
+ end
716
+ end
717
+
718
+ context 'merged three or more rows' do
719
+ # | A1 | B1 | C1 | D1 | E1 |
720
+ # | A2 | | E2 |
721
+ # | A3 | MERGED | E3 |
722
+ # | A4 | | E4 |
723
+ # | A5 | B5 | C5 | D5 | E5 |
724
+ before do
725
+ subject.merge_cells(1, 1, 3, 3)
726
+ expect(subject.merged_cells.size).to eq 1
727
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:D4'
728
+ end
729
+
730
+ # | A2 | | E2 |
731
+ # | A3 | MERGED | E3 |
732
+ # | A4 | | E4 |
733
+ # | A5 | B5 | C5 | D5 | E5 |
734
+ it 'should updates merged cell when delete above the cell' do
735
+ subject.delete_row(0)
736
+ expect(subject.merged_cells.size).to eq 1
737
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B1:D3'
738
+ end
739
+
740
+ # | A1 | B1 | C1 | D1 | E1 |
741
+ # | A3 | MERGED | E3 |
742
+ # | A4 | | E4 |
743
+ # | A5 | B5 | C5 | D5 | E5 |
744
+ it 'should updates merged cell when delete top of the cell' do
745
+ subject.delete_row(1)
746
+ expect(subject.merged_cells.size).to eq 1
747
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:D3'
748
+ end
749
+
750
+ # | A1 | B1 | C1 | D1 | E1 |
751
+ # | A2 | MERGED | E2 |
752
+ # | A4 | | E4 |
753
+ # | A5 | B5 | C5 | D5 | E5 |
754
+ it 'should updates merged cell when delete middle of the cell' do
755
+ subject.delete_row(2)
756
+ expect(subject.merged_cells.size).to eq 1
757
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:D3'
758
+ end
759
+
760
+ # | A1 | B1 | C1 | D1 | E1 |
761
+ # | A2 | MERGED | E2 |
762
+ # | A3 | | E3 |
763
+ # | A5 | B5 | C5 | D5 | E5 |
764
+ it 'should updates merged cell when delete bottom of the cell' do
765
+ subject.delete_row(3)
766
+ expect(subject.merged_cells.size).to eq 1
767
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:D3'
768
+ end
769
+
770
+ # | A1 | B1 | C1 | D1 | E1 |
771
+ # | A2 | | E2 |
772
+ # | A3 | MERGED | E3 |
773
+ # | A4 | | E4 |
774
+ it 'should not updates merged cell when ldelete below the cell' do
775
+ subject.delete_row(4)
776
+ expect(subject.merged_cells.size).to eq 1
777
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:D4'
778
+ end
779
+ end
780
+ end
781
+
782
+ it 'should not make empty merged_cells when a worksheet does not have a merged cell' do
783
+ # If a worksheet has empty merged_cells, the xlsx file has an XML error and has to repair.
784
+ subject.delete_row(0)
785
+ expect(subject.merged_cells).to be_nil
786
+ end
644
787
  end
645
788
 
646
789
  describe '.insert_row' do
647
790
  it 'should insert a row at index specified, "pushing" everything else "down"' do
648
- @worksheet.insert_row(0)
649
- expect(@worksheet[0][0]).to be_nil
650
- expect(@worksheet[1][0].value).to eq(@old_cell_value)
651
- expect(@worksheet[1][0].formula.expression.to_s).to eq(@old_cell_formula)
791
+ old_cell = subject[0][0]
792
+ old_cell_value = old_cell.value.to_s
793
+ old_cell_formula = old_cell.formula.expression.to_s
652
794
 
653
- @worksheet.insert_row(5)
654
- expect(@worksheet[5][0].is_underlined).to be_nil
795
+ subject.insert_row(0)
796
+ expect(subject[0][0]).to be_nil
797
+ expect(subject[1][0].value).to eq(old_cell_value)
798
+ expect(subject[1][0].formula.expression.to_s).to eq(old_cell_formula)
799
+
800
+ subject.insert_row(7)
801
+ expect(subject[7][0].is_underlined).to be_nil
655
802
  end
656
803
 
657
804
  it 'should insert a row skipping nil rows that might exist' do
658
- @worksheet.sheet_data.rows << nil << nil
659
- rows = @worksheet.sheet_data.rows.size
660
- @worksheet.insert_row(rows)
661
- expect(@worksheet[rows - 1]).to be_nil
805
+ subject.sheet_data.rows << nil << nil
806
+ rows = subject.sheet_data.rows.size
807
+ subject.insert_row(rows)
808
+ expect(subject[rows - 1]).to be_nil
662
809
  end
663
810
 
664
811
  it 'should insert a row at index specified, copying styles from row "above"' do
665
- @worksheet.change_row_font_name(0, 'Courier')
666
- @worksheet.insert_row(1)
667
- expect(@worksheet.get_row_font_name(1)).to eq('Courier')
812
+ subject.change_row_font_name(0, 'Courier')
813
+ subject.insert_row(1)
814
+ expect(subject.get_row_font_name(1)).to eq('Courier')
668
815
  end
669
816
 
670
817
  it 'should preserve (rather than fix) formulas that reference cells "pushed down" rows' do
671
- @worksheet.add_cell(5,0,nil, 'SUM(A1:A4)')
672
- @worksheet.insert_row(0)
673
- expect(@worksheet[6][0].formula.expression).to eq('SUM(A1:A4)')
818
+ subject.add_cell(5, 0, nil, 'SUM(A1:A4)')
819
+ subject.insert_row(0)
820
+ expect(subject[6][0].formula.expression).to eq('SUM(A1:A4)')
674
821
  end
675
822
 
676
823
  it 'should cause error if a negative argument is passed in' do
677
824
  expect {
678
- @worksheet.insert_row(-1)
825
+ subject.insert_row(-1)
679
826
  }.to raise_error(RuntimeError)
680
827
  end
681
828
 
682
- it 'should expand matrix to fit argument if nonnegative' do
683
- expect(@worksheet.sheet_data.size).to eq(11)
684
- @worksheet.insert_row(11)
685
- expect(@worksheet.sheet_data.size).to eq(13)
829
+ it 'should expand matrix to fit argument if nonnegative' do
830
+ expect(subject.sheet_data.size).to eq(11)
831
+ subject.insert_row(11)
832
+ expect(subject.sheet_data.size).to eq(13)
833
+ end
834
+
835
+ it 'should properly reindex the cells' do
836
+ subject.sheet_data.rows.each_with_index { |row, r|
837
+ if (r == SKIP_ROW_COL) then
838
+ expect(row).to be_nil
839
+ else
840
+ row.cells.each_with_index { |cell, c|
841
+ if (c == SKIP_ROW_COL) then
842
+ expect(cell).to be_nil
843
+ else
844
+ expect(cell.row).to eq(r)
845
+ expect(cell.column).to eq(c)
846
+ end
847
+ }
848
+ end
849
+ }
686
850
  end
687
851
 
688
- it 'should properly reindex the cells' do
689
- @worksheet.sheet_data.rows.each_with_index { |row, r|
690
- row.cells.each_with_index { |cell, c|
691
- expect(cell.row).to eq(r)
692
- expect(cell.column).to eq(c)
693
- }
694
- }
852
+ describe 'merged_cells updating' do
853
+ # | A1 | B1 | C1 | D1 |
854
+ # | A2 | MERGED | D2 |
855
+ # | A3 | | D3 |
856
+ # | A4 | B4 | C4 | D4 |
857
+ before do
858
+ subject.merge_cells(1, 1, 2, 2)
859
+ expect(subject.merged_cells.size).to eq 1
860
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:C3'
861
+ end
862
+
863
+ # | A1 | B1 | C1 | D1 |
864
+ # | | | | |
865
+ # | A2 | MERGED | D2 |
866
+ # | A3 | | D3 |
867
+ # | A4 | B4 | C4 | D4 |
868
+ it 'should updates merged cell when insert above the cell' do
869
+ subject.insert_row(1)
870
+ expect(subject.merged_cells.size).to eq 1
871
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B3:C4'
872
+ end
873
+
874
+ # | A1 | B1 | C1 | D1 |
875
+ # | A2 | | D2 |
876
+ # | | MERGED | |
877
+ # | A3 | | D3 |
878
+ # | A4 | B4 | C4 | D4 |
879
+ it 'should updates merged cell when insert into the cell' do
880
+ subject.insert_row(2)
881
+ expect(subject.merged_cells.size).to eq 1
882
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:C4'
883
+ end
884
+
885
+ # | A1 | B1 | C1 | D1 |
886
+ # | A2 | MERGED | D2 |
887
+ # | A3 | | D3 |
888
+ # | | | | |
889
+ # | A4 | B4 | C4 | D4 |
890
+ it 'should not updates merged cell when insert below the cell' do
891
+ subject.insert_row(3)
892
+ expect(subject.merged_cells.size).to eq 1
893
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:C3'
894
+ end
895
+ end
896
+
897
+ it 'should not make empty merged_cells when a worksheet does not have a merged cell' do
898
+ # If a worksheet has empty merged_cells, the xlsx file has an XML error and has to repair.
899
+ subject.insert_row(0)
900
+ expect(subject.merged_cells).to be_nil
695
901
  end
696
902
  end
697
903
 
698
904
  describe '.delete_column' do
699
905
  it 'should delete a column at index specified, "pushing" everything else "left"' do
700
- @worksheet.delete_column(0)
701
- expect(@worksheet[0][0].value).to eq("0:1")
702
- expect(@worksheet[0][0].formula.expression.to_s).to eq("F0:1")
703
- expect(@worksheet[0][0].row).to eq(0)
906
+ subject.delete_column(0)
907
+ expect(subject[0][0].value).to eq('1:0')
908
+ expect(subject[0][0].formula.expression.to_s).to eq('F1:0')
909
+ expect(subject[0][0].row).to eq(0)
704
910
  end
705
911
 
706
912
  it 'should delete a column at index specified, "pushing" styles "left"' do
707
- @worksheet.change_column_font_name(1,"Courier")
708
- @worksheet.delete_column(0)
709
- expect(@worksheet.get_column_font_name(0)).to eq("Courier")
913
+ subject.change_column_font_name(1, 'Courier')
914
+ subject.delete_column(0)
915
+ expect(subject.get_column_font_name(0)).to eq('Courier')
710
916
  end
711
917
 
712
918
  it 'should preserve (rather than fix) formulas that reference cells in "pushed left" columns' do
713
- @worksheet.add_cell(0,4,nil, 'SUM(A1:D1)')
714
- @worksheet.delete_column(0)
715
- expect(@worksheet[0][3].formula.expression).to eq('SUM(A1:D1)')
919
+ subject.add_cell(0, 4, nil, 'SUM(A1:D1)')
920
+ subject.delete_column(0)
921
+ expect(subject[0][3].formula.expression).to eq('SUM(A1:D1)')
716
922
  end
717
923
 
718
924
  it 'should update cell indices after deleting the column' do
719
- @worksheet.delete_column(2)
720
- @worksheet[0].cells.each_with_index { |cell, i|
721
- expect(cell.column).to eq(i)
925
+ subject.delete_column(2)
926
+
927
+ subject.sheet_data.rows.each_with_index { |row, r|
928
+ if (r == SKIP_ROW_COL) then
929
+ expect(row).to be_nil
930
+ else
931
+ row.cells.each_with_index { |cell, c|
932
+ if (SKIP_ROW_COL - 1 == c) then
933
+ expect(cell).to be_nil
934
+ else
935
+ expect(cell.row).to eq(r)
936
+ expect(cell.column).to eq(c)
937
+ end
938
+ }
939
+ end
722
940
  }
723
941
  end
724
942
 
725
943
  it 'should cause error if negative argument is passed in' do
726
944
  expect {
727
- @worksheet.delete_column(-1)
945
+ subject.delete_column(-1)
728
946
  }.to raise_error(RuntimeError)
729
947
  end
730
948
 
731
- it 'should properly reindex the cells' do
732
- @worksheet.sheet_data.rows.each_with_index { |row, r|
733
- row.cells.each_with_index { |cell, c|
734
- expect(cell.row).to eq(r)
735
- expect(cell.column).to eq(c)
736
- }
949
+ it 'should properly reindex the cells' do
950
+ subject.sheet_data.rows.each_with_index { |row, r|
951
+ if (r == SKIP_ROW_COL) then
952
+ expect(row).to be_nil
953
+ else
954
+ row.cells.each_with_index { |cell, c|
955
+ if (c == SKIP_ROW_COL) then
956
+ expect(cell).to be_nil
957
+ else
958
+ expect(cell.row).to eq(r)
959
+ expect(cell.column).to eq(c)
960
+ end
961
+ }
962
+ end
737
963
  }
738
964
  end
965
+
966
+ describe 'merged_cells updating' do
967
+ context 'merged cells in the column' do
968
+ # | A1 | B1 | C1 |
969
+ # | A2 | | C2 |
970
+ # | A3 | MERGED | C3 |
971
+ # | A4 | | C4 |
972
+ # | A5 | B5 | C5 |
973
+ before do
974
+ subject.merge_cells(1, 1, 3, 1)
975
+ expect(subject.merged_cells.size).to eq 1
976
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:B4'
977
+ end
978
+ it 'should delete merged cell' do
979
+ subject.delete_column(1)
980
+ expect(subject.merged_cells.size).to eq 0
981
+ end
982
+ end
983
+ context 'merged horizontal two cells' do
984
+ # | A1 | B1 | C1 | D1 |
985
+ # | A2 | MERGED | D2 |
986
+ # | A3 | B3 | C3 | D3 |
987
+ before do
988
+ subject.merge_cells(1, 1, 1, 2)
989
+ expect(subject.merged_cells.size).to eq 1
990
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:C2'
991
+ end
992
+ it 'should delete merged cell' do
993
+ subject.delete_column(1)
994
+ expect(subject.merged_cells.size).to eq 0
995
+ end
996
+ end
997
+ context 'merged three or more columns' do
998
+ # | A1 | B1 | C1 | D1 | E1 |
999
+ # | A2 | | E2 |
1000
+ # | A3 | MERGED | E3 |
1001
+ # | A4 | | E4 |
1002
+ # | A5 | B5 | C5 | D5 | E5 |
1003
+ before do
1004
+ subject.merge_cells(1, 1, 3, 3)
1005
+ expect(subject.merged_cells.size).to eq 1
1006
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:D4'
1007
+ end
1008
+ # | B1 | C1 | D1 | E1 |
1009
+ # | | E2 |
1010
+ # | MERGED | E3 |
1011
+ # | | E4 |
1012
+ # | B5 | C5 | D5 | E5 |
1013
+ it 'should updates merged cell when delete before the cell' do
1014
+ subject.delete_column(0)
1015
+ expect(subject.merged_cells.size).to eq 1
1016
+ expect(subject.merged_cells.first.ref.to_s).to eq 'A2:C4'
1017
+ end
1018
+ # | A1 | C1 | D1 | E1 |
1019
+ # | A2 | | E2 |
1020
+ # | A3 | MERGED | E3 |
1021
+ # | A4 | | E4 |
1022
+ # | A5 | C5 | D5 | E5 |
1023
+ it 'should updates merged cell when delete left of the cell' do
1024
+ subject.delete_column(1)
1025
+ expect(subject.merged_cells.size).to eq 1
1026
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:C4'
1027
+ end
1028
+ # | A1 | B1 | D1 | E1 |
1029
+ # | A2 | | E2 |
1030
+ # | A3 | MERGED | E3 |
1031
+ # | A4 | | E4 |
1032
+ # | A5 | B5 | D5 | E5 |
1033
+ it 'should updates merged cell when delete center of the cell' do
1034
+ subject.delete_column(2)
1035
+ expect(subject.merged_cells.size).to eq 1
1036
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:C4'
1037
+ end
1038
+ # | A1 | B1 | C1 | E1 |
1039
+ # | A2 | | E2 |
1040
+ # | A3 | MERGED | E3 |
1041
+ # | A4 | | E4 |
1042
+ # | A5 | B5 | C5 | E5 |
1043
+ it 'should updates merged cell when delete right of the cell' do
1044
+ subject.delete_column(3)
1045
+ expect(subject.merged_cells.size).to eq 1
1046
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:C4'
1047
+ end
1048
+ # | A1 | B1 | C1 | D1 |
1049
+ # | A2 | |
1050
+ # | A3 | MERGED |
1051
+ # | A4 | |
1052
+ # | A5 | B5 | C5 | D5 |
1053
+ it 'should not updates merged cell when delete after the cell' do
1054
+ subject.delete_column(4)
1055
+ expect(subject.merged_cells.size).to eq 1
1056
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:D4'
1057
+ end
1058
+ end
1059
+ end
1060
+
1061
+ it 'should not make empty merged_cells when a worksheet does not have a merged cell' do
1062
+ # If a worksheet has empty merged_cells, the xlsx file has an XML error and has to repair.
1063
+ subject.delete_column(0)
1064
+ expect(subject.merged_cells).to be_nil
1065
+ end
739
1066
  end
740
1067
 
741
1068
  describe '.insert_column' do
742
1069
  it 'should insert a column at index specified, "pushing" everything else "right"' do
743
- @worksheet.insert_column(0)
744
- expect(@worksheet[0][0]).to be_nil
745
- expect(@worksheet[0][1].value).to eq(@old_cell_value)
746
- expect(@worksheet[0][1].formula.expression.to_s).to eq(@old_cell_formula)
1070
+ old_cell = subject[0][0]
1071
+ old_cell_value = old_cell.value.to_s
1072
+ old_cell_formula = old_cell.formula.expression.to_s
1073
+
1074
+ subject.insert_column(0)
1075
+ expect(subject[0][0]).to be_nil
1076
+ expect(subject[0][1].value).to eq(old_cell_value)
1077
+ expect(subject[0][1].formula.expression.to_s).to eq(old_cell_formula)
747
1078
  end
748
1079
 
749
1080
  it 'should insert a column at index specified, copying styles from column to "left"' do
750
- @worksheet.change_column_font_name(0, 'Courier')
751
- @worksheet.insert_column(1)
752
- expect(@worksheet.get_column_font_name(1)).to eq('Courier')
1081
+ subject.change_column_font_name(0, 'Courier')
1082
+ subject.insert_column(1)
1083
+ expect(subject.get_column_font_name(1)).to eq('Courier')
753
1084
  end
754
1085
 
755
1086
  it 'should insert a column at 0 without copying any styles, when passed 0 as column index' do
756
- @worksheet.change_column_font_name(0, 'Courier')
757
- @worksheet.insert_column(0)
758
- expect(@worksheet.get_column_font_name(0)).to eq('Verdana') #not courier
1087
+ subject.change_column_font_name(0, 'Courier')
1088
+ subject.insert_column(0)
1089
+ expect(subject.get_column_font_name(0)).to eq('Verdana') # not courier
759
1090
  end
760
1091
 
761
1092
  it 'should preserve (rather than fix) formulas that reference cells in "pushed right" column' do
762
- @worksheet.add_cell(0,5,nil, 'SUM(A1:D1)')
763
- @worksheet.insert_column(0)
764
- expect(@worksheet[0][6].formula.expression).to eq('SUM(A1:D1)')
1093
+ subject.add_cell(0, 5, nil, 'SUM(A1:D1)')
1094
+ subject.insert_column(0)
1095
+ expect(subject[0][6].formula.expression).to eq('SUM(A1:D1)')
765
1096
  end
766
1097
 
767
1098
  it 'should update cell indices after deleting the column' do
768
- @worksheet.insert_column(5)
769
- @worksheet[0].cells.each_with_index { |cell, i|
1099
+ subject.insert_column(5)
1100
+ subject[0].cells.each_with_index { |cell, i|
770
1101
  next if cell.nil?
771
1102
  expect(cell.column).to eq(i)
772
1103
  }
@@ -774,590 +1105,665 @@ describe RubyXL::Worksheet do
774
1105
 
775
1106
  it 'should cause error if a negative argument is passed in' do
776
1107
  expect {
777
- @worksheet.insert_column(-1)
1108
+ subject.insert_column(-1)
778
1109
  }.to raise_error(RuntimeError)
779
1110
  end
780
1111
 
781
- it 'should properly reindex the cells' do
782
- @worksheet.sheet_data.rows.each_with_index { |row, r|
783
- row.cells.each_with_index { |cell, c|
784
- expect(cell.row).to eq(r)
785
- expect(cell.column).to eq(c)
786
- }
1112
+ it 'should properly reindex the cells' do
1113
+ subject.sheet_data.rows.each_with_index { |row, r|
1114
+ if (r == SKIP_ROW_COL) then
1115
+ expect(row).to be_nil
1116
+ else
1117
+ row.cells.each_with_index { |cell, c|
1118
+ if (c == SKIP_ROW_COL) then
1119
+ expect(cell).to be_nil
1120
+ else
1121
+ expect(cell.row).to eq(r)
1122
+ expect(cell.column).to eq(c)
1123
+ end
1124
+ }
1125
+ end
787
1126
  }
788
1127
  end
1128
+
1129
+ describe 'merged_cells updating' do
1130
+ # | A1 | B1 | C1 | D1 |
1131
+ # | A2 | MERGED | D2 |
1132
+ # | A3 | | D3 |
1133
+ # | A4 | B4 | C4 | D4 |
1134
+ before do
1135
+ subject.merge_cells(1, 1, 2, 2)
1136
+ expect(subject.merged_cells.size).to eq 1
1137
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:C3'
1138
+ end
1139
+
1140
+ # | A1 | | B1 | C1 | D1 |
1141
+ # | A2 | | MERGED | D2 |
1142
+ # | A3 | | | D3 |
1143
+ # | A4 | | B4 | C4 | D4 |
1144
+ it 'should updates merged cell when insert before the cell' do
1145
+ subject.insert_column(1)
1146
+ expect(subject.merged_cells.size).to eq 1
1147
+ expect(subject.merged_cells.first.ref.to_s).to eq 'C2:D3'
1148
+ end
1149
+
1150
+ # | A1 | B1 | | C1 | D1 |
1151
+ # | A2 | MERGED | D2 |
1152
+ # | A3 | | D3 |
1153
+ # | A4 | B4 | | C4 | D4 |
1154
+ it 'should updates merged cell when insert into the cell' do
1155
+ subject.insert_column(2)
1156
+ expect(subject.merged_cells.size).to eq 1
1157
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:D3'
1158
+ end
1159
+
1160
+ # | A1 | B1 | C1 | | D1 |
1161
+ # | A2 | MERGED | | D2 |
1162
+ # | A3 | | | D3 |
1163
+ # | A4 | B4 | C4 | | D4 |
1164
+ it 'should not updates merged cell when insert after the cell' do
1165
+ subject.insert_column(3)
1166
+ expect(subject.merged_cells.size).to eq 1
1167
+ expect(subject.merged_cells.first.ref.to_s).to eq 'B2:C3'
1168
+ end
1169
+ end
1170
+
1171
+ it 'should not make empty merged_cells when a worksheet does not have a merged cell' do
1172
+ # If a worksheet has empty merged_cells, the xlsx file has an XML error and has to repair.
1173
+ subject.insert_column(0)
1174
+ expect(subject.merged_cells).to be_nil
1175
+ end
789
1176
  end
790
1177
 
791
1178
  describe '.insert_cell' do
792
1179
  it 'should simply add a cell if no shift argument is specified' do
793
- @worksheet.insert_cell(0,0, 'test')
794
- expect(@worksheet[0][0].value).to eq('test')
795
- expect(@worksheet[0][1].value).to eq('0:1')
796
- expect(@worksheet[1][0].value).to eq('1:0')
1180
+ subject.insert_cell(0, 0, 'test')
1181
+ expect(subject[0][0].value).to eq('test')
1182
+ expect(subject[0][1].value).to eq('1:0')
1183
+ expect(subject[1][0].value).to eq('0:1')
797
1184
  end
798
1185
 
799
1186
  it 'should shift cells to the right if :right is specified' do
800
- @worksheet.insert_cell(0, 0, 'test', nil, :right)
801
- expect(@worksheet[0][0].value).to eq('test')
802
- expect(@worksheet[0][1].value).to eq('0:0')
803
- expect(@worksheet[1][0].value).to eq('1:0')
1187
+ subject.insert_cell(0, 0, 'test', nil, :right)
1188
+ expect(subject[0][0].value).to eq('test')
1189
+ expect(subject[0][1].value).to eq('0:0')
1190
+ expect(subject[1][0].value).to eq('0:1')
804
1191
  end
805
1192
 
806
1193
  it 'should update cell indices after inserting the cell' do
807
- @worksheet.insert_cell(0, 0, 'test', nil, :right)
808
- @worksheet[0].cells.each_with_index { |cell, i|
809
- expect(cell.column).to eq(i)
1194
+ subject.insert_cell(0, 0, 'test', nil, :right)
1195
+ subject.sheet_data.rows.each_with_index { |row, r|
1196
+ if (r == SKIP_ROW_COL) then
1197
+ expect(row).to be_nil
1198
+ else
1199
+ row.cells.each_with_index { |cell, c|
1200
+ if ((r == 0) && (SKIP_ROW_COL + 1 == c)) || ((r != 0) && (c == SKIP_ROW_COL)) then
1201
+ expect(cell).to be_nil
1202
+ else
1203
+ expect(cell.row).to eq(r)
1204
+ expect(cell.column).to eq(c)
1205
+ end
1206
+ }
1207
+ end
810
1208
  }
811
1209
  end
812
1210
 
813
1211
  it 'should shift cells down if :down is specified' do
814
- @worksheet.insert_cell(0, 0, 'test', nil, :down)
815
- expect(@worksheet[0][0].value).to eq('test')
816
- expect(@worksheet[0][1].value).to eq('0:1')
817
- expect(@worksheet[1][0].value).to eq('0:0')
1212
+ subject.insert_cell(0, 0, 'test', nil, :down)
1213
+ expect(subject[0][0].value).to eq('test')
1214
+ expect(subject[0][1].value).to eq('1:0')
1215
+ expect(subject[1][0].value).to eq('0:0')
818
1216
  end
819
1217
 
820
- it 'should cause error if shift argument is specified whcih is not :right or :down' do
1218
+ it 'should cause error if shift argument is specified which is not :right or :down' do
821
1219
  expect {
822
- @worksheet.insert_cell(0, 0, 'test', nil, :up)
1220
+ subject.insert_cell(0, 0, 'test', nil, :up)
823
1221
  }.to raise_error(RuntimeError)
824
1222
  end
825
1223
 
826
1224
  it 'should cause error if a negative argument is passed in' do
827
1225
  expect {
828
- @worksheet.insert_cell(-1, -1)
1226
+ subject.insert_cell(-1, -1)
829
1227
  }.to raise_error(RuntimeError)
830
1228
  end
831
1229
  end
832
1230
 
833
1231
  describe '.delete_cell' do
834
1232
  it 'should make a cell nil if no shift argument specified' do
835
- deleted = @worksheet.delete_cell(0, 0)
836
- expect(@worksheet[0][0]).to be_nil
837
- expect(@old_cell.inspect).to eq(deleted.inspect)
1233
+ old_cell = subject[0][0].inspect
1234
+
1235
+ deleted = subject.delete_cell(0, 0)
1236
+ expect(subject[0][0]).to be_nil
1237
+ expect(old_cell).to eq(deleted.inspect)
838
1238
  end
839
1239
 
840
1240
  it 'should return nil if a cell which is out of range is specified' do
841
- expect(@worksheet.delete_cell(12, 12)).to be_nil
1241
+ expect(subject.delete_cell(12, 12)).to be_nil
842
1242
  end
843
1243
 
844
1244
  it 'should cause error if a negative argument is passed in' do
845
1245
  expect {
846
- @worksheet.delete_cell(-1,-1)
1246
+ subject.delete_cell(-1, -1)
847
1247
  }.to raise_error(RuntimeError)
848
1248
  end
849
1249
 
850
1250
  it 'should shift cells to the right of the deleted cell left if :left is specified' do
851
- @worksheet.delete_cell(0, 0, :left)
852
- expect(@worksheet[0][0].value).to eq('0:1')
1251
+ subject.delete_cell(0, 0, :left)
1252
+ expect(subject[0][0].value).to eq('1:0')
853
1253
  end
854
1254
 
855
1255
  it 'should update cell indices after deleting the cell' do
856
- @worksheet.delete_cell(4, 0, :left)
857
- @worksheet[0].cells.each_with_index { |cell, i|
858
- expect(cell.column).to eq(i)
1256
+ subject.delete_cell(4, 0, :left)
1257
+ subject[0].cells.each_with_index { |cell, i|
1258
+ if i == SKIP_ROW_COL then
1259
+ expect(cell).to be_nil
1260
+ else
1261
+ expect(cell.column).to eq(i)
1262
+ end
859
1263
  }
860
1264
  end
861
1265
 
862
1266
  it 'should shift cells below the deleted cell up if :up is specified' do
863
- @worksheet.delete_cell(0,0,:up)
864
- expect(@worksheet[0][0].value).to eq('1:0')
1267
+ subject.delete_cell(0, 0, :up)
1268
+ expect(subject[0][0].value).to eq('0:1')
865
1269
  end
866
1270
 
867
1271
  it 'should cause en error if an argument other than :left, :up, or nil is specified for shift' do
868
1272
  expect {
869
- @worksheet.delete_cell(0,0,:down)
1273
+ subject.delete_cell(0, 0, :down)
870
1274
  }.to raise_error(RuntimeError)
871
1275
  end
872
1276
  end
873
1277
 
874
1278
  describe '.get_row_fill' do
875
1279
  it 'should return white (ffffff) if no fill color specified for row' do
876
- expect(@worksheet.get_row_fill(0)).to eq('ffffff')
1280
+ expect(subject.get_row_fill(0)).to eq('ffffff')
877
1281
  end
878
1282
 
879
1283
  it 'should correctly reflect fill color if specified for row' do
880
- @worksheet.change_row_fill(0, '000000')
881
- expect(@worksheet.get_row_fill(0)).to eq('000000')
1284
+ subject.change_row_fill(0, '000000')
1285
+ expect(subject.get_row_fill(0)).to eq('000000')
882
1286
  end
883
1287
 
884
1288
  it 'should return nil if a row which does not exist is passed in' do
885
- expect(@worksheet.get_row_fill(11)).to be_nil
1289
+ expect(subject.get_row_fill(11)).to be_nil
886
1290
  end
887
1291
  end
888
1292
 
889
1293
  describe '.get_row_font_name' do
890
1294
  it 'should correctly reflect font name for row' do
891
- @worksheet.change_row_font_name(0, 'Courier')
892
- expect(@worksheet.get_row_font_name(0)).to eq('Courier')
1295
+ subject.change_row_font_name(0, 'Courier')
1296
+ expect(subject.get_row_font_name(0)).to eq('Courier')
893
1297
  end
894
1298
 
895
1299
  it 'should return nil if a (nonnegative) row which does not exist is passed in' do
896
- expect(@worksheet.get_row_font_name(11)).to be_nil
1300
+ expect(subject.get_row_font_name(11)).to be_nil
897
1301
  end
898
1302
  end
899
1303
 
900
1304
  describe '.get_row_font_size' do
901
1305
  it 'should correctly reflect font size for row' do
902
- @worksheet.change_row_font_size(0,30)
903
- expect(@worksheet.get_row_font_size(0)).to eq(30)
1306
+ subject.change_row_font_size(0, 30)
1307
+ expect(subject.get_row_font_size(0)).to eq(30)
904
1308
  end
905
1309
 
906
1310
  it 'should return nil if a (nonnegative) row which does not exist is passed in' do
907
- expect(@worksheet.get_row_font_size(11)).to be_nil
1311
+ expect(subject.get_row_font_size(11)).to be_nil
908
1312
  end
909
1313
  end
910
1314
 
911
1315
  describe '.get_row_font_color' do
912
1316
  it 'should correctly reflect font color for row' do
913
- @worksheet.change_row_font_color(0, '0f0f0f')
914
- expect(@worksheet.get_row_font_color(0)).to eq('0f0f0f')
1317
+ subject.change_row_font_color(0, '0f0f0f')
1318
+ expect(subject.get_row_font_color(0)).to eq('0f0f0f')
915
1319
  end
916
1320
 
917
1321
  it 'should return nil if a (nonnegative) row which does not exist is passed in' do
918
- expect(@worksheet.get_row_font_color(11)).to be_nil
1322
+ expect(subject.get_row_font_color(11)).to be_nil
919
1323
  end
920
1324
  end
921
1325
 
922
1326
  describe '.is_row_italicized' do
923
1327
  it 'should correctly return whether row is italicized' do
924
- @worksheet.change_row_italics(0, true)
925
- expect(@worksheet.is_row_italicized(0)).to eq(true)
1328
+ subject.change_row_italics(0, true)
1329
+ expect(subject.is_row_italicized(0)).to eq(true)
926
1330
  end
927
1331
 
928
1332
  it 'should return nil if a (nonnegative) row which does not exist is passed in' do
929
- expect(@worksheet.is_row_italicized(11)).to be_nil
1333
+ expect(subject.is_row_italicized(11)).to be_nil
930
1334
  end
931
1335
  end
932
1336
 
933
1337
  describe '.is_row_bolded' do
934
1338
  it 'should correctly return whether row is bolded' do
935
- @worksheet.change_row_bold(0, true)
936
- expect(@worksheet.is_row_bolded(0)).to eq(true)
1339
+ subject.change_row_bold(0, true)
1340
+ expect(subject.is_row_bolded(0)).to eq(true)
937
1341
  end
938
1342
 
939
1343
  it 'should return nil if a (nonnegative) row which does not exist is passed in' do
940
- expect(@worksheet.is_row_bolded(11)).to be_nil
1344
+ expect(subject.is_row_bolded(11)).to be_nil
941
1345
  end
942
1346
  end
943
1347
 
944
1348
  describe '.is_row_underlined' do
945
1349
  it 'should correctly return whether row is underlined' do
946
- @worksheet.change_row_underline(0, true)
947
- expect(@worksheet.is_row_underlined(0)).to eq(true)
1350
+ subject.change_row_underline(0, true)
1351
+ expect(subject.is_row_underlined(0)).to eq(true)
948
1352
  end
949
1353
 
950
1354
  it 'should return nil if a (nonnegative) row which does not exist is passed in' do
951
- expect(@worksheet.is_row_underlined(11)).to be_nil
1355
+ expect(subject.is_row_underlined(11)).to be_nil
952
1356
  end
953
1357
  end
954
1358
 
955
1359
  describe '.is_row_struckthrough' do
956
1360
  it 'should correctly return whether row is struckthrough' do
957
- @worksheet.change_row_strikethrough(0, true)
958
- expect(@worksheet.is_row_struckthrough(0)).to eq(true)
1361
+ subject.change_row_strikethrough(0, true)
1362
+ expect(subject.is_row_struckthrough(0)).to eq(true)
959
1363
  end
960
1364
 
961
1365
  it 'should return nil if a (nonnegative) row which does not exist is passed in' do
962
- expect(@worksheet.is_row_struckthrough(11)).to be_nil
1366
+ expect(subject.is_row_struckthrough(11)).to be_nil
963
1367
  end
964
1368
  end
965
1369
 
966
1370
  describe '.get_row_height' do
967
1371
  it 'should return 13 if no height specified for row' do
968
- expect(@worksheet.get_row_height(0)).to eq(13)
1372
+ expect(subject.get_row_height(0)).to eq(13)
969
1373
  end
970
1374
 
971
1375
  it 'should correctly reflect height if specified for row' do
972
- @worksheet.change_row_height(0, 30)
973
- expect(@worksheet.get_row_height(0)).to eq(30)
1376
+ subject.change_row_height(0, 30)
1377
+ expect(subject.get_row_height(0)).to eq(30)
974
1378
  end
975
1379
 
976
1380
  it 'should return default row height if a row which does not exist is passed in' do
977
- expect(@worksheet.get_row_height(11)).to eq(13)
1381
+ expect(subject.get_row_height(11)).to eq(13)
978
1382
  end
979
1383
 
980
1384
  it 'should cause error if a negative argument is passed in' do
981
1385
  expect {
982
- @worksheet.get_row_height(-1)
1386
+ subject.get_row_height(-1)
983
1387
  }.to raise_error(RuntimeError)
984
1388
  end
985
1389
  end
986
1390
 
987
1391
  describe '.get_row_alignment' do
988
- it 'should cause error if a negative argument is passed in' do
989
- expect {
990
- @worksheet.get_row_alignment(-1, true)
991
- }.to raise_error(RuntimeError)
992
- end
993
-
994
1392
  it 'should return nil if no horizontal alignment specified for row' do
995
- expect(@worksheet.get_row_alignment(0, true)).to be_nil
1393
+ expect(subject.get_row_alignment(0, true)).to be_nil
996
1394
  end
997
1395
 
998
1396
  it 'should return nil if a row which does not exist is passed in' do
999
- expect(@worksheet.get_row_alignment(11, true)).to be_nil
1397
+ expect(subject.get_row_alignment(11, true)).to be_nil
1000
1398
  end
1001
1399
 
1002
1400
  it 'should return correct horizontal alignment if it is set for that row' do
1003
- @worksheet.change_row_horizontal_alignment(0, 'center')
1004
- expect(@worksheet.get_row_alignment(0, true)).to eq('center')
1401
+ subject.change_row_horizontal_alignment(0, 'center')
1402
+ expect(subject.get_row_alignment(0, true)).to eq('center')
1005
1403
  end
1006
1404
 
1007
1405
  it 'should return nil if no alignment specified for row' do
1008
- expect(@worksheet.get_row_alignment(0, false)).to be_nil
1406
+ expect(subject.get_row_alignment(0, false)).to be_nil
1009
1407
  end
1010
1408
 
1011
1409
  it 'should return nil if a row which does not exist is passed in' do
1012
- expect(@worksheet.get_row_alignment(11, false)).to be_nil
1410
+ expect(subject.get_row_alignment(11, false)).to be_nil
1013
1411
  end
1014
1412
 
1015
1413
  it 'should return correct vertical alignment if it is set for that row' do
1016
- @worksheet.change_row_vertical_alignment(0, 'center')
1017
- expect(@worksheet.get_row_alignment(0, false)).to eq('center')
1414
+ subject.change_row_vertical_alignment(0, 'center')
1415
+ expect(subject.get_row_alignment(0, false)).to eq('center')
1018
1416
  end
1019
1417
  end
1020
1418
 
1021
1419
  describe '.get_row_border' do
1022
1420
  it 'should return nil if no border is specified for that row in that direction' do
1023
- expect(@worksheet.get_row_border(0, :top)).to be_nil
1421
+ expect(subject.get_row_border(0, :top)).to be_nil
1024
1422
  end
1025
1423
 
1026
1424
  it 'should return type of border that this row has on top' do
1027
- @worksheet.change_row_border(0, :top, 'thin')
1028
- expect(@worksheet.get_row_border(0, :top)).to eq('thin')
1029
- end
1030
-
1031
- it 'should cause error if a negative argument is passed in' do
1032
- expect {
1033
- @worksheet.get_row_border(-1, :top)
1034
- }.to raise_error(RuntimeError)
1425
+ subject.change_row_border(0, :top, 'thin')
1426
+ expect(subject.get_row_border(0, :top)).to eq('thin')
1035
1427
  end
1036
1428
 
1037
1429
  it 'should return nil if a row which does not exist is passed in' do
1038
- expect(@worksheet.get_row_border(11, :top)).to be_nil
1430
+ expect(subject.get_row_border(11, :top)).to be_nil
1039
1431
  end
1040
1432
  end
1041
1433
 
1042
1434
  describe '.get_column_font_name' do
1043
1435
  it 'should correctly reflect font name for column' do
1044
- @worksheet.change_column_font_name(0, 'Courier')
1045
- expect(@worksheet.get_column_font_name(0)).to eq('Courier')
1436
+ subject.change_column_font_name(0, 'Courier')
1437
+ expect(subject.get_column_font_name(0)).to eq('Courier')
1046
1438
  end
1047
1439
 
1048
1440
  it 'should cause error if a negative argument is passed in' do
1049
1441
  expect {
1050
- @worksheet.get_column_font_name(-1)
1442
+ subject.get_column_font_name(-1)
1051
1443
  }.to raise_error(RuntimeError)
1052
1444
  end
1053
1445
 
1054
1446
  it 'should return default font if a (nonnegative) column which does not exist is passed in' do
1055
- expect(@worksheet.get_column_font_name(11)).to eq('Verdana')
1447
+ expect(subject.get_column_font_name(11)).to eq('Verdana')
1056
1448
  end
1057
1449
  end
1058
1450
 
1059
1451
  describe '.get_column_font_size' do
1060
1452
  it 'should correctly reflect font size for column' do
1061
- @worksheet.change_column_font_size(0,30)
1062
- expect(@worksheet.get_column_font_size(0)).to eq(30)
1453
+ subject.change_column_font_size(0, 30)
1454
+ expect(subject.get_column_font_size(0)).to eq(30)
1063
1455
  end
1064
1456
 
1065
1457
  it 'should cause error if a negative argument is passed in' do
1066
1458
  expect {
1067
- @worksheet.get_column_font_size(-1)
1459
+ subject.get_column_font_size(-1)
1068
1460
  }.to raise_error(RuntimeError)
1069
1461
  end
1070
1462
 
1071
1463
  it 'should return default font size if a column which does not exist is passed in' do
1072
- expect(@worksheet.get_column_font_size(11)).to eq(10)
1464
+ expect(subject.get_column_font_size(11)).to eq(10)
1073
1465
  end
1074
1466
  end
1075
1467
 
1076
1468
  describe '.get_column_font_color' do
1077
1469
  it 'should correctly reflect font color for column' do
1078
- @worksheet.change_column_font_color(0, '0f0f0f')
1079
- expect(@worksheet.get_column_font_color(0)).to eq('0f0f0f')
1470
+ subject.change_column_font_color(0, '0f0f0f')
1471
+ expect(subject.get_column_font_color(0)).to eq('0f0f0f')
1080
1472
  end
1081
1473
 
1082
1474
  it 'should cause error if a negative argument is passed in' do
1083
1475
  expect {
1084
- @worksheet.get_column_font_color(-1)
1476
+ subject.get_column_font_color(-1)
1085
1477
  }.to raise_error(RuntimeError)
1086
1478
  end
1087
1479
 
1088
1480
  it 'should return default color (000000) if a (nonnegative) column which does not exist is passed in' do
1089
- expect(@worksheet.get_column_font_color(11)).to eq('000000')
1481
+ expect(subject.get_column_font_color(11)).to eq('000000')
1090
1482
  end
1091
1483
 
1092
1484
  it 'should return default color (000000) if no rgb font color is specified' do
1093
- expect(@worksheet.get_column_font_color(0)).to eq('000000')
1485
+ expect(subject.get_column_font_color(0)).to eq('000000')
1094
1486
  end
1095
1487
  end
1096
1488
 
1097
1489
  describe '.is_column_italicized' do
1098
1490
  it 'should correctly return whether column is italicized' do
1099
- @worksheet.change_column_italics(0, true)
1100
- expect(@worksheet.is_column_italicized(0)).to eq(true)
1491
+ subject.change_column_italics(0, true)
1492
+ expect(subject.is_column_italicized(0)).to eq(true)
1101
1493
  end
1102
1494
 
1103
1495
  it 'should cause error if a negative argument is passed in' do
1104
1496
  expect {
1105
- @worksheet.is_column_italicized(-1)
1497
+ subject.is_column_italicized(-1)
1106
1498
  }.to raise_error(RuntimeError)
1107
1499
  end
1108
1500
 
1109
1501
  it 'should return nil if a (nonnegative) column which does not exist is passed in' do
1110
- expect(@worksheet.is_column_italicized(11)).to be_nil
1502
+ expect(subject.is_column_italicized(11)).to be_nil
1111
1503
  end
1112
1504
  end
1113
1505
 
1114
1506
  describe '.is_column_bolded' do
1115
1507
  it 'should correctly return whether column is bolded' do
1116
- @worksheet.change_column_bold(0, true)
1117
- expect(@worksheet.is_column_bolded(0)).to eq(true)
1508
+ subject.change_column_bold(0, true)
1509
+ expect(subject.is_column_bolded(0)).to eq(true)
1118
1510
  end
1119
1511
 
1120
1512
  it 'should cause error if a negative argument is passed in' do
1121
1513
  expect {
1122
- @worksheet.is_column_bolded(-1)
1514
+ subject.is_column_bolded(-1)
1123
1515
  }.to raise_error(RuntimeError)
1124
1516
  end
1125
1517
 
1126
1518
  it 'should return nil if a (nonnegative) column which does not exist is passed in' do
1127
- expect(@worksheet.is_column_bolded(11)).to be_nil
1519
+ expect(subject.is_column_bolded(11)).to be_nil
1128
1520
  end
1129
1521
  end
1130
1522
 
1131
1523
  describe '.is_column_underlined' do
1132
1524
  it 'should correctly return whether column is underlined' do
1133
- @worksheet.change_column_underline(0, true)
1134
- expect(@worksheet.is_column_underlined(0)).to eq(true)
1525
+ subject.change_column_underline(0, true)
1526
+ expect(subject.is_column_underlined(0)).to eq(true)
1135
1527
  end
1136
1528
 
1137
1529
  it 'should cause error if a negative argument is passed in' do
1138
1530
  expect {
1139
- @worksheet.is_column_underlined(-1)
1531
+ subject.is_column_underlined(-1)
1140
1532
  }.to raise_error(RuntimeError)
1141
1533
  end
1142
1534
 
1143
1535
  it 'should return nil if a (nonnegative) column which does not exist is passed in' do
1144
- expect(@worksheet.is_column_underlined(11)).to be_nil
1536
+ expect(subject.is_column_underlined(11)).to be_nil
1145
1537
  end
1146
1538
  end
1147
1539
 
1148
1540
  describe '.is_column_struckthrough' do
1149
1541
  it 'should correctly return whether column is struckthrough' do
1150
- @worksheet.change_column_strikethrough(0, true)
1151
- expect(@worksheet.is_column_struckthrough(0)).to eq(true)
1542
+ subject.change_column_strikethrough(0, true)
1543
+ expect(subject.is_column_struckthrough(0)).to eq(true)
1152
1544
  end
1153
1545
 
1154
1546
  it 'should cause error if a negative argument is passed in' do
1155
1547
  expect {
1156
- @worksheet.is_column_struckthrough(-1)
1548
+ subject.is_column_struckthrough(-1)
1157
1549
  }.to raise_error(RuntimeError)
1158
1550
  end
1159
1551
 
1160
1552
  it 'should return nil if a (nonnegative) column which does not exist is passed in' do
1161
- expect(@worksheet.is_column_struckthrough(11)).to be_nil
1553
+ expect(subject.is_column_struckthrough(11)).to be_nil
1162
1554
  end
1163
1555
  end
1164
1556
 
1165
1557
  describe '.get_column_width_raw' do
1166
1558
  it 'should return nil if no width specified for column' do
1167
- expect(@worksheet.get_column_width_raw(0)).to be_nil
1559
+ expect(subject.get_column_width_raw(0)).to be_nil
1168
1560
  end
1169
1561
 
1170
1562
  it 'should correctly reflect width if specified for column' do
1171
- @worksheet.change_column_width_raw(0, 30.123)
1172
- expect(@worksheet.get_column_width_raw(0)).to eq(30.123)
1563
+ subject.change_column_width_raw(0, 30.123)
1564
+ expect(subject.get_column_width_raw(0)).to eq(30.123)
1173
1565
  end
1174
1566
 
1175
1567
  it 'should return nil for a column that does not exist' do
1176
- expect(@worksheet.get_column_width_raw(11)).to be_nil
1568
+ expect(subject.get_column_width_raw(11)).to be_nil
1177
1569
  end
1178
1570
 
1179
1571
  it 'should cause error if a negative argument is passed in' do
1180
1572
  expect {
1181
- @worksheet.get_column_width_raw(-1)
1573
+ subject.get_column_width_raw(-1)
1182
1574
  }.to raise_error(RuntimeError)
1183
1575
  end
1184
1576
  end
1185
1577
 
1186
1578
  describe '.get_column_width' do
1187
1579
  it 'should return default width if no width specified for column' do
1188
- expect(@worksheet.get_column_width(0)).to eq(RubyXL::ColumnRange::DEFAULT_WIDTH)
1580
+ expect(subject.get_column_width(0)).to eq(RubyXL::ColumnRange::DEFAULT_WIDTH)
1189
1581
  end
1190
1582
 
1191
1583
  it 'should correctly reflect width if specified for column' do
1192
- @worksheet.change_column_width(0, 15)
1193
- expect(@worksheet.get_column_width(0)).to eq(15)
1584
+ subject.change_column_width(0, 15)
1585
+ expect(subject.get_column_width(0)).to eq(15)
1194
1586
  end
1195
1587
 
1196
1588
  it 'should return default width for a column that does not exist' do
1197
- expect(@worksheet.get_column_width(11)).to eq(RubyXL::ColumnRange::DEFAULT_WIDTH)
1589
+ expect(subject.get_column_width(11)).to eq(RubyXL::ColumnRange::DEFAULT_WIDTH)
1198
1590
  end
1199
1591
 
1200
1592
  it 'should cause error if a negative argument is passed in' do
1201
1593
  expect {
1202
- @worksheet.get_column_width(-1)
1594
+ subject.get_column_width(-1)
1203
1595
  }.to raise_error(RuntimeError)
1204
1596
  end
1205
1597
  end
1206
1598
 
1207
1599
  describe '.get_column_fill' do
1208
1600
  it 'should return white (ffffff) if no fill color specified for column' do
1209
- expect(@worksheet.get_column_fill(0)).to eq('ffffff')
1601
+ expect(subject.get_column_fill(0)).to eq('ffffff')
1210
1602
  end
1211
1603
 
1212
1604
  it 'should correctly reflect fill color if specified for column' do
1213
- @worksheet.change_column_fill(0, '000000')
1214
- expect(@worksheet.get_column_fill(0)).to eq('000000')
1605
+ subject.change_column_fill(0, '000000')
1606
+ expect(subject.get_column_fill(0)).to eq('000000')
1215
1607
  end
1216
1608
 
1217
1609
  it 'should return nil if a column which does not exist is passed in' do
1218
- expect(@worksheet.get_column_fill(11)).to eq('ffffff')
1610
+ expect(subject.get_column_fill(11)).to eq('ffffff')
1219
1611
  end
1220
1612
 
1221
1613
  it 'should cause error if a negative argument is passed in' do
1222
1614
  expect {
1223
- @worksheet.get_column_fill(-1)
1615
+ subject.get_column_fill(-1)
1224
1616
  }.to raise_error(RuntimeError)
1225
1617
  end
1226
1618
  end
1227
1619
 
1228
1620
  describe '.get_column_horizontal_alignment' do
1229
1621
  it 'should return nil if no alignment specified for column' do
1230
- expect(@worksheet.get_column_alignment(0, :horizontal)).to be_nil
1622
+ expect(subject.get_column_alignment(0, :horizontal)).to be_nil
1231
1623
  end
1232
1624
 
1233
1625
  it 'should return nil if a column which does not exist is passed in' do
1234
- expect(@worksheet.get_column_alignment(11, :horizontal)).to be_nil
1626
+ expect(subject.get_column_alignment(11, :horizontal)).to be_nil
1235
1627
  end
1236
1628
 
1237
1629
  it 'should cause error if a negative argument is passed in' do
1238
1630
  expect {
1239
- @worksheet.get_column_alignment(-1, :horizontal)
1631
+ subject.get_column_alignment(-1, :horizontal)
1240
1632
  }.to raise_error(RuntimeError)
1241
1633
  end
1242
1634
 
1243
1635
  it 'should return correct horizontal alignment if it is set for that column' do
1244
- @worksheet.change_column_horizontal_alignment(0, 'center')
1245
- expect(@worksheet.get_column_alignment(0, :horizontal)).to eq('center')
1636
+ subject.change_column_horizontal_alignment(0, 'center')
1637
+ expect(subject.get_column_alignment(0, :horizontal)).to eq('center')
1246
1638
  end
1247
1639
  end
1248
1640
 
1249
1641
  describe '.get_column_vertical_alignment' do
1250
1642
  it 'should return nil if no alignment specified for column' do
1251
- expect(@worksheet.get_column_alignment(0, :vertical)).to be_nil
1643
+ expect(subject.get_column_alignment(0, :vertical)).to be_nil
1252
1644
  end
1253
1645
 
1254
1646
  it 'should return nil if a column which does not exist is passed in' do
1255
- expect(@worksheet.get_column_alignment(11, :vertical)).to be_nil
1647
+ expect(subject.get_column_alignment(11, :vertical)).to be_nil
1256
1648
  end
1257
1649
 
1258
1650
  it 'should cause error if a negative argument is passed in' do
1259
1651
  expect {
1260
- @worksheet.get_column_alignment(-1, :vertical)
1652
+ subject.get_column_alignment(-1, :vertical)
1261
1653
  }.to raise_error(RuntimeError)
1262
1654
  end
1263
1655
 
1264
1656
  it 'should return correct vertical alignment if it is set for that column' do
1265
- @worksheet.change_column_vertical_alignment(0, 'center')
1266
- expect(@worksheet.get_column_alignment(0, :vertical)).to eq('center')
1657
+ subject.change_column_vertical_alignment(0, 'center')
1658
+ expect(subject.get_column_alignment(0, :vertical)).to eq('center')
1267
1659
  end
1268
1660
  end
1269
1661
 
1270
1662
  describe '.get_column_border' do
1271
1663
  it 'should return nil if no border is specified for that column in that direction' do
1272
- expect(@worksheet.get_column_border(0, :diagonal)).to be_nil
1664
+ expect(subject.get_column_border(0, :diagonal)).to be_nil
1273
1665
  end
1274
1666
 
1275
1667
  it 'should return type of border that this column has on diagonal' do
1276
- @worksheet.change_column_border(0, :diagonal, 'thin')
1277
- expect(@worksheet.get_column_border(0, :diagonal)).to eq('thin')
1668
+ subject.change_column_border(0, :diagonal, 'thin')
1669
+ expect(subject.get_column_border(0, :diagonal)).to eq('thin')
1278
1670
  end
1279
1671
 
1280
1672
  it 'should cause error if a negative argument is passed in' do
1281
1673
  expect {
1282
- @worksheet.get_column_border(-1, :diagonal)
1674
+ subject.get_column_border(-1, :diagonal)
1283
1675
  }.to raise_error(RuntimeError)
1284
1676
  end
1285
1677
 
1286
1678
  it 'should return nil if a column which does not exist is passed in' do
1287
- expect(@worksheet.get_column_border(11, :diagonal)).to be_nil
1679
+ expect(subject.get_column_border(11, :diagonal)).to be_nil
1288
1680
  end
1289
1681
  end
1290
1682
 
1291
1683
  describe '@column_range' do
1292
1684
  it 'should properly handle range addition and modification' do
1293
1685
  # Ranges should be empty for brand new worskeet
1294
- expect(@worksheet.cols.size).to eq(0)
1686
+ expect(subject.cols.size).to eq(0)
1295
1687
 
1296
1688
  # Range should be created if the column has not been touched before
1297
- @worksheet.change_column_width(0, 30)
1298
- expect(@worksheet.get_column_width(0)).to eq(30)
1299
- expect(@worksheet.cols.size).to eq(1)
1689
+ subject.change_column_width(0, 30)
1690
+ expect(subject.get_column_width(0)).to eq(30)
1691
+ expect(subject.cols.size).to eq(1)
1300
1692
 
1301
1693
  # Existing range should be reused
1302
- @worksheet.change_column_width(0, 20)
1303
- expect(@worksheet.get_column_width(0)).to eq(20)
1304
- expect(@worksheet.cols.size).to eq(1)
1694
+ subject.change_column_width(0, 20)
1695
+ expect(subject.get_column_width(0)).to eq(20)
1696
+ expect(subject.cols.size).to eq(1)
1305
1697
 
1306
1698
  # Creation of the new range should not affect previously changed columns
1307
- @worksheet.change_column_width(1, 30)
1308
- expect(@worksheet.get_column_width(1)).to eq(30)
1309
- expect(@worksheet.get_column_width(0)).to eq(20)
1310
- expect(@worksheet.cols.size).to eq(2)
1699
+ subject.change_column_width(1, 30)
1700
+ expect(subject.get_column_width(1)).to eq(30)
1701
+ expect(subject.get_column_width(0)).to eq(20)
1702
+ expect(subject.cols.size).to eq(2)
1311
1703
 
1312
- @worksheet.cols.clear
1313
- @worksheet.cols << RubyXL::ColumnRange.new(:min => 1, :max => 9, :width => 33) # Note that this is raw width
1704
+ subject.cols.clear
1705
+ subject.cols << RubyXL::ColumnRange.new(:min => 1, :max => 9, :width => 33) # Note that this is raw width
1314
1706
 
1315
- r = @worksheet.cols.locate_range(3)
1707
+ r = subject.cols.locate_range(3)
1316
1708
  expect(r.min).to eq(1)
1317
1709
  expect(r.max).to eq(9)
1318
1710
 
1319
1711
  # When a column is modified at the beginning of the range, it should shrink to the right
1320
- @worksheet.change_column_width(0, 20)
1321
- expect(@worksheet.cols.size).to eq(2)
1322
- expect(@worksheet.get_column_width(0)).to eq(20)
1323
- expect(@worksheet.get_column_width(1)).to eq(32)
1712
+ subject.change_column_width(0, 20)
1713
+ expect(subject.cols.size).to eq(2)
1714
+ expect(subject.get_column_width(0)).to eq(20)
1715
+ expect(subject.get_column_width(1)).to eq(32)
1324
1716
 
1325
- r = @worksheet.cols.locate_range(3)
1717
+ r = subject.cols.locate_range(3)
1326
1718
  expect(r.min).to eq(2)
1327
1719
  expect(r.max).to eq(9)
1328
1720
 
1329
1721
  # When a column is modified at the beginning of the range, it should shrink to the left
1330
- @worksheet.change_column_width(8, 30)
1331
- expect(@worksheet.cols.size).to eq(3)
1332
- expect(@worksheet.get_column_width(8)).to eq(30)
1722
+ subject.change_column_width(8, 30)
1723
+ expect(subject.cols.size).to eq(3)
1724
+ expect(subject.get_column_width(8)).to eq(30)
1333
1725
 
1334
- r = @worksheet.cols.locate_range(3)
1726
+ r = subject.cols.locate_range(3)
1335
1727
  expect(r.min).to eq(2)
1336
1728
  expect(r.max).to eq(8)
1337
1729
 
1338
1730
  # When a column is modified in the middle of the range, it should split into two
1339
- @worksheet.change_column_width(4, 15)
1340
- expect(@worksheet.cols.size).to eq(5)
1341
- expect(@worksheet.get_column_width(3)).to eq(32)
1731
+ subject.change_column_width(4, 15)
1732
+ expect(subject.cols.size).to eq(5)
1733
+ expect(subject.get_column_width(3)).to eq(32)
1342
1734
 
1343
- r = @worksheet.cols.locate_range(2)
1735
+ r = subject.cols.locate_range(2)
1344
1736
  expect(r.min).to eq(2)
1345
1737
  expect(r.max).to eq(4)
1346
1738
 
1347
- expect(@worksheet.get_column_width(4)).to eq(15)
1739
+ expect(subject.get_column_width(4)).to eq(15)
1348
1740
 
1349
- r = @worksheet.cols.locate_range(4)
1741
+ r = subject.cols.locate_range(4)
1350
1742
  expect(r.min).to eq(5)
1351
1743
  expect(r.max).to eq(5)
1352
1744
 
1353
- expect(@worksheet.get_column_width(5)).to eq(32)
1745
+ expect(subject.get_column_width(5)).to eq(32)
1354
1746
 
1355
- r = @worksheet.cols.locate_range(6)
1747
+ r = subject.cols.locate_range(6)
1356
1748
  expect(r.min).to eq(6)
1357
1749
  expect(r.max).to eq(8)
1750
+ end
1751
+ end
1358
1752
 
1753
+ describe 'forbidden sheet names' do
1754
+ it 'should stream a workbook successfully' do
1755
+ subject.sheet_name = 'Test Name'
1756
+ subject.workbook.stream
1359
1757
  end
1360
1758
 
1361
- end
1759
+ it 'should throw an error when forbidden characters are used in the sheet name' do
1760
+ subject.sheet_name = 'Some [Special] Name'
1761
+ expect { subject.workbook.stream }.to raise_error(RuntimeError)
1762
+ end
1362
1763
 
1764
+ it 'should throw an error when forbidden name is used' do
1765
+ subject.sheet_name = 'History'
1766
+ expect { subject.workbook.stream }.to raise_error(RuntimeError)
1767
+ end
1768
+ end
1363
1769
  end