From c8c63518b4d58ca8875f81602792050cbec318f2 Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Wed, 23 Nov 2011 21:45:54 +0900 Subject: Adding image support and some document clean up for .8 release --- .yardoc/checksums | 34 +- .yardoc/objects/root.dat | Bin 427683 -> 452703 bytes .yardops | 4 +- README.md | 22 +- doc/Axlsx.html | 156 ++- doc/Axlsx/App.html | 2 +- doc/Axlsx/Axis.html | 2 +- doc/Axlsx/Bar3DChart.html | 2 +- doc/Axlsx/BarSeries.html | 2 +- doc/Axlsx/Border.html | 2 +- doc/Axlsx/BorderPr.html | 2 +- doc/Axlsx/CatAxis.html | 2 +- doc/Axlsx/CatAxisData.html | 12 +- doc/Axlsx/Cell.html | 2 +- doc/Axlsx/CellAlignment.html | 2 +- doc/Axlsx/CellProtection.html | 2 +- doc/Axlsx/CellStyle.html | 2 +- doc/Axlsx/Chart.html | 32 +- doc/Axlsx/Color.html | 2 +- doc/Axlsx/ContentType.html | 2 +- doc/Axlsx/Core.html | 2 +- doc/Axlsx/DataTypeValidator.html | 2 +- doc/Axlsx/Default.html | 2 +- doc/Axlsx/Drawing.html | 308 ++++-- doc/Axlsx/Fill.html | 2 +- doc/Axlsx/Font.html | 2 +- doc/Axlsx/GradientFill.html | 2 +- doc/Axlsx/GradientStop.html | 2 +- doc/Axlsx/GraphicFrame.html | 42 +- doc/Axlsx/Line3DChart.html | 2 +- doc/Axlsx/LineSeries.html | 14 +- doc/Axlsx/Marker.html | 2 +- doc/Axlsx/NumFmt.html | 2 +- doc/Axlsx/OneCellAnchor.html | 988 +++++++++++++++++++ doc/Axlsx/Override.html | 2 +- doc/Axlsx/Package.html | 202 ++-- doc/Axlsx/PatternFill.html | 2 +- doc/Axlsx/Pic.html | 1532 +++++++++++++++++++++++++++++ doc/Axlsx/Pie3DChart.html | 12 +- doc/Axlsx/PieSeries.html | 2 +- doc/Axlsx/RegexValidator.html | 2 +- doc/Axlsx/Relationship.html | 12 +- doc/Axlsx/Relationships.html | 2 +- doc/Axlsx/RestrictionValidator.html | 2 +- doc/Axlsx/Row.html | 2 +- doc/Axlsx/Scaling.html | 2 +- doc/Axlsx/SerAxis.html | 2 +- doc/Axlsx/Series.html | 2 +- doc/Axlsx/SeriesTitle.html | 2 +- doc/Axlsx/SimpleTypedList.html | 2 +- doc/Axlsx/Styles.html | 2 +- doc/Axlsx/TableStyle.html | 2 +- doc/Axlsx/TableStyleElement.html | 2 +- doc/Axlsx/TableStyles.html | 2 +- doc/Axlsx/Title.html | 2 +- doc/Axlsx/TwoCellAnchor.html | 226 +++-- doc/Axlsx/ValAxis.html | 2 +- doc/Axlsx/ValAxisData.html | 2 +- doc/Axlsx/View3D.html | 2 +- doc/Axlsx/Workbook.html | 198 +++- doc/Axlsx/Worksheet.html | 207 +++- doc/Axlsx/Xf.html | 2 +- doc/_index.html | 16 +- doc/class_list.html | 2 +- doc/file.README.html | 33 +- doc/index.html | 33 +- doc/method_list.html | 934 +++++++++++------- doc/top-level-namespace.html | 2 +- examples/example.rb | 13 + examples/image1.gif | Bin 0 -> 238879 bytes examples/image1.jpeg | Bin 0 -> 82255 bytes examples/image1.jpg | Bin 0 -> 142628 bytes examples/image1.png | Bin 0 -> 475939 bytes lib/axlsx/drawing/bar_series.rb | 1 - lib/axlsx/drawing/cat_axis_data.rb | 1 + lib/axlsx/drawing/chart.rb | 1 - lib/axlsx/drawing/drawing.rb | 38 +- lib/axlsx/drawing/graphic_frame.rb | 2 - lib/axlsx/drawing/line_series.rb | 1 - lib/axlsx/drawing/one_cell_anchor.rb | 89 ++ lib/axlsx/drawing/pic.rb | 158 +++ lib/axlsx/drawing/pie_3D_chart.rb | 1 - lib/axlsx/drawing/two_cell_anchor.rb | 21 +- lib/axlsx/package.rb | 36 +- lib/axlsx/rels/relationship.rb | 3 +- lib/axlsx/util/constants.rb | 24 + lib/axlsx/util/validators.rb | 4 +- lib/axlsx/version.rb | 2 +- lib/axlsx/workbook/workbook.rb | 8 + lib/axlsx/workbook/worksheet/worksheet.rb | 11 +- test/drawing/tc_drawing.rb | 11 +- test/drawing/tc_one_cell_anchor.rb | 67 ++ test/drawing/tc_pic.rb | 71 ++ test/tc_package.rb | 2 - 94 files changed, 4853 insertions(+), 821 deletions(-) create mode 100644 doc/Axlsx/OneCellAnchor.html create mode 100644 doc/Axlsx/Pic.html create mode 100644 examples/image1.gif create mode 100644 examples/image1.jpeg create mode 100644 examples/image1.jpg create mode 100644 examples/image1.png create mode 100644 lib/axlsx/drawing/one_cell_anchor.rb create mode 100644 lib/axlsx/drawing/pic.rb create mode 100644 test/drawing/tc_one_cell_anchor.rb create mode 100644 test/drawing/tc_pic.rb diff --git a/.yardoc/checksums b/.yardoc/checksums index 4281ee7b..ef718f71 100644 --- a/.yardoc/checksums +++ b/.yardoc/checksums @@ -1,56 +1,58 @@ lib/axlsx/stylesheet/table_styles.rb 04b778652c29d612f63e93080d06c3936e48d765 lib/axlsx/stylesheet/table_style.rb b592135b8b02969a29bd24c28a13282f6af76f30 -lib/axlsx/drawing/pie_3D_chart.rb 9370e48b73000c96ebd50712dc4b4a958ad8527d +lib/axlsx/drawing/pie_3D_chart.rb f9c70bd12b697dcd51780f29c037d4659b48e479 lib/axlsx/stylesheet/border_pr.rb 09dcb61ec7b0cf49f2da4c4f8ccba8f7e0df7b07 lib/axlsx/stylesheet/color.rb 4927aaebe27dda42d78bb7baf9a44edc1753c77f +lib/axlsx/util/constants.rb 4dc8b1d765aa0593615a14c3761b0183be308908 lib/axlsx/drawing/marker.rb 3507738522c02a3733a01f115d9ef22fae4ea542 -lib/axlsx/util/constants.rb 20e4a98177305d407b77eb62f0bca5ecc29b234c lib/axlsx/stylesheet/cell_protection.rb ce494f9add6de0a51407ddd9122fffe95759a48a lib/axlsx/stylesheet/cell_style.rb 46c6ff183bce5c6b1ab6228823257d638007b03c lib/axlsx/drawing/series_title.rb 8f088942649b5b5cc351b621bf8fb252f33cb510 -lib/axlsx/drawing/line_series.rb ada7cbca0d561c2e2f6bad56c1eb5d8ea2c1f071 +lib/axlsx/drawing/line_series.rb ffcd6d010ea0606f54a543eb1fc61022aac129d7 lib/axlsx/drawing/series.rb 1cf010706e32e7e51affbc9edb9d4862a26b33ef -lib/axlsx/package.rb eea7499e09e0936eeb8e08d10823f05990722023 +lib/axlsx/package.rb 339a8e5650f45623b126efddd22d3a5f0655aad9 lib/axlsx/stylesheet/cell_alignment.rb f67f6a0bc16bf13669ed7b18714e4de23825ed94 lib/axlsx/content_type/default.rb 8ec0d9d1e6bf261735739823acd460c271e3f5ed lib/axlsx/drawing/title.rb b46fb082e3bea936d129c8aa0998f3b71c9838cc lib/axlsx/drawing/axis.rb 5e37bac9f4dd258265213d5621522eed3c614954 lib/axlsx/stylesheet/table_style_element.rb bee66d743e3113fb14adc7ebdecbeb606bfb49fc lib/axlsx/content_type/content_type.rb 6c576e1618f99f7163fffa6b6e89e964653dcb5f -lib/axlsx/stylesheet/num_fmt.rb dc830c6540465afa824881efa2f1ce4070957c47 lib/axlsx/rels/relationships.rb 9c741e180796259bb378a789fd484fa1d8f04425 +lib/axlsx/stylesheet/num_fmt.rb dc830c6540465afa824881efa2f1ce4070957c47 lib/axlsx.rb 7d8c589a0bdc16acf8774ae1b77d5177b030a80c -lib/axlsx/drawing/graphic_frame.rb 43496359fac0e990ded62f04254232f3cec8f736 lib/axlsx/content_type/override.rb 72245683bca868f181d709a515f9152485653229 +lib/axlsx/drawing/graphic_frame.rb 9fb4e59405ea7974e9759906efd5c8c90dfa9b89 lib/axlsx/drawing/pie_series.rb df339ed3eeb5692077e3a134339d04e77c9bc89b -lib/axlsx/drawing/bar_series.rb 044a3c42d3781755012c863ca138257b85ff5c0a +lib/axlsx/drawing/bar_series.rb 76d41efe347318587a932f9313f03e0a76abb4ee lib/axlsx/stylesheet/gradient_fill.rb 5fd260ec2b94ab75a970159035528548a9d21cd6 lib/axlsx/workbook/worksheet/row.rb f866a98341ce4e604908e42d00f2af09e58c75d2 lib/axlsx/util/simple_typed_list.rb b95f7e8d8958361cb1946b8545126b9384ff9fd2 -lib/axlsx/workbook/workbook.rb ec98ed826e6c3ca9c6e3303dbfbe00c0b5fb9aee +lib/axlsx/workbook/workbook.rb 12c82a584a9bfc4dfbb92c04426413d7eb44a504 lib/axlsx/stylesheet/fill.rb 35966285f5d759d63451005ceae3a5ae5ba2ceca lib/axlsx/drawing/view_3D.rb c8e25d57901dd7d679fe7d1ed674d5549ab6f1b3 lib/axlsx/stylesheet/xf.rb e3d6e2e4c3b0b33c91de4c3db16c73aca3db4473 -lib/axlsx/drawing/two_cell_anchor.rb a9400212ca7ed64263fd77826c3d336115cae185 +lib/axlsx/drawing/two_cell_anchor.rb b89873e55820f9be35f8e5ebe22bd8a0d319622a lib/axlsx/stylesheet/styles.rb 3679a8fe86270bdef96f02bcf76f2eac27b1c2ef lib/axlsx/drawing/val_axis.rb da067622f8b09e6caf5067955b277d75ab3c8943 lib/axlsx/drawing/cat_axis.rb f046262d1e8d04ff697fe29b88725225cd406cb2 -lib/axlsx/util/validators.rb 2320eee50ceee29cc0dbab95721a6c633dc660e1 +lib/axlsx/util/validators.rb 11eb309df0232fc1ad36c8c5ab0804d656b2294a lib/axlsx/stylesheet/font.rb 8b002d5fcba2fb0979858517f5254aadf96c7e58 lib/axlsx/doc_props/app.rb 52f01e985a33253987177798d4e79ed208649b30 -lib/axlsx/workbook/worksheet/worksheet.rb ba299b3a4f1e82f7da4fb6e28fad264dd6e2fbed +lib/axlsx/workbook/worksheet/worksheet.rb c7159356776e5ca1cfb6d0bc288c3acf278226c8 lib/axlsx/workbook/worksheet/cell.rb 939623ffc2065e9ec26bc56d9e289d9137fe57d3 -lib/axlsx/rels/relationship.rb a160c998acf7fd0ab8195ea6162b1eb2eab4963c +lib/axlsx/rels/relationship.rb 067b924c964a870124d51ea6e39dc1cd8983db21 lib/axlsx/stylesheet/border.rb 517bfcb43380919ce7abef494d5d3e50911b7c19 lib/axlsx/drawing/ser_axis.rb 6d15f6cc2092ef5c3baa314ed1af793247418d9b -lib/axlsx/drawing/drawing.rb a5d71d9c7e86f15fdea03754ab258009035151dd -lib/axlsx/drawing/chart.rb 2907d74c75580cd5f029a71140a750d4e69c869e -lib/axlsx/version.rb eb4274097b7f8f3f60e4e3dd8d57fb6bf6148f36 +lib/axlsx/drawing/drawing.rb 243992f4dd131092c6981b3b8cb68905c55d7e1e +lib/axlsx/drawing/chart.rb b0bfdd0cc2f0f48ed3ddcf2a1b1c46c5d9cabc2e +lib/axlsx/version.rb ff68edc0a9bdaaaa00a81a27a3de4fa8fe4e70ce lib/axlsx/stylesheet/gradient_stop.rb de34e289aeccb4abd9a3b7e60e816a0b12ffacff -lib/axlsx/drawing/cat_axis_data.rb efc95067f90bf8d0bb4ce0fa6e35b7b9d642e8b5 +lib/axlsx/drawing/cat_axis_data.rb f440010084afad99d97d31354f5b5a8ee8766e9b lib/axlsx/drawing/val_axis_data.rb c57c0abf5abb4aca9fba774f20e2f2c04d3020e8 lib/axlsx/doc_props/core.rb 90ebc8086f6606af02275c27068c359a5647faf0 +lib/axlsx/drawing/pic.rb b728be1f2f927e02c08b55c7a03b8bc6059f8672 lib/axlsx/drawing/bar_3D_chart.rb e5199cf0a33e416ea5ddf66677031ee08e5c116f lib/axlsx/drawing/scaling.rb d3b59eed1897dc2b07bb41b2245c6e4b3e274d7e lib/axlsx/stylesheet/pattern_fill.rb 817cf55beb3db160b2b56edb6c94de1ecf1ecee7 +lib/axlsx/drawing/one_cell_anchor.rb 512f300984cc9b2c4db73afb967b445d2e240ab7 lib/axlsx/drawing/line_3D_chart.rb de0a2c8a49259e0348fd2c642c08eb4c567bcf1b diff --git a/.yardoc/objects/root.dat b/.yardoc/objects/root.dat index 489afdf0..0646be52 100644 Binary files a/.yardoc/objects/root.dat and b/.yardoc/objects/root.dat differ diff --git a/.yardops b/.yardops index e3bb24aa..20a78eb1 100644 --- a/.yardops +++ b/.yardops @@ -1,4 +1,4 @@ --protected --no-private -CHANGELOG.md -LICENSE +--title "AXLSX" +LICENSE CHANGELOG.md diff --git a/README.md b/README.md index d81c10a1..47be4c39 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Axlsx: Office Open XML Spreadsheet Generation **Author**: Randy Morgan **Copyright**: 2011 **License**: MIT License -**Latest Version**: 1.0.7 +**Latest Version**: 1.0.8 **Ruby Version**: 1.8.7 **Release Date**: November 23nd 2011 @@ -14,7 +14,7 @@ Synopsis -------- Axlsx is an Office Open XML Spreadsheet generator for the Ruby programming language. -It enables the you to generate 100% valid xlsx files that include customised styling 3D pie, bar and line charts. Below is a summary of salient features. +It enables the you to generate 100% valid xlsx files that include customised styling, images, 3D pie, bar and line charts and auto-width columns. Below is a summary of salient features. Feature List ------------ @@ -31,6 +31,7 @@ Feature List **6. Support for both 1904 and 1900 epocs configurable in the workbook. +**7. Add jpg, gif and png images to worksheets Installing ---------- @@ -134,6 +135,17 @@ Generating A Line Chart end p.serialize("example6.xlsx") +Adding an Image + + p = Axlsx::Package.new + p.workbook.add_worksheet do |sheet| + sheet.add_image(:image_src => (File.dirname(__FILE__) + "/image1.png")) do |image| + image.width=720 + image.height=666 + image.start_at 2, 2 + end + end + p.serialize("example7.xlsx") ###Documentation @@ -149,6 +161,8 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem, Changelog --------- +- **October.23.11**: 1.0.8 release + - Added support for images (jpg, gif, png) in worksheets. - **October.23.11**: 1.0.7 released - Added support for 3D options when creating a new chart. This lets you set the persective, rotation and other 3D attributes when using worksheet.add_chart @@ -163,6 +177,10 @@ Changelog Please see the {file:CHANGELOG.md} document for past release information. +Help Wanted +----------- + +I'd really like to get rid of the depenency on RMagick in this gem. RMagic is being used to calculate the column widths in a worksheet based on the content the user specified. If there happens to be anyone out there with the background and skill set to write an extenstion that can determine the width of a singel character render with a specific font at a specific size please give me a shout. Copyright --------- diff --git a/doc/Axlsx.html b/doc/Axlsx.html index 2a8b517f..8fde8b4d 100644 --- a/doc/Axlsx.html +++ b/doc/Axlsx.html @@ -73,7 +73,7 @@
Defined in:
lib/axlsx/package.rb,
- lib/axlsx.rb,
lib/axlsx/version.rb,
lib/axlsx/drawing/axis.rb,
lib/axlsx/doc_props/app.rb,
lib/axlsx/drawing/title.rb,
lib/axlsx/stylesheet/xf.rb,
lib/axlsx/drawing/chart.rb,
lib/axlsx/drawing/series.rb,
lib/axlsx/util/constants.rb,
lib/axlsx/drawing/marker.rb,
lib/axlsx/doc_props/core.rb,
lib/axlsx/drawing/view_3D.rb,
lib/axlsx/stylesheet/font.rb,
lib/axlsx/drawing/drawing.rb,
lib/axlsx/util/validators.rb,
lib/axlsx/drawing/scaling.rb,
lib/axlsx/stylesheet/fill.rb,
lib/axlsx/stylesheet/color.rb,
lib/axlsx/drawing/ser_axis.rb,
lib/axlsx/drawing/cat_axis.rb,
lib/axlsx/drawing/val_axis.rb,
lib/axlsx/stylesheet/border.rb,
lib/axlsx/workbook/workbook.rb,
lib/axlsx/stylesheet/styles.rb,
lib/axlsx/rels/relationship.rb,
lib/axlsx/drawing/bar_series.rb,
lib/axlsx/drawing/pie_series.rb,
lib/axlsx/rels/relationships.rb,
lib/axlsx/stylesheet/num_fmt.rb,
lib/axlsx/drawing/line_series.rb,
lib/axlsx/stylesheet/border_pr.rb,
lib/axlsx/drawing/series_title.rb,
lib/axlsx/content_type/default.rb,
lib/axlsx/drawing/bar_3D_chart.rb,
lib/axlsx/drawing/pie_3D_chart.rb,
lib/axlsx/drawing/line_3D_chart.rb,
lib/axlsx/stylesheet/cell_style.rb,
lib/axlsx/drawing/val_axis_data.rb,
lib/axlsx/content_type/override.rb,
lib/axlsx/drawing/cat_axis_data.rb,
lib/axlsx/drawing/graphic_frame.rb,
lib/axlsx/util/simple_typed_list.rb,
lib/axlsx/stylesheet/table_style.rb,
lib/axlsx/workbook/worksheet/row.rb,
lib/axlsx/stylesheet/table_styles.rb,
lib/axlsx/drawing/two_cell_anchor.rb,
lib/axlsx/workbook/worksheet/cell.rb,
lib/axlsx/stylesheet/pattern_fill.rb,
lib/axlsx/stylesheet/gradient_fill.rb,
lib/axlsx/stylesheet/gradient_stop.rb,
lib/axlsx/content_type/content_type.rb,
lib/axlsx/stylesheet/cell_alignment.rb,
lib/axlsx/stylesheet/cell_protection.rb,
lib/axlsx/workbook/worksheet/worksheet.rb,
lib/axlsx/stylesheet/table_style_element.rb
+ lib/axlsx.rb,
lib/axlsx/version.rb,
lib/axlsx/drawing/pic.rb,
lib/axlsx/drawing/axis.rb,
lib/axlsx/doc_props/app.rb,
lib/axlsx/drawing/title.rb,
lib/axlsx/drawing/chart.rb,
lib/axlsx/stylesheet/xf.rb,
lib/axlsx/doc_props/core.rb,
lib/axlsx/drawing/series.rb,
lib/axlsx/drawing/marker.rb,
lib/axlsx/util/constants.rb,
lib/axlsx/stylesheet/font.rb,
lib/axlsx/drawing/view_3D.rb,
lib/axlsx/drawing/drawing.rb,
lib/axlsx/stylesheet/fill.rb,
lib/axlsx/util/validators.rb,
lib/axlsx/drawing/scaling.rb,
lib/axlsx/drawing/cat_axis.rb,
lib/axlsx/stylesheet/color.rb,
lib/axlsx/drawing/ser_axis.rb,
lib/axlsx/drawing/val_axis.rb,
lib/axlsx/stylesheet/border.rb,
lib/axlsx/workbook/workbook.rb,
lib/axlsx/stylesheet/styles.rb,
lib/axlsx/rels/relationship.rb,
lib/axlsx/stylesheet/num_fmt.rb,
lib/axlsx/drawing/bar_series.rb,
lib/axlsx/rels/relationships.rb,
lib/axlsx/drawing/pie_series.rb,
lib/axlsx/drawing/line_series.rb,
lib/axlsx/drawing/bar_3D_chart.rb,
lib/axlsx/stylesheet/border_pr.rb,
lib/axlsx/content_type/default.rb,
lib/axlsx/drawing/series_title.rb,
lib/axlsx/drawing/pie_3D_chart.rb,
lib/axlsx/drawing/val_axis_data.rb,
lib/axlsx/drawing/graphic_frame.rb,
lib/axlsx/drawing/line_3D_chart.rb,
lib/axlsx/content_type/override.rb,
lib/axlsx/drawing/cat_axis_data.rb,
lib/axlsx/stylesheet/cell_style.rb,
lib/axlsx/util/simple_typed_list.rb,
lib/axlsx/workbook/worksheet/row.rb,
lib/axlsx/stylesheet/table_style.rb,
lib/axlsx/drawing/one_cell_anchor.rb,
lib/axlsx/stylesheet/table_styles.rb,
lib/axlsx/workbook/worksheet/cell.rb,
lib/axlsx/drawing/two_cell_anchor.rb,
lib/axlsx/stylesheet/pattern_fill.rb,
lib/axlsx/stylesheet/gradient_stop.rb,
lib/axlsx/stylesheet/gradient_fill.rb,
lib/axlsx/stylesheet/cell_alignment.rb,
lib/axlsx/content_type/content_type.rb,
lib/axlsx/stylesheet/cell_protection.rb,
lib/axlsx/workbook/worksheet/worksheet.rb,
lib/axlsx/stylesheet/table_style_element.rb
@@ -98,7 +98,7 @@ cell styles, automatically resized column widths and 3D pie charts. - Classes: App, Axis, Bar3DChart, BarSeries, Border, BorderPr, CatAxis, CatAxisData, Cell, CellAlignment, CellProtection, CellStyle, Chart, Color, ContentType, Core, DataTypeValidator, Default, Drawing, Fill, Font, GradientFill, GradientStop, GraphicFrame, Line3DChart, LineSeries, Marker, NumFmt, Override, Package, PatternFill, Pie3DChart, PieSeries, RegexValidator, Relationship, Relationships, RestrictionValidator, Row, Scaling, SerAxis, Series, SeriesTitle, SimpleTypedList, Styles, TableStyle, TableStyleElement, TableStyles, Title, TwoCellAnchor, ValAxis, ValAxisData, View3D, Workbook, Worksheet, Xf + Classes: App, Axis, Bar3DChart, BarSeries, Border, BorderPr, CatAxis, CatAxisData, Cell, CellAlignment, CellProtection, CellStyle, Chart, Color, ContentType, Core, DataTypeValidator, Default, Drawing, Fill, Font, GradientFill, GradientStop, GraphicFrame, Line3DChart, LineSeries, Marker, NumFmt, OneCellAnchor, Override, Package, PatternFill, Pic, Pie3DChart, PieSeries, RegexValidator, Relationship, Relationships, RestrictionValidator, Row, Scaling, SerAxis, Series, SeriesTitle, SimpleTypedList, Styles, TableStyle, TableStyleElement, TableStyles, Title, TwoCellAnchor, ValAxis, ValAxisData, View3D, Workbook, Worksheet, Xf

@@ -122,7 +122,7 @@ version -
"1.0.7"
+        
"1.0.8"
 
ENCODING = @@ -539,6 +539,24 @@ chart rels namespace
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"
 
+
IMAGE_R = +
+
+

+image rels namespace +

+ + +
+
+
+ + +
+
+
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
+
+
TABLE_CT =
@@ -719,6 +737,60 @@ chart content type
"application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
 
+
JPEG_CT = +
+
+

+jpeg content type +

+ + +
+
+
+ + +
+
+
"image/jpeg"
+
+ +
GIF_CT = +
+
+

+gif content type +

+ + +
+
+
+ + +
+
+
"image/gif"
+
+ +
PNG_CT = +
+
+

+png content type +

+ + +
+
+
+ + +
+
+
"image/png"
+
+
DRAWING_CT =
@@ -755,6 +827,60 @@ xml content type extensions
"xml"
 
+
JPEG_EX = +
+
+

+jpeg extension +

+ + +
+
+
+ + +
+
+
"jpeg"
+
+ +
GIF_EX = +
+
+

+gif extension +

+ + +
+
+
+ + +
+
+
"gif"
+
+ +
PNG_EX = +
+
+

+png extension +

+ + +
+
+
+ + +
+
+
"png"
+
+
RELS_EX =
@@ -989,6 +1115,24 @@ chart part
"charts/chart%d.xml"
 
+
IMAGE_PN = +
+
+

+chart part +

+ + +
+
+
+ + +
+
+
"media/image%d.%s"
+
+
APP_XSD =
@@ -1743,7 +1887,7 @@ The value validated
# File 'lib/axlsx/util/validators.rb', line 114
 
 def self.validate_content_type(v)
-  RestrictionValidator.validate :content_type, [TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, DRAWING_CT], v
+  RestrictionValidator.validate :content_type, [TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, JPEG_CT, GIF_CT, PNG_CT, DRAWING_CT], v
 end
 
@@ -2126,7 +2270,7 @@ The value validated
# File 'lib/axlsx/util/validators.rb', line 121
 
 def self.validate_relationship_type(v)
-  RestrictionValidator.validate :relationship_type, [XML_NS_R, TABLE_R, WORKBOOK_R, WORKSHEET_R, APP_R, RELS_R, CORE_R, STYLES_R, CHART_R, DRAWING_R], v
+  RestrictionValidator.validate :relationship_type, [XML_NS_R, TABLE_R, WORKBOOK_R, WORKSHEET_R, APP_R, RELS_R, CORE_R, STYLES_R, CHART_R, DRAWING_R, IMAGE_R], v
 end
 
@@ -2434,7 +2578,7 @@ The value validated
diff --git a/doc/Axlsx/App.html b/doc/Axlsx/App.html index c7e072d2..90816fde 100644 --- a/doc/Axlsx/App.html +++ b/doc/Axlsx/App.html @@ -2631,7 +2631,7 @@ The document as a string
diff --git a/doc/Axlsx/Axis.html b/doc/Axlsx/Axis.html index f999a62c..5d2cfb3a 100644 --- a/doc/Axlsx/Axis.html +++ b/doc/Axlsx/Axis.html @@ -1064,7 +1064,7 @@ The document builder instance this objects xml will be added to. diff --git a/doc/Axlsx/Bar3DChart.html b/doc/Axlsx/Bar3DChart.html index adc2e51e..5c6ba596 100644 --- a/doc/Axlsx/Bar3DChart.html +++ b/doc/Axlsx/Bar3DChart.html @@ -1171,7 +1171,7 @@ Serializes the bar chart diff --git a/doc/Axlsx/BarSeries.html b/doc/Axlsx/BarSeries.html index 6528def1..287b4f9d 100644 --- a/doc/Axlsx/BarSeries.html +++ b/doc/Axlsx/BarSeries.html @@ -697,7 +697,7 @@ The document builder instance this objects xml will be added to. diff --git a/doc/Axlsx/Border.html b/doc/Axlsx/Border.html index 259897a0..49db8f1b 100644 --- a/doc/Axlsx/Border.html +++ b/doc/Axlsx/Border.html @@ -766,7 +766,7 @@ The document builder instance this objects xml will be added to. diff --git a/doc/Axlsx/BorderPr.html b/doc/Axlsx/BorderPr.html index e199b368..1f0f3d86 100644 --- a/doc/Axlsx/BorderPr.html +++ b/doc/Axlsx/BorderPr.html @@ -700,7 +700,7 @@ The document builder instance this objects xml will be added to. diff --git a/doc/Axlsx/CatAxis.html b/doc/Axlsx/CatAxis.html index 4f5b14cf..e12cfcf2 100644 --- a/doc/Axlsx/CatAxis.html +++ b/doc/Axlsx/CatAxis.html @@ -760,7 +760,7 @@ The document builder instance this objects xml will be added to. diff --git a/doc/Axlsx/CatAxisData.html b/doc/Axlsx/CatAxisData.html index 46378225..8fb3726a 100644 --- a/doc/Axlsx/CatAxisData.html +++ b/doc/Axlsx/CatAxisData.html @@ -253,7 +253,8 @@ typed list of cells. 7 8 9 -10
+10 +11
# File 'lib/axlsx/drawing/cat_axis_data.rb', line 7
@@ -261,6 +262,7 @@ typed list of cells.
 def initialize(data=[])
   super Object
   @list.concat data if data.is_a?(Array)
+  data.each { |i| @list << i } if data.is_a?(SimpleTypedList)
 end
 
@@ -344,7 +346,6 @@ The document builder instance this objects xml will be added to.
 
 
-15
 16
 17
 18
@@ -359,10 +360,11 @@ The document builder instance this objects xml will be added to.
 27
 28
 29
-30
+30 +31 -
# File 'lib/axlsx/drawing/cat_axis_data.rb', line 15
+      
# File 'lib/axlsx/drawing/cat_axis_data.rb', line 16
 
 def to_xml(xml)
   xml.send('c:cat') {
@@ -391,7 +393,7 @@ The document builder instance this objects xml will be added to.
 
     
     
diff --git a/doc/Axlsx/Cell.html b/doc/Axlsx/Cell.html
index 97c47170..1519044e 100644
--- a/doc/Axlsx/Cell.html
+++ b/doc/Axlsx/Cell.html
@@ -1614,7 +1614,7 @@ xml text for the cell
 
     
     
diff --git a/doc/Axlsx/CellAlignment.html b/doc/Axlsx/CellAlignment.html
index 5bdcf895..6e2a8155 100644
--- a/doc/Axlsx/CellAlignment.html
+++ b/doc/Axlsx/CellAlignment.html
@@ -1238,7 +1238,7 @@ The document builder instance this objects xml will be added to.
 
     
     
diff --git a/doc/Axlsx/CellProtection.html b/doc/Axlsx/CellProtection.html
index 669e70ef..6937b970 100644
--- a/doc/Axlsx/CellProtection.html
+++ b/doc/Axlsx/CellProtection.html
@@ -556,7 +556,7 @@ The document builder instance this objects xml will be added to.
 
     
     
diff --git a/doc/Axlsx/CellStyle.html b/doc/Axlsx/CellStyle.html
index 6f8eec14..a02f0170 100644
--- a/doc/Axlsx/CellStyle.html
+++ b/doc/Axlsx/CellStyle.html
@@ -940,7 +940,7 @@ The document builder instance this objects xml will be added to.
 
     
     
diff --git a/doc/Axlsx/Chart.html b/doc/Axlsx/Chart.html
index 1260ec43..c5dc9212 100644
--- a/doc/Axlsx/Chart.html
+++ b/doc/Axlsx/Chart.html
@@ -1290,13 +1290,13 @@ Adds a new series to the chart’s series collection.
       
 
 
+100
 101
 102
-103
-104
+103
-
# File 'lib/axlsx/drawing/chart.rb', line 101
+      
# File 'lib/axlsx/drawing/chart.rb', line 100
 
 def add_series(options={})
   @series_type.new(self, options)
@@ -1385,13 +1385,13 @@ The row
       
 
 
+148
 149
 150
-151
-152
+151
-
# File 'lib/axlsx/drawing/chart.rb', line 149
+      
# File 'lib/axlsx/drawing/chart.rb', line 148
 
 def end_at(x, y)
   @graphic_frame.anchor.to.col = x
@@ -1438,12 +1438,12 @@ markers
       
 
 
+93
 94
-95
-96
+95
-
# File 'lib/axlsx/drawing/chart.rb', line 94
+      
# File 'lib/axlsx/drawing/chart.rb', line 93
 
 def from
   @graphic_frame.anchor.from
@@ -1532,13 +1532,13 @@ The row
       
 
 
+137
 138
 139
-140
-141
+140
-
# File 'lib/axlsx/drawing/chart.rb', line 138
+      
# File 'lib/axlsx/drawing/chart.rb', line 137
 
 def start_at(x, y)
   @graphic_frame.anchor.from.col = x
@@ -1626,6 +1626,7 @@ Chart Serialization serializes the chart
       
 
 
+107
 108
 109
 110
@@ -1647,11 +1648,10 @@ Chart Serialization serializes the chart
 126
 127
 128
-129
-130
+129
-
# File 'lib/axlsx/drawing/chart.rb', line 108
+      
# File 'lib/axlsx/drawing/chart.rb', line 107
 
 def to_xml
   builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
@@ -1687,7 +1687,7 @@ Chart Serialization serializes the chart
 
     
     
diff --git a/doc/Axlsx/Color.html b/doc/Axlsx/Color.html
index 04ffc461..45f37f05 100644
--- a/doc/Axlsx/Color.html
+++ b/doc/Axlsx/Color.html
@@ -656,7 +656,7 @@ The document builder instance this objects xml will be added to.
 
     
     
diff --git a/doc/Axlsx/ContentType.html b/doc/Axlsx/ContentType.html
index 5f853af7..0dc84a68 100644
--- a/doc/Axlsx/ContentType.html
+++ b/doc/Axlsx/ContentType.html
@@ -331,7 +331,7 @@ The document as a string.
 
     
     
diff --git a/doc/Axlsx/Core.html b/doc/Axlsx/Core.html
index 5ad9e059..494f3853 100644
--- a/doc/Axlsx/Core.html
+++ b/doc/Axlsx/Core.html
@@ -456,7 +456,7 @@ time when this method is called.
 
     
     
diff --git a/doc/Axlsx/DataTypeValidator.html b/doc/Axlsx/DataTypeValidator.html
index ed694a90..1847c874 100644
--- a/doc/Axlsx/DataTypeValidator.html
+++ b/doc/Axlsx/DataTypeValidator.html
@@ -315,7 +315,7 @@ types or the block passed returns false
 
     
     
diff --git a/doc/Axlsx/Default.html b/doc/Axlsx/Default.html
index 3f689e96..e1f5c386 100644
--- a/doc/Axlsx/Default.html
+++ b/doc/Axlsx/Default.html
@@ -566,7 +566,7 @@ The document builder instance this objects xml will be added to.
 
     
     
diff --git a/doc/Axlsx/Drawing.html b/doc/Axlsx/Drawing.html
index 26f3f3fa..8f899d2a 100644
--- a/doc/Axlsx/Drawing.html
+++ b/doc/Axlsx/Drawing.html
@@ -183,6 +183,34 @@ An array of charts that are associated with this drawing’s anchors.
 

+ + + +
  • + + + - (Array) images + + + + + + + readonly + + + + + + + + +

    +An array of image objects that are associated with this drawing’s +anchors. +

    +
    +
  • @@ -383,6 +411,30 @@ Adds a chart to the drawing.

    + + + +
  • + + + - (Object) add_image(options = {}) + + + + + + + + + + + + +

    +Adds an image to the chart. +

    +
    +
  • @@ -488,21 +540,21 @@ The worksheet that owns this drawing
     
     
    -71
    -72
    -73
    -74
    -75
    -76
    +80 +81 +82 +83 +84 +85
    -
    # File 'lib/axlsx/drawing/drawing.rb', line 71
    +      
    # File 'lib/axlsx/drawing/drawing.rb', line 80
     
     def initialize(worksheet)
       DataTypeValidator.validate "Drawing.worksheet", Worksheet, worksheet
       @worksheet = worksheet
       @worksheet.workbook.drawings << self
    -  @anchors = SimpleTypedList.new TwoCellAnchor
    +  @anchors = SimpleTypedList.new [TwoCellAnchor, OneCellAnchor]
     end
     
    @@ -557,12 +609,12 @@ in this version
     
     
    -43
    -44
    -45
    +48 +49 +50
    -
    # File 'lib/axlsx/drawing/drawing.rb', line 43
    +      
    # File 'lib/axlsx/drawing/drawing.rb', line 48
     
     def anchors
       @anchors
    @@ -614,15 +666,77 @@ An array of charts that are associated with this drawing’s anchors
           
     
     
    -47
    -48
    -49
    +52 +53 +54 +55
    -
    # File 'lib/axlsx/drawing/drawing.rb', line 47
    +      
    # File 'lib/axlsx/drawing/drawing.rb', line 52
     
     def charts
    -  @anchors.map { |a| a.graphic_frame.chart }
    +  charts = @anchors.select { |a| a.object.is_a?(GraphicFrame) }
    +  charts.map { |a| a.object.chart }
    +end
    +
    + + + + + + + + +
    +

    + + - (Array) images (readonly) + + + +

    +
    +

    +An array of image objects that are associated with this drawing’s +anchors +

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (Array) + + + +
    • + +
    + +
    + + + @@ -672,12 +786,12 @@ collection.
     
     
    -51
    -52
    -53
    +60 +61 +62 + +
    +
    +
    +
    +56
    +57
    +58
    +59
    +
    +
    # File 'lib/axlsx/drawing/drawing.rb', line 56
    +
    +def images
    +  images = @anchors.select { |a| a.object.is_a?(Pic) }
    +  images.map { |a| a.object }
     end
     
    -
    # File 'lib/axlsx/drawing/drawing.rb', line 51
    +      
    # File 'lib/axlsx/drawing/drawing.rb', line 60
     
     def index
       @worksheet.workbook.drawings.index(self)
    @@ -729,12 +843,12 @@ The part name for this drawing
           
     
     
    -59
    -60
    -61
    +68 +69 +70
    -
    # File 'lib/axlsx/drawing/drawing.rb', line 59
    +      
    # File 'lib/axlsx/drawing/drawing.rb', line 68
     
     def pn
       "#{DRAWING_PN % (index+1)}"
    @@ -786,24 +900,28 @@ The drawing’s relationships.
           
     
     
    -67
    -68
    -69
    -70
    -71
    -72
    -73
    -74
    +76 +77 +78 +79 +80 +81 +82 +83 +84 +85
    -
    # File 'lib/axlsx/drawing/drawing.rb', line 67
    +      
    # File 'lib/axlsx/drawing/drawing.rb', line 76
     
     def relationships
       r = Relationships.new
    -  @anchors.each do |anchor|
    -    chart = anchor.graphic_frame.chart
    +  charts.each do |chart|
         r << Relationship.new(CHART_R, "../#{chart.pn}")
       end
    +  images.each do |image|
    +    r << Relationship.new(IMAGE_R, "../#{image.pn}")
    +  end
       r
     end
     
    @@ -853,12 +971,12 @@ The relational part name for this drawing
     
     
    -63
    -64
    -65
    +72 +73 +74
    -
    # File 'lib/axlsx/drawing/drawing.rb', line 63
    +      
    # File 'lib/axlsx/drawing/drawing.rb', line 72
     
     def rels_pn
       "#{DRAWING_RELS_PN % (index+1)}"
    @@ -910,12 +1028,12 @@ The relation reference id for this drawing
           
     
     
    -55
    -56
    -57
    +64 +65 +66
    -
    # File 'lib/axlsx/drawing/drawing.rb', line 55
    +      
    # File 'lib/axlsx/drawing/drawing.rb', line 64
     
     def rId
       "rId#{index+1}"
    @@ -967,12 +1085,12 @@ The worksheet that owns the drawing
           
     
     
    -38
    -39
    -40
    +43 +44 +45
    -
    # File 'lib/axlsx/drawing/drawing.rb', line 38
    +      
    # File 'lib/axlsx/drawing/drawing.rb', line 43
     
     def worksheet
       @worksheet
    @@ -1032,17 +1150,77 @@ Adds a chart to the drawing.
           
     
     
    -82
    -83
    -84
    -85
    +98 +99 +100 +101
    -
    # File 'lib/axlsx/drawing/drawing.rb', line 82
    +      
    # File 'lib/axlsx/drawing/drawing.rb', line 98
     
     def add_chart(chart_type, options={})
    -  TwoCellAnchor.new(self, chart_type, options)
    -  @anchors.last.graphic_frame.chart
    +  TwoCellAnchor.new(self, options)
    +  @anchors.last.add_chart(chart_type, options)
    +end
    +
    +
    +
    + +
    +

    + + - (Object) add_image(options = {}) + + + +

    +
    + +
    + Note: +

    +The recommended way to manage images is to use Worksheet.add_image. Please +refer to that method for documentation. +

    +
    +
    + +

    +Adds an image to the chart +

    + + +
    +
    +
    + + +

    See Also:

    + + +
    + + + @@ -1088,17 +1266,17 @@ Serializes the drawing
     
     
    -118
    -119
    -120
    -121
    -122
    -123
    -124
    -125
    +142 +143 +144 +145 +146 +147 +148 +149 @@ -451,17 +449,17 @@ Serializes the pie chart
     
     
    +32
     33
     34
     35
     36
     37
     38
    -39
    -40
    +39 @@ -513,12 +561,12 @@ The drawing that holds this anchor
     
     
    -20
    -21
    -22
    +25 +26 +27 @@ -646,18 +694,18 @@ The frame for your chart - +
    -

    +

    - - (Integer) index (readonly) + - (Pic, GraphicFrame) object (readonly)

    -The index of this anchor in the drawing +The object this anchor hosts

    @@ -671,7 +719,7 @@ The index of this anchor in the drawing
  • - (Integer) + (Pic, GraphicFrame) @@ -685,15 +733,15 @@ The index of this anchor in the drawing
     
     
    -24
    -25
    -26
    +21 +22 +23
  • @@ -767,7 +815,63 @@ A marker that returns the to cell anchor. The default to column and row are
    -

    +

    + + - (Chart) add_chart(chart_type, options) + + + +

    +
    +

    +Creates a graphic frame and chart object associated with this anchor +

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (Chart) + + + +
    • + +
    + +
    +
    +
    +
    +90
    +91
    +92
    +93
    +
    +
    # File 'lib/axlsx/drawing/drawing.rb', line 90
    +
    +def add_image(options={})
    +  OneCellAnchor.new(self, options)
    +  @anchors.last.object
     end
     
    -
    # File 'lib/axlsx/drawing/drawing.rb', line 118
    +      
    # File 'lib/axlsx/drawing/drawing.rb', line 142
     
     def to_xml
       builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
    @@ -1119,7 +1297,7 @@ Serializes the drawing
     
         
         
    diff --git a/doc/Axlsx/Fill.html b/doc/Axlsx/Fill.html
    index 298476de..15e908a7 100644
    --- a/doc/Axlsx/Fill.html
    +++ b/doc/Axlsx/Fill.html
    @@ -451,7 +451,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/Font.html b/doc/Axlsx/Font.html
    index f5afba14..d67be582 100644
    --- a/doc/Axlsx/Font.html
    +++ b/doc/Axlsx/Font.html
    @@ -1545,7 +1545,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/GradientFill.html b/doc/Axlsx/GradientFill.html
    index 503858e2..162e7f63 100644
    --- a/doc/Axlsx/GradientFill.html
    +++ b/doc/Axlsx/GradientFill.html
    @@ -1017,7 +1017,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/GradientStop.html b/doc/Axlsx/GradientStop.html
    index 3e172370..455d8b1f 100644
    --- a/doc/Axlsx/GradientStop.html
    +++ b/doc/Axlsx/GradientStop.html
    @@ -517,7 +517,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/GraphicFrame.html b/doc/Axlsx/GraphicFrame.html
    index 6a3d3052..e9c4d8bc 100644
    --- a/doc/Axlsx/GraphicFrame.html
    +++ b/doc/Axlsx/GraphicFrame.html
    @@ -326,14 +326,14 @@ Creates a new GraphicFrame object
           
     
     
    +22
    +23
     24
     25
    -26
    -27
    -28
    +26
    -
    # File 'lib/axlsx/drawing/graphic_frame.rb', line 24
    +      
    # File 'lib/axlsx/drawing/graphic_frame.rb', line 22
     
     def initialize(anchor, chart_type, options)
       DataTypeValidator.validate "Drawing.chart_type", Chart, chart_type 
    @@ -392,12 +392,12 @@ A anchor that holds this frame
           
     
     
    -15
    -16
    -17
    +13 +14 +15
    -
    # File 'lib/axlsx/drawing/graphic_frame.rb', line 15
    +      
    # File 'lib/axlsx/drawing/graphic_frame.rb', line 13
     
     def anchor
       @anchor
    @@ -449,12 +449,12 @@ A reference to the chart object associated with this frame
           
     
     
    -11
    -12
    -13
    +9 +10 +11
    -
    # File 'lib/axlsx/drawing/graphic_frame.rb', line 11
    +      
    # File 'lib/axlsx/drawing/graphic_frame.rb', line 9
     
     def chart
       @chart
    @@ -506,12 +506,12 @@ The relationship id for this graphic
           
     
     
    -19
    -20
    -21
    +17 +18 +19
    -
    # File 'lib/axlsx/drawing/graphic_frame.rb', line 19
    +      
    # File 'lib/axlsx/drawing/graphic_frame.rb', line 17
     
     def rId 
       "rId#{@anchor.index+1}"
    @@ -588,6 +588,8 @@ The document builder instance this objects xml will be added to.
           
     
     
    +35
    +36
     37
     38
     39
    @@ -603,12 +605,10 @@ The document builder instance this objects xml will be added to.
     49
     50
     51
    -52
    -53
    -54
    +52
    -
    # File 'lib/axlsx/drawing/graphic_frame.rb', line 37
    +      
    # File 'lib/axlsx/drawing/graphic_frame.rb', line 35
     
     def to_xml(xml)
       xml.send('xdr:graphicFrame') {        
    @@ -639,7 +639,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/Line3DChart.html b/doc/Axlsx/Line3DChart.html
    index 3c39226b..8d4efe8d 100644
    --- a/doc/Axlsx/Line3DChart.html
    +++ b/doc/Axlsx/Line3DChart.html
    @@ -993,7 +993,7 @@ Serializes the bar chart
     
         
         
    diff --git a/doc/Axlsx/LineSeries.html b/doc/Axlsx/LineSeries.html
    index 4e0ca266..bfc616d6 100644
    --- a/doc/Axlsx/LineSeries.html
    +++ b/doc/Axlsx/LineSeries.html
    @@ -251,8 +251,7 @@ Creates a new series.
     
       
         

    -Serializes the series TODO create series_cat and series_val classes as this -serialization is duplicated. +Serializes the series.

    @@ -514,8 +513,7 @@ The labels for this series.

    -Serializes the series TODO create series_cat and series_val classes as this -serialization is duplicated +Serializes the series

    @@ -564,15 +562,15 @@ The document builder instance this objects xml will be added to.
     
     
    +29
     30
     31
     32
     33
    -34
    -35
    +34
    -
    # File 'lib/axlsx/drawing/line_series.rb', line 30
    +      
    # File 'lib/axlsx/drawing/line_series.rb', line 29
     
     def to_xml(xml)
       super(xml) do |xml|
    @@ -591,7 +589,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/Marker.html b/doc/Axlsx/Marker.html
    index aaa0ffd7..ff00dfd9 100644
    --- a/doc/Axlsx/Marker.html
    +++ b/doc/Axlsx/Marker.html
    @@ -848,7 +848,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/NumFmt.html b/doc/Axlsx/NumFmt.html
    index f82acc34..903ba32d 100644
    --- a/doc/Axlsx/NumFmt.html
    +++ b/doc/Axlsx/NumFmt.html
    @@ -553,7 +553,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/OneCellAnchor.html b/doc/Axlsx/OneCellAnchor.html
    new file mode 100644
    index 00000000..bbc68665
    --- /dev/null
    +++ b/doc/Axlsx/OneCellAnchor.html
    @@ -0,0 +1,988 @@
    +
    +
    +  
    +    
    +
    +  Class: Axlsx::OneCellAnchor
    +  
    +    — Documentation by YARD 0.7.3
    +  
    +
    +
    +  
    +
    +  
    +
    +
    +
    +  
    +
    +  
    +
    +
    +  
    +  
    +    
    +    
    +    
    +    
    +    
    +    
    +    

    Class: Axlsx::OneCellAnchor + + + +

    + +
    + +
    Inherits:
    +
    + Object + +
      +
    • Object
    • + + + +
    + show all + +
    + + + + + + + + + +
    Defined in:
    +
    lib/axlsx/drawing/one_cell_anchor.rb
    + +
    +
    + +

    Overview

    +
    + +
    + Note: +

    +The recommended way to manage drawings, images and charts is +Worksheet#add_chart or Worksheet#add_image. +

    +
    +
    + +

    +This class details a single cell anchor for drawings. +

    + + +
    +
    +
    + + +

    See Also:

    + + +
    + +

    Instance Attribute Summary (collapse)

    +
      + +
    • + + + - (Drawing) drawing + + + + + + + readonly + + + + + + + + +

      +The drawing that holds this anchor. +

      +
      + +
    • + + +
    • + + + - (Marker) from + + + + + + + readonly + + + + + + + + +

      +A marker that defines the from cell anchor. +

      +
      + +
    • + + +
    • + + + - (Integer) height + + + + + + + + + + + + + + + +

      +the height of the graphic object in pixels this is converted to EMU at a 92 +ppi resolution. +

      +
      + +
    • + + +
    • + + + - (Integer) index + + + + + + + readonly + + + + + + + + +

      +The index of this anchor in the drawing. +

      +
      + +
    • + + +
    • + + + - (Pic) object + + + + + + + readonly + + + + + + + + +

      +The object this anchor hosts. +

      +
      + +
    • + + +
    • + + + - (Integer) width + + + + + + + + + + + + + + + +

      +the width of the graphic object in pixels. +

      +
      + +
    • + + +
    + + + + + +

    + Instance Method Summary + (collapse) +

    + + + + +
    +

    Constructor Details

    + +
    +

    + + - (OneCellAnchor) initialize(drawing, options = {}) + + + +

    +
    +

    +Creates a new OneCellAnchor object and an Pic associated with it. +

    + + +
    +
    +
    +

    Parameters:

    +
      + +
    • + + drawing + + + (Drawing) + + + +
    • + +
    • + + options + + + (Hash) + + + (defaults to: {}) + + + — +

      +a customizable set of options +

      +
      + +
    • + +
    + + + + + + +

    Options Hash (options):

    +
      + +
    • + start_at + (Array) + + + + —

      +the col, row to start at +

      +
      +
    • + +
    • + width + (Integer) + + + + +
    • + +
    • + height + (Integer) + + + + +
    • + +
    • + image_src + (String) + + + + —

      +the file location of the image you will render +

      +
      +
    • + +
    • + name + (String) + + + + —

      +the name attribute for the rendered image +

      +
      +
    • + +
    • + descr + (String) + + + + —

      +the description of the image rendered +

      +
      +
    • + +
    + + + +
    + + + + +
    +
    +
    +
    +44
    +45
    +46
    +47
    +48
    +49
    +50
    +51
    +52
    +53
    +54
    +
    +
    # File 'lib/axlsx/drawing/one_cell_anchor.rb', line 44
    +
    +def initialize(drawing, options={})
    +  @drawing = drawing
    +  @width = 0
    +  @height = 0
    +  drawing.anchors << self      
    +  @from = Marker.new
    +  options.each do |o|
    +    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
    +  end
    +  @object = Pic.new(self, options)
    +end
    +
    +
    +
    + +
    + +
    +

    Instance Attribute Details

    + + + + +
    +

    + + - (Drawing) drawing (readonly) + + + +

    +
    +

    +The drawing that holds this anchor +

    + + +
    +
    +
    + +

    Returns:

    + + +
    + + + + +
    +
    +
    +
    +18
    +19
    +20
    +
    +
    # File 'lib/axlsx/drawing/one_cell_anchor.rb', line 18
    +
    +def drawing
    +  @drawing
    +end
    +
    +
    +
    + + + + +
    +

    + + - (Marker) from (readonly) + + + +

    +
    +

    +A marker that defines the from cell anchor. The default from column and row +are 0 and 0 respectively +

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (Marker) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +10
    +11
    +12
    +
    +
    # File 'lib/axlsx/drawing/one_cell_anchor.rb', line 10
    +
    +def from
    +  @from
    +end
    +
    +
    +
    + + + + +
    +

    + + - (Integer) height + + + +

    +
    +

    +the height of the graphic object in pixels this is converted to EMU at a 92 +ppi resolution +

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (Integer) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +33
    +34
    +35
    +
    +
    # File 'lib/axlsx/drawing/one_cell_anchor.rb', line 33
    +
    +def height
    +  @height
    +end
    +
    +
    +
    + + + + +
    +

    + + - (Integer) index (readonly) + + + +

    +
    +

    +The index of this anchor in the drawing +

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (Integer) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +22
    +23
    +24
    +
    +
    # File 'lib/axlsx/drawing/one_cell_anchor.rb', line 22
    +
    +def index
    +  @drawing.anchors.index(self)
    +end
    +
    +
    +
    + + + + +
    +

    + + - (Pic) object (readonly) + + + +

    +
    +

    +The object this anchor hosts +

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (Pic) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +14
    +15
    +16
    +
    +
    # File 'lib/axlsx/drawing/one_cell_anchor.rb', line 14
    +
    +def object
    +  @object
    +end
    +
    +
    +
    + + + + +
    +

    + + - (Integer) width + + + +

    +
    +

    +the width of the graphic object in pixels. this is converted to EMU at a 92 +ppi resolution +

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (Integer) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +28
    +29
    +30
    +
    +
    # File 'lib/axlsx/drawing/one_cell_anchor.rb', line 28
    +
    +def width
    +  @width
    +end
    +
    +
    +
    + +
    + + +
    +

    Instance Method Details

    + + +
    +

    + + - (String) to_xml(xml) + + + +

    +
    +

    +Serializes the anchor +

    + + +
    +
    +
    +

    Parameters:

    +
      + +
    • + + xml + + + (Nokogiri::XML::Builder) + + + + — +

      +The document builder instance this objects xml will be added to. +

      +
      + +
    • + +
    + +

    Returns:

    +
      + +
    • + + + (String) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +66
    +67
    +68
    +69
    +70
    +71
    +72
    +73
    +74
    +75
    +
    +
    # File 'lib/axlsx/drawing/one_cell_anchor.rb', line 66
    +
    +def to_xml(xml)
    +  xml.send('xdr:oneCellAnchor') {
    +    xml.send('xdr:from') {
    +      from.to_xml(xml)
    +    }
    +    xml.send('xdr:ext', ext)
    +    @object.to_xml(xml)
    +    xml.send('xdr:clientData')
    +  }
    +end
    +
    +
    +
    + +
    + +
    + + + + + \ No newline at end of file diff --git a/doc/Axlsx/Override.html b/doc/Axlsx/Override.html index 41bc5195..89360a19 100644 --- a/doc/Axlsx/Override.html +++ b/doc/Axlsx/Override.html @@ -559,7 +559,7 @@ The document builder instance this objects xml will be added to. diff --git a/doc/Axlsx/Package.html b/doc/Axlsx/Package.html index ca431570..a28cf133 100644 --- a/doc/Axlsx/Package.html +++ b/doc/Axlsx/Package.html @@ -640,20 +640,20 @@ Creates the minimum content types for generating a valid xlsx document.
     
     
    -156
    -157
    -158
    -159
    -160
    -161
    -162
    -163
    -164
    -165
    -166
    +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192
    -
    # File 'lib/axlsx/package.rb', line 156
    +      
    # File 'lib/axlsx/package.rb', line 182
     
     def base_content_types
       c_types = ContentType.new()
    @@ -711,25 +711,36 @@ your workbook to the default content types.
           
     
     
    -136
    -137
    -138
    -139
    -140
    -141
    -142
    -143
    -144
    -145
    -146
    -147
    -148
    -149
    -150
    -151
    +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177
    -
    # File 'lib/axlsx/package.rb', line 136
    +      
    # File 'lib/axlsx/package.rb', line 151
     
     def content_types
       c_types = base_content_types
    @@ -745,6 +756,17 @@ your workbook to the default content types.
         c_types << Axlsx::Override.new(:PartName => "/xl/#{sheet.pn}", 
                                          :ContentType => WORKSHEET_CT)
       end
    +  exts = workbook.images.map { |image| image.extname }
    +  exts.uniq.each do |ext|
    +    ct = if  ['jpeg', 'jpg'].include?(ext)
    +           JPEG_CT
    +         elsif ext == 'gif'
    +           GIF_CT
    +         elsif ext == 'png'
    +           PNG_CT
    +         end
    +    c_types << Axlsx::Default.new(:ContentType => ct, :Extension => ext )
    +  end
       c_types
     end
     
    @@ -798,17 +820,6 @@ of the package.
     
     
    -90
    -91
    -92
    -93
    -94
    -95
    -96
    -97
    -98
    -99
    -100
     101
     102
     103
    @@ -822,10 +833,25 @@ of the package.
     111
     112
     113
    -114
    +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129
    -
    # File 'lib/axlsx/package.rb', line 90
    +      
    # File 'lib/axlsx/package.rb', line 101
     
     def parts
       @parts = [
    @@ -845,7 +871,11 @@ of the package.
       workbook.charts.each do |chart|          
         @parts << {:entry => "xl/#{chart.pn}", :doc => chart.to_xml, :schema => DRAWING_XSD}
       end                  
    - 
    +
    +  workbook.images.each do |image|
    +    @parts << {:entry => "xl/#{image.pn}", :path => image.image_src}
    +  end
    +
       workbook.worksheets.each do |sheet|            
         @parts << {:entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships.to_xml, :schema => RELS_XSD}
         @parts << {:entry => "xl/#{sheet.pn}", :doc => sheet.to_xml, :schema => SML_XSD}        
    @@ -896,17 +926,17 @@ Creates the relationships required for a valid xlsx document
           
     
     
    -171
    -172
    -173
    -174
    -175
    -176
    -177
    -178
    +197 +198 +199 +200 +201 +202 +203 +204
    -
    # File 'lib/axlsx/package.rb', line 171
    +      
    # File 'lib/axlsx/package.rb', line 197
     
     def relationships
       rels = Axlsx::Relationships.new
    @@ -1046,17 +1076,39 @@ serialized
     59
     60
     61
    -62
    +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73
    # File 'lib/axlsx/package.rb', line 55
     
     def serialize(output, confirm_valid=false)
       return false unless !confirm_valid || self.validate.empty?
    -  f = File.new(output, "w")
    -  Zip::ZipOutputStream.open(f.path) do |zip|
    -    parts.each{ |part| zip.put_next_entry(part[:entry]); zip.puts(part[:doc]) }
    +  p = parts
    +  Zip::ZipOutputStream.open(output) do |zip|
    +    p.each do |part| 
    +      zip.put_next_entry(part[:entry]); zip.puts(part[:doc]) unless part[:doc].nil?
    +    end
    +  end
    +  Zip::ZipFile.open(output) do |zip|
    +    p.each do |part|
    +      if part[:path]
    +        zip.add(part[:entry], part[:path], &proc{ true })
    +      end
    +    end                  
       end
    +
    +
       true
     end
     
    @@ -1147,18 +1199,18 @@ An array of all validation errors found.
     
     
    -79
    -80
    -81
    -82
    -83
    +90 +91 +92 +93 +94
    -
    # File 'lib/axlsx/package.rb', line 79
    +      
    # File 'lib/axlsx/package.rb', line 90
     
     def validate
       errors = []
    -  parts.each { |part| errors.concat validate_single_doc(part[:schema], part[:doc]) }
    +  parts.each { |part| errors.concat validate_single_doc(part[:schema], part[:doc]) unless part[:schema].nil? }
       errors
     end
     
    @@ -1249,19 +1301,19 @@ An array of all validation errors encountered.
     
     
    -122
    -123
    -124
    -125
    -126
    -127
    -128
    -129
    -130
    -131
    +137 +138 +139 +140 +141 +142 +143 +144 +145 +146
    -
    # File 'lib/axlsx/package.rb', line 122
    +      
    # File 'lib/axlsx/package.rb', line 137
     
     def validate_single_doc(schema, doc)
       schema = Nokogiri::XML::Schema(File.open(schema))
    @@ -1284,7 +1336,7 @@ An array of all validation errors encountered.
     
         
         
    diff --git a/doc/Axlsx/PatternFill.html b/doc/Axlsx/PatternFill.html
    index be70ff59..0c671e70 100644
    --- a/doc/Axlsx/PatternFill.html
    +++ b/doc/Axlsx/PatternFill.html
    @@ -672,7 +672,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/Pic.html b/doc/Axlsx/Pic.html
    new file mode 100644
    index 00000000..a204ec1b
    --- /dev/null
    +++ b/doc/Axlsx/Pic.html
    @@ -0,0 +1,1532 @@
    +
    +
    +  
    +    
    +
    +  Class: Axlsx::Pic
    +  
    +    — Documentation by YARD 0.7.3
    +  
    +
    +
    +  
    +
    +  
    +
    +
    +
    +  
    +
    +  
    +
    +
    +  
    +  
    +    
    +    
    +    
    +    
    +    
    +    
    +    

    Class: Axlsx::Pic + + + +

    + +
    + +
    Inherits:
    +
    + Object + +
      +
    • Object
    • + + + +
    + show all + +
    + + + + + + + + + +
    Defined in:
    +
    lib/axlsx/drawing/pic.rb
    + +
    +
    + +

    Overview

    +
    +

    +a Pic object represents an image in your worksheet Worksheet#add_image is +the recommended way to manage images in your sheets +

    + + +
    +
    +
    + + +

    See Also:

    + + +
    +

    Constant Summary

    + +
    + +
    ALLOWED_EXTENSIONS = +
    +
    +

    +allowed file extenstions +

    + + +
    +
    +
    + + +
    +
    +
    ['gif', 'jpeg', 'png', 'jpg']
    +
    + +
    + + + +

    Instance Attribute Summary (collapse)

    +
      + +
    • + + + - (OneCellAnchor) anchor + + + + + + + readonly + + + + + + + + +

      +The anchor for this image. +

      +
      + +
    • + + +
    • + + + - (String) descr + + + + + + + + + + + + + + + +

      +A description of the picture. +

      +
      + +
    • + + +
    • + + + - (String) extname + + + + + + + readonly + + + + + + + + +

      +returns the extension of image_src without the preceeding ’.’. +

      +
      + +
    • + + +
    • + + + - (String) file_name + + + + + + + readonly + + + + + + + + +

      +The name of the image file, sans directory info. +

      +
      + +
    • + + +
    • + + + - (Object) height + + + + + + + + + + + + + + + +

      +providing access to update the anchor’s height attribute. +

      +
      + +
    • + + +
    • + + + - (String) image_src + + + + + + + + + + + + + + + +

      +The path to the image you want to include Only local images are supported +at this time and only jpg support. +

      +
      + +
    • + + +
    • + + + - (Index) index + + + + + + + readonly + + + + + + + + +

      +The index of this image in the workbooks images collections. +

      +
      + +
    • + + +
    • + + + - (String) name + + + + + + + + + + + + + + + +

      +The name to use for this picture. +

      +
      + +
    • + + +
    • + + + - (String) pn + + + + + + + readonly + + + + + + + + +

      +The part name for this image used in serialization and relationship +building. +

      +
      + +
    • + + +
    • + + + - (Object) width + + + + + + + + + + + + + + + +

      +providing access to the anchor’s width attribute. +

      +
      + +
    • + + +
    + + + + + +

    + Instance Method Summary + (collapse) +

    + + + + +
    +

    Constructor Details

    + +
    +

    + + - (Pic) initialize(anchor, options = {}) {|_self| ... } + + + +

    +
    +

    +Creates a new Pic(ture) object +

    + + +
    +
    +
    +

    Parameters:

    +
      + +
    • + + anchor + + + (Anchor) + + + + — +

      +the anchor that holds this image +

      +
      + +
    • + +
    • + + options + + + (Hash) + + + (defaults to: {}) + + + — +

      +a customizable set of options +

      +
      + +
    • + +
    + + + + + + +

    Options Hash (options):

    +
      + +
    • + name + (String) + + + + +
    • + +
    • + descr + (String) + + + + +
    • + +
    • + image_src + (String) + + + + +
    • + +
    • + start_at + (Array) + + + + +
    • + +
    • + width + (Intger) + + + + +
    • + +
    • + height + (Intger) + + + + +
    • + +
    + + +

    Yields:

    +
      + +
    • + + + (_self) + + + +
    • + +
    +

    Yield Parameters:

    +
      + +
    • + + _self + + + (Axlsx::Pic) + + + + — +

      +the object that the method was called on +

      +
      + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +66
    +67
    +68
    +69
    +70
    +71
    +72
    +73
    +74
    +
    +
    # File 'lib/axlsx/drawing/pic.rb', line 66
    +
    +def initialize(anchor, options={})
    +  @anchor = anchor
    +  @anchor.drawing.worksheet.workbook.images << self
    +  options.each do |o|
    +    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
    +  end
    +  start_at *options[:start_at] if options[:start_at]
    +  yield self if block_given?
    +end
    +
    +
    +
    + +
    + +
    +

    Instance Attribute Details

    + + + + +
    +

    + + - (OneCellAnchor) anchor (readonly) + + + +

    +
    +

    +The anchor for this image +

    + + +
    +
    +
    + +

    Returns:

    + + +
    + + + + +
    +
    +
    +
    +36
    +37
    +38
    +
    +
    # File 'lib/axlsx/drawing/pic.rb', line 36
    +
    +def anchor
    +  @anchor
    +end
    +
    +
    +
    + + + + +
    +

    + + - (String) descr + + + +

    +
    +

    +A description of the picture +

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (String) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +27
    +28
    +29
    +
    +
    # File 'lib/axlsx/drawing/pic.rb', line 27
    +
    +def descr
    +  @descr
    +end
    +
    +
    +
    + + + + +
    +

    + + - (String) extname (readonly) + + + +

    +
    +

    +returns the extension of image_src without the preceeding ’.’ +

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (String) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +40
    +41
    +42
    +
    +
    # File 'lib/axlsx/drawing/pic.rb', line 40
    +
    +def extname
    +  File.extname(image_src).delete('.') unless image_src.nil?
    +end
    +
    +
    +
    + + + + +
    +

    + + - (String) file_name (readonly) + + + +

    +
    +

    +The name of the image file, sans directory info +

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (String) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +44
    +45
    +46
    +
    +
    # File 'lib/axlsx/drawing/pic.rb', line 44
    +
    +def file_name
    +  File.basename(image_src) unless image_src.nil?
    +end
    +
    +
    +
    + + + + +
    +

    + + - (Object) height + + + +

    +
    +

    +providing access to update the anchor’s height attribute +

    + + +
    +
    +
    +

    Parameters:

    +
      + +
    • + + v + + + (Integer) + + + +
    • + +
    + + +

    See Also:

    +
      + +
    • OneCellAnchor.width
    • + +
    + +
    + + + + +
    +
    +
    +
    +23
    +24
    +25
    +
    +
    # File 'lib/axlsx/drawing/pic.rb', line 23
    +
    +def height
    +  @anchor.height
    +end
    +
    +
    +
    + + + + +
    +

    + + - (String) image_src + + + +

    +
    +

    +The path to the image you want to include Only local images are supported +at this time and only jpg support +

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (String) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +32
    +33
    +34
    +
    +
    # File 'lib/axlsx/drawing/pic.rb', line 32
    +
    +def image_src
    +  @image_src
    +end
    +
    +
    +
    + + + + +
    +

    + + - (Index) index (readonly) + + + +

    +
    +

    +The index of this image in the workbooks images collections +

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (Index) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +52
    +53
    +54
    +
    +
    # File 'lib/axlsx/drawing/pic.rb', line 52
    +
    +def index
    +  @anchor.drawing.worksheet.workbook.images.index(self)
    +end
    +
    +
    +
    + + + + +
    +

    + + - (String) name + + + +

    +
    +

    +The name to use for this picture +

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (String) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +13
    +14
    +15
    +
    +
    # File 'lib/axlsx/drawing/pic.rb', line 13
    +
    +def name
    +  @name
    +end
    +
    +
    +
    + + + + +
    +

    + + - (String) pn (readonly) + + + +

    +
    +

    +The part name for this image used in serialization and relationship +building +

    + + +
    +
    +
    + +

    Returns:

    +
      + +
    • + + + (String) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +48
    +49
    +50
    +
    +
    # File 'lib/axlsx/drawing/pic.rb', line 48
    +
    +def pn
    +  "#{IMAGE_PN % [(index+1), extname]}"
    +end
    +
    +
    +
    + + + + +
    +

    + + - (Object) width + + + +

    +
    +

    +providing access to the anchor’s width attribute +

    + + +
    +
    +
    +

    Parameters:

    +
      + +
    • + + v + + + (Integer) + + + +
    • + +
    + + +

    See Also:

    +
      + +
    • OneCellAnchor.width
    • + +
    + +
    + + + + +
    +
    +
    +
    +18
    +19
    +20
    +
    +
    # File 'lib/axlsx/drawing/pic.rb', line 18
    +
    +def width
    +  @anchor.width
    +end
    +
    +
    +
    + +
    + + +
    +

    Instance Method Details

    + + +
    +

    + + - (Marker) start_at(x, y) + + + +

    +
    +

    +This is a short cut method to set the start anchor position If you need +finer granularity in positioning use graphic_frame.anchor.from.colOff / +rowOff +

    + + +
    +
    +
    +

    Parameters:

    +
      + +
    • + + x + + + (Integer) + + + + — +

      +The column +

      +
      + +
    • + +
    • + + y + + + (Integer) + + + + — +

      +The row +

      +
      + +
    • + +
    + +

    Returns:

    +
      + +
    • + + + (Marker) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +124
    +125
    +126
    +127
    +
    +
    # File 'lib/axlsx/drawing/pic.rb', line 124
    +
    +def start_at(x, y)
    +  @anchor.from.col = x
    +  @anchor.from.row = y
    +end
    +
    +
    +
    + +
    +

    + + - (String) to_xml(xml) + + + +

    +
    +

    +Serializes the picture +

    + + +
    +
    +
    +

    Parameters:

    +
      + +
    • + + xml + + + (Nokogiri::XML::Builder) + + + + — +

      +The document builder instance this objects xml will be added to. +

      +
      + +
    • + +
    + +

    Returns:

    +
      + +
    • + + + (String) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +132
    +133
    +134
    +135
    +136
    +137
    +138
    +139
    +140
    +141
    +142
    +143
    +144
    +145
    +146
    +147
    +148
    +149
    +150
    +151
    +152
    +153
    +154
    +155
    +156
    +
    +
    # File 'lib/axlsx/drawing/pic.rb', line 132
    +
    +def to_xml(xml)
    +  xml.send('xdr:pic') {
    +    xml.send('xdr:nvPicPr') {
    +      xml.send('xdr:cNvPr', :id=>"2", :name=>name, :descr=>descr)
    +      xml.send('xdr:cNvPicPr') {
    +        xml.send('a:picLocks', :noChangeAspect=>1)
    +      }
    +    }
    +    xml.send('xdr:blipFill') {
    +      xml.send('a:blip', :'xmlns:r' => XML_NS_R, :'r:embed'=>"rId1")
    +      xml.send('a:stretch') {
    +        xml.send('a:fillRect')
    +      }
    +    }
    +    xml.send('xdr:spPr') {
    +      xml.send('a:xfrm') {
    +        xml.send('a:off', :x=>0, :y=>0)
    +        xml.send('a:ext', :cx=>2336800, :cy=>2161540)
    +      }
    +      xml.send('a:prstGeom', :prst=>:rect) {
    +        xml.send('a:avLst')
    +      }
    +    }
    +  }
    +end
    +
    +
    +
    + +
    + +
    + + + + + \ No newline at end of file diff --git a/doc/Axlsx/Pie3DChart.html b/doc/Axlsx/Pie3DChart.html index 463ee085..81f128ff 100644 --- a/doc/Axlsx/Pie3DChart.html +++ b/doc/Axlsx/Pie3DChart.html @@ -388,8 +388,7 @@ a customizable set of options 25 26 27 -28 -29
    +28
    # File 'lib/axlsx/drawing/pie_3D_chart.rb', line 24
    @@ -398,7 +397,6 @@ a customizable set of options
       super(frame, options)
       @series_type = PieSeries
       @view3D = View3D.new({:rotX=>30, :perspective=>30}.merge(options))
    -
     end
     
    -
    # File 'lib/axlsx/drawing/pie_3D_chart.rb', line 33
    +      
    # File 'lib/axlsx/drawing/pie_3D_chart.rb', line 32
     
     def to_xml
       super() do |xml|
    @@ -482,7 +480,7 @@ Serializes the pie chart
     
         
         
    diff --git a/doc/Axlsx/PieSeries.html b/doc/Axlsx/PieSeries.html
    index ac8bc6bb..17d4e297 100644
    --- a/doc/Axlsx/PieSeries.html
    +++ b/doc/Axlsx/PieSeries.html
    @@ -694,7 +694,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/RegexValidator.html b/doc/Axlsx/RegexValidator.html
    index 5e0f6f0f..4dec6fee 100644
    --- a/doc/Axlsx/RegexValidator.html
    +++ b/doc/Axlsx/RegexValidator.html
    @@ -259,7 +259,7 @@ The value to validate.
     
         
         
    diff --git a/doc/Axlsx/Relationship.html b/doc/Axlsx/Relationship.html
    index 8bea1e24..9480cc84 100644
    --- a/doc/Axlsx/Relationship.html
    +++ b/doc/Axlsx/Relationship.html
    @@ -228,7 +228,7 @@ A new instance of Relationship.
     
       
         

    -Serializes the relationship TODO: use object.rId to get this infomation. +Serializes the relationship.

    @@ -454,7 +454,7 @@ The type of relationship

    -Serializes the relationship TODO: use object.rId to get this infomation +Serializes the relationship

    @@ -520,14 +520,14 @@ the reference id of the object.
     
     
    +36
     37
     38
     39
    -40
    -41
    +40
    -
    # File 'lib/axlsx/rels/relationship.rb', line 37
    +      
    # File 'lib/axlsx/rels/relationship.rb', line 36
     
     def to_xml(xml, rId)
       h = self.instance_values
    @@ -545,7 +545,7 @@ the reference id of the object.
     
         
         
    diff --git a/doc/Axlsx/Relationships.html b/doc/Axlsx/Relationships.html
    index a2d44c51..63f9f97f 100644
    --- a/doc/Axlsx/Relationships.html
    +++ b/doc/Axlsx/Relationships.html
    @@ -334,7 +334,7 @@ Serializes the relationships document.
     
         
         
    diff --git a/doc/Axlsx/RestrictionValidator.html b/doc/Axlsx/RestrictionValidator.html
    index 5cea69a1..26518704 100644
    --- a/doc/Axlsx/RestrictionValidator.html
    +++ b/doc/Axlsx/RestrictionValidator.html
    @@ -291,7 +291,7 @@ Raised if the value provided is not in the list of choices.
     
         
         
    diff --git a/doc/Axlsx/Row.html b/doc/Axlsx/Row.html
    index f4793412..97a255c2 100644
    --- a/doc/Axlsx/Row.html
    +++ b/doc/Axlsx/Row.html
    @@ -762,7 +762,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/Scaling.html b/doc/Axlsx/Scaling.html
    index 2d734018..fcf2813d 100644
    --- a/doc/Axlsx/Scaling.html
    +++ b/doc/Axlsx/Scaling.html
    @@ -731,7 +731,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/SerAxis.html b/doc/Axlsx/SerAxis.html
    index 54fdcdaf..1fd700a2 100644
    --- a/doc/Axlsx/SerAxis.html
    +++ b/doc/Axlsx/SerAxis.html
    @@ -630,7 +630,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/Series.html b/doc/Axlsx/Series.html
    index 22614377..6c966945 100644
    --- a/doc/Axlsx/Series.html
    +++ b/doc/Axlsx/Series.html
    @@ -752,7 +752,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/SeriesTitle.html b/doc/Axlsx/SeriesTitle.html
    index 0d48cf72..5819efb3 100644
    --- a/doc/Axlsx/SeriesTitle.html
    +++ b/doc/Axlsx/SeriesTitle.html
    @@ -281,7 +281,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/SimpleTypedList.html b/doc/Axlsx/SimpleTypedList.html
    index 268f2fc4..de9f323b 100644
    --- a/doc/Axlsx/SimpleTypedList.html
    +++ b/doc/Axlsx/SimpleTypedList.html
    @@ -1677,7 +1677,7 @@ Unlock the list
     
         
         
    diff --git a/doc/Axlsx/Styles.html b/doc/Axlsx/Styles.html
    index 3d111991..396f5ab0 100644
    --- a/doc/Axlsx/Styles.html
    +++ b/doc/Axlsx/Styles.html
    @@ -1745,7 +1745,7 @@ Serializes the styles document
     
         
         
    diff --git a/doc/Axlsx/TableStyle.html b/doc/Axlsx/TableStyle.html
    index 1d8f1584..76271084 100644
    --- a/doc/Axlsx/TableStyle.html
    +++ b/doc/Axlsx/TableStyle.html
    @@ -701,7 +701,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/TableStyleElement.html b/doc/Axlsx/TableStyleElement.html
    index 316cdc18..47a89fc4 100644
    --- a/doc/Axlsx/TableStyleElement.html
    +++ b/doc/Axlsx/TableStyleElement.html
    @@ -668,7 +668,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/TableStyles.html b/doc/Axlsx/TableStyles.html
    index bf84de69..2ef28eb3 100644
    --- a/doc/Axlsx/TableStyles.html
    +++ b/doc/Axlsx/TableStyles.html
    @@ -590,7 +590,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/Title.html b/doc/Axlsx/Title.html
    index b785b91f..2d0b20cb 100644
    --- a/doc/Axlsx/Title.html
    +++ b/doc/Axlsx/Title.html
    @@ -616,7 +616,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/TwoCellAnchor.html b/doc/Axlsx/TwoCellAnchor.html
    index 0e1ca139..f805ab7e 100644
    --- a/doc/Axlsx/TwoCellAnchor.html
    +++ b/doc/Axlsx/TwoCellAnchor.html
    @@ -183,7 +183,7 @@ A marker that defines the from cell anchor.
           
  • - - (GraphicFrame) graphic_frame + - (Integer) index @@ -200,7 +200,7 @@ A marker that defines the from cell anchor.

    -The frame for your chart. +The index of this anchor in the drawing.

    @@ -210,7 +210,7 @@ The frame for your chart.
  • - - (Integer) index + - (Pic, GraphicFrame) object @@ -227,7 +227,7 @@ The frame for your chart.

    -The index of this anchor in the drawing. +The object this anchor hosts.

    @@ -277,7 +277,31 @@ A marker that returns the to cell anchor.
  • - - (TwoCellAnchor) initialize(drawing, chart_type, options) + - (Chart) add_chart(chart_type, options) + + + + + + + + + + + + +

    +Creates a graphic frame and chart object associated with this anchor. +

    +
    + +
  • + + +
  • + + + - (TwoCellAnchor) initialize(drawing, options = {}) @@ -334,13 +358,22 @@ Serializes the two cell anchor.

    - - (TwoCellAnchor) initialize(drawing, chart_type, options) + - (TwoCellAnchor) initialize(drawing, options = {})

    -

    + +

    + Note: +

    +the chart_type parameter will be replaced with object in v. 2.0.0 +

    +
    +
    + +

    Creates a new TwoCellAnchor object and sets up a reference to the from and to markers in the graphic_frame’s chart. That means that you can do stuff like c = worksheet.add_chart Axlsx::Chart c.start_at 5, 9 @@ -382,6 +415,23 @@ subclass of Chart

  • +
  • + + object + + + + + + + — +

    +The object this anchor holds. +

    +
    + +
  • +
  • options @@ -390,6 +440,8 @@ subclass of Chart (Hash) + (defaults to: {}) + —

    @@ -406,8 +458,6 @@ a customizable set of options - -

    Options Hash (options):

      @@ -445,21 +495,19 @@ the col, row to end at
       
       
      -34
      -35
      -36
      -37
      -38
      -39
      +41 +42 +43 +44 +45
  • -
    # File 'lib/axlsx/drawing/two_cell_anchor.rb', line 34
    +      
    # File 'lib/axlsx/drawing/two_cell_anchor.rb', line 41
     
    -def initialize(drawing, chart_type, options)
    +def initialize(drawing, options={})
       @drawing = drawing
       drawing.anchors << self      
       @from, @to =  Marker.new, Marker.new(:col => 5, :row=>10)
    -  @graphic_frame = GraphicFrame.new(self, chart_type, options)
     end
     
    -
    # File 'lib/axlsx/drawing/two_cell_anchor.rb', line 20
    +      
    # File 'lib/axlsx/drawing/two_cell_anchor.rb', line 25
     
     def drawing
       @drawing
    @@ -589,18 +637,18 @@ are 0 and 0 respectively
         
           
           
    -      
    +      
           
    -

    +

    - - (GraphicFrame) graphic_frame (readonly) + - (Integer) index (readonly)

    -The frame for your chart +The index of this anchor in the drawing

    @@ -614,7 +662,7 @@ The frame for your chart
  • - (GraphicFrame) + (Integer) @@ -628,15 +676,15 @@ The frame for your chart
     
     
    -16
    -17
    -18
    +29 +30 +31
  • -
    # File 'lib/axlsx/drawing/two_cell_anchor.rb', line 16
    +      
    # File 'lib/axlsx/drawing/two_cell_anchor.rb', line 29
     
    -def graphic_frame
    -  @graphic_frame
    +def index
    +  @drawing.anchors.index(self)
     end
     
    -
    # File 'lib/axlsx/drawing/two_cell_anchor.rb', line 24
    +      
    # File 'lib/axlsx/drawing/two_cell_anchor.rb', line 21
     
    -def index
    -  @drawing.anchors.index(self)
    +def object
    +  @object
     end
     
    + + + + +
    +
    +
    +
    +49
    +50
    +51
    +52
    +
    +
    # File 'lib/axlsx/drawing/two_cell_anchor.rb', line 49
    +
    +def add_chart(chart_type, options)      
    +  @object = GraphicFrame.new(self, chart_type, options)
    +  @object.chart
    +end
    +
    +
    +
    + +
    +

    - (String) to_xml(xml) @@ -825,22 +929,22 @@ The document builder instance this objects xml will be added to.

     
     
    -47
    -48
    -49
    -50
    -51
    -52
    -53
    -54
    -55
    -56
    -57
    -58
    -59
    +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72
    -
    # File 'lib/axlsx/drawing/two_cell_anchor.rb', line 47
    +      
    # File 'lib/axlsx/drawing/two_cell_anchor.rb', line 60
     
     def to_xml(xml)
       #build it for now, break it down later!
    @@ -851,7 +955,7 @@ The document builder instance this objects xml will be added to.
         xml.send('xdr:to') {
           to.to_xml(xml)
         }
    -    @graphic_frame.to_xml(xml)
    +    @object.to_xml(xml)
         xml.send('xdr:clientData')
       }
     end
    @@ -866,7 +970,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/ValAxis.html b/doc/Axlsx/ValAxis.html
    index 54a0fd41..37412dd8 100644
    --- a/doc/Axlsx/ValAxis.html
    +++ b/doc/Axlsx/ValAxis.html
    @@ -529,7 +529,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/ValAxisData.html b/doc/Axlsx/ValAxisData.html
    index 7fb222d2..a471d919 100644
    --- a/doc/Axlsx/ValAxisData.html
    +++ b/doc/Axlsx/ValAxisData.html
    @@ -317,7 +317,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/View3D.html b/doc/Axlsx/View3D.html
    index c310792f..3239e75b 100644
    --- a/doc/Axlsx/View3D.html
    +++ b/doc/Axlsx/View3D.html
    @@ -962,7 +962,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/Axlsx/Workbook.html b/doc/Axlsx/Workbook.html
    index 47675817..bd6b1e44 100644
    --- a/doc/Axlsx/Workbook.html
    +++ b/doc/Axlsx/Workbook.html
    @@ -237,6 +237,33 @@ A colllection of drawings associated with this workbook.
     

    + + + +
  • + + + - (SimpleTypedList) images + + + + + + + readonly + + + + + + + + +

    +A colllection of images associated with this workbook. +

    +
    +
  • @@ -571,23 +598,25 @@ the object that the method was called on
     
     
    -75
    -76
    -77
    -78
    -79
    -80
    -81
    -82
    +82 +83 +84 +85 +86 +87 +88 +89 +90
    -
    # File 'lib/axlsx/workbook/workbook.rb', line 75
    +      
    # File 'lib/axlsx/workbook/workbook.rb', line 82
     
     def initialize(options={})
       @styles = Styles.new
       @worksheets = SimpleTypedList.new Worksheet
       @drawings = SimpleTypedList.new Drawing
       @charts = SimpleTypedList.new Chart
    +  @images = SimpleTypedList.new Pic
       self.date1904= options[:date1904] unless options[:date1904].nil?
       yield self if block_given?      
     end
    @@ -718,10 +747,10 @@ Instance level access to the class variable 1904
           
     
     
    -67
    +74
    -
    # File 'lib/axlsx/workbook/workbook.rb', line 67
    +      
    # File 'lib/axlsx/workbook/workbook.rb', line 74
     
     def date1904() @@date1904; end
     
    @@ -789,6 +818,81 @@ A colllection of drawings associated with this workbook
     
     
    +59
    +60
    +61
    + + +
    # File 'lib/axlsx/workbook/workbook.rb', line 59
    +
    +def drawings
    +  @drawings
    +end
    +
    + + + + + + + + +
    +

    + + - (SimpleTypedList) images (readonly) + + + +

    +
    + +
    + Note: +

    +The recommended way to manage images is Worksheet#add_image +

    +
    +
    + +

    +A colllection of images associated with this workbook +

    + + +
    +
    +
    + +

    Returns:

    + + +

    See Also:

    + + +
    + + @@ -846,17 +950,17 @@ The workbook relationships. This is managed automatically by the workbook
     
     
    -63
    -64
    -65
    -66
    -67
    -68
    -69
    -70
    +70 +71 +72 +73 +74 +75 +76 +77
    +
    +
    +
     52
     53
     54
    @@ -796,8 +900,8 @@ A colllection of drawings associated with this workbook
    # File 'lib/axlsx/workbook/workbook.rb', line 52
     
    -def drawings
    -  @drawings
    +def images
    +  @images
     end
     
    -
    # File 'lib/axlsx/workbook/workbook.rb', line 63
    +      
    # File 'lib/axlsx/workbook/workbook.rb', line 70
     
     def relationships
       r = Relationships.new
    @@ -931,12 +1035,12 @@ The styles associated with this workbook
           
     
     
    -59
    -60
    -61
    +66 +67 +68
    -
    # File 'lib/axlsx/workbook/workbook.rb', line 59
    +      
    # File 'lib/axlsx/workbook/workbook.rb', line 66
     
     def styles
       @styles
    @@ -1067,10 +1171,10 @@ retrieves the date1904 attribute
           
     
     
    -93
    +101
    -
    # File 'lib/axlsx/workbook/workbook.rb', line 93
    +      
    # File 'lib/axlsx/workbook/workbook.rb', line 101
     
     def self.date1904() @@date1904; end
     
    @@ -1117,10 +1221,10 @@ Sets the date1904 attribute to the provided boolean
     
     
    -89
    +97
    -
    # File 'lib/axlsx/workbook/workbook.rb', line 89
    +      
    # File 'lib/axlsx/workbook/workbook.rb', line 97
     
     def self.date1904=(v) Axlsx::validate_boolean v; @@date1904 = v end
     
    @@ -1237,14 +1341,14 @@ The name of the worksheet.
     
     
    -99
    -100
    -101
    -102
    -103
    +107 +108 +109 +110 +111
    -
    # File 'lib/axlsx/workbook/workbook.rb', line 99
    +      
    # File 'lib/axlsx/workbook/workbook.rb', line 107
     
     def add_worksheet(options={})
       worksheet = Worksheet.new(self, options)
    @@ -1295,23 +1399,23 @@ Serializes the workbook document
           
     
     
    -116
    -117
    -118
    -119
    -120
    -121
    -122
    -123
     124
     125
     126
     127
     128
    -129
    +129 +130 +131 +132 +133 +134 +135 +136 +137
    -
    # File 'lib/axlsx/workbook/workbook.rb', line 116
    +      
    # File 'lib/axlsx/workbook/workbook.rb', line 124
     
     def to_xml()
       add_worksheet unless worksheets.size > 0
    @@ -1338,7 +1442,7 @@ Serializes the workbook document
     
         
         
    diff --git a/doc/Axlsx/Worksheet.html b/doc/Axlsx/Worksheet.html
    index 3b43a42c..74a98d58 100644
    --- a/doc/Axlsx/Worksheet.html
    +++ b/doc/Axlsx/Worksheet.html
    @@ -413,6 +413,30 @@ Adds a chart to this worksheets drawing.
     

    + + + +
  • + + + - (Object) add_image(options = {}) {|image| ... } + + + + + + + + + + + + +

    +Adds a media item to the worksheets drawing. +

    +
    +
  • @@ -1451,6 +1475,119 @@ a customizable set of options
    +
    + +
    +

    + + - (Object) add_image(options = {}) {|image| ... } + + + +

    +
    +

    +Adds a media item to the worksheets drawing +

    + + +
    +
    +
    +

    Parameters:

    +
      + +
    • + + media_type + + + (Class) + + + +
    • + +
    • + + options + + + (Hash) + + + (defaults to: {}) + + + — +

      +a customizable set of options +

      +
      + +
    • + +
    + + + + +

    Options Hash (options):

    +
      + +
    • + [] + (Object) + + + + —

      +unknown +

      +
      +
    • + +
    + + +

    Yields:

    +
      + +
    • + + + (image) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +125
    +126
    +127
    +128
    +129
    +
    +
    # File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 125
    +
    +def add_image(options={})
    +  image = drawing.add_image(options)
    +  yield image if block_given?
    +  image
    +end
    +
    +
    @@ -1660,22 +1797,22 @@ hash of auto_fit_data
     
     
    -190
    -191
    -192
    -193
    -194
    -195
    -196
    -197
    -198
    -199
    +199 +200 +201 +202 +203 +204 +205 +206 +207 +208
    -
    # File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 190
    +      
    # File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 199
     
     def auto_width(col)
    -  mdw = 6.0 # maximum digit with is always 6.0 in testable fonts so instead of beating RMagick every time, I am hardcoding it here.
    +  mdw = 6.0 # maximum digit with is always 6.0 with RMagick's default font
       mdw_count = 0 
       best_guess = 1.5  #direct testing shows the results of the documented formula to be a bit too small. This is a best guess scaling
       font_scale = col[:sz].to_f / (self.workbook.styles.fonts[0].sz.to_f || 11.0)
    @@ -1728,15 +1865,6 @@ Serializes the worksheet document
           
     
     
    -124
    -125
    -126
    -127
    -128
    -129
    -130
    -131
    -132
     133
     134
     135
    @@ -1748,10 +1876,19 @@ Serializes the worksheet document
     141
     142
     143
    -144
    +144 +145 +146 +147 +148 +149 +150 +151 +152 +153
    -
    # File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 124
    +      
    # File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 133
     
     def to_xml
       builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
    @@ -1847,15 +1984,6 @@ of Cell objects
           
     
     
    -162
    -163
    -164
    -165
    -166
    -167
    -168
    -169
    -170
     171
     172
     173
    @@ -1865,10 +1993,19 @@ of Cell objects
     177
     178
     179
    -180
    +180 +181 +182 +183 +184 +185 +186 +187 +188 +189
    -
    # File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 162
    +      
    # File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 171
     
     def update_auto_fit_data(cells)
       styles = self.workbook.styles
    @@ -1900,7 +2037,7 @@ of Cell objects
     
         
         
    diff --git a/doc/Axlsx/Xf.html b/doc/Axlsx/Xf.html
    index 3bc5617c..ce88b303 100644
    --- a/doc/Axlsx/Xf.html
    +++ b/doc/Axlsx/Xf.html
    @@ -1672,7 +1672,7 @@ The document builder instance this objects xml will be added to.
     
         
         
    diff --git a/doc/_index.html b/doc/_index.html
    index aecdfb4b..c1c95126 100644
    --- a/doc/_index.html
    +++ b/doc/_index.html
    @@ -356,6 +356,13 @@
               
  • O
  • +

    Adding an Image

    + +
     p = Axlsx::Package.new
    + p.workbook.add_worksheet do |sheet|
    +   sheet.add_image(:image_src => (File.dirname(__FILE__) + "/image1.png")) do |image|
    +     image.width=720
    +     image.height=666
    +     image.start_at 2, 2
    +   end
    + end  
    + p.serialize("example7.xlsx")
    +
    +

    Documentation

    This gem is 100% documented with YARD, an exceptional documentation library. To see documentation for this, and all the gems installed on your system use:

    @@ -208,7 +223,13 @@ It enables the you to generate 100% valid xlsx files that include customised sty

    Changelog

      -
    • October.23.11: 1.0.7 released +
    • October.23.11: 1.0.8 release

      + +
        +
      • Added support for images (jpg, gif, png) in worksheets.
      • +
      +
    • +
    • October.23.11: 1.0.7 released

      • Added support for 3D options when creating a new chart. This lets you set the persective, rotation and other 3D attributes when using worksheet.add_chart
      • @@ -227,6 +248,10 @@ It enables the you to generate 100% valid xlsx files that include customised sty

        Please see the CHANGELOG document for past release information.

        +

        Help Wanted

        + +

        I'd really like to get rid of the depenency on RMagick in this gem. RMagic is being used to calculate the column widths in a worksheet based on the content the user specified. If there happens to be anyone out there with the background and skill set to write an extenstion that can determine the width of a singel character render with a specific font at a specific size please give me a shout.

        +

        Copyright

        Axlsx © 2011 by Randy Morgan. Axlsx is @@ -234,7 +259,7 @@ licensed under the MIT license. Please see the

        diff --git a/doc/index.html b/doc/index.html index 028a3e27..7f999f96 100644 --- a/doc/index.html +++ b/doc/index.html @@ -61,14 +61,14 @@ Author: Randy Morgan
        Copyright: 2011
        License: MIT License
        -Latest Version: 1.0.7
        +Latest Version: 1.0.8
        Ruby Version: 1.8.7
        Release Date: November 23nd 2011

        Synopsis

        Axlsx is an Office Open XML Spreadsheet generator for the Ruby programming language. -It enables the you to generate 100% valid xlsx files that include customised styling 3D pie, bar and line charts. Below is a summary of salient features.

        +It enables the you to generate 100% valid xlsx files that include customised styling, images, 3D pie, bar and line charts and auto-width columns. Below is a summary of salient features.

        Feature List

        @@ -84,6 +84,8 @@ It enables the you to generate 100% valid xlsx files that include customised sty

        **6. Support for both 1904 and 1900 epocs configurable in the workbook.

        +

        **7. Add jpg, gif and png images to worksheets

        +

        Installing

        To install Axlsx, use the following command:

        @@ -193,6 +195,19 @@ It enables the you to generate 100% valid xlsx files that include customised sty p.serialize("example6.xlsx")
    +

    Adding an Image

    + +
     p = Axlsx::Package.new
    + p.workbook.add_worksheet do |sheet|
    +   sheet.add_image(:image_src => (File.dirname(__FILE__) + "/image1.png")) do |image|
    +     image.width=720
    +     image.height=666
    +     image.start_at 2, 2
    +   end
    + end  
    + p.serialize("example7.xlsx")
    +
    +

    Documentation

    This gem is 100% documented with YARD, an exceptional documentation library. To see documentation for this, and all the gems installed on your system use:

    @@ -208,7 +223,13 @@ It enables the you to generate 100% valid xlsx files that include customised sty

    Changelog

      -
    • October.23.11: 1.0.7 released +
    • October.23.11: 1.0.8 release

      + +
        +
      • Added support for images (jpg, gif, png) in worksheets.
      • +
      +
    • +
    • October.23.11: 1.0.7 released

      • Added support for 3D options when creating a new chart. This lets you set the persective, rotation and other 3D attributes when using worksheet.add_chart
      • @@ -227,6 +248,10 @@ It enables the you to generate 100% valid xlsx files that include customised sty

        Please see the CHANGELOG document for past release information.

        +

        Help Wanted

        + +

        I'd really like to get rid of the depenency on RMagick in this gem. RMagic is being used to calculate the column widths in a worksheet based on the content the user specified. If there happens to be anyone out there with the background and skill set to write an extenstion that can determine the width of a singel character render with a specific font at a specific size please give me a shout.

        +

        Copyright

        Axlsx © 2011 by Randy Morgan. Axlsx is @@ -234,7 +259,7 @@ licensed under the MIT license. Please see the

        diff --git a/doc/method_list.html b/doc/method_list.html index 8b35aedf..704dd4d6 100644 --- a/doc/method_list.html +++ b/doc/method_list.html @@ -321,7 +321,23 @@
      • - #add_row + #add_chart + + Axlsx::TwoCellAnchor + +
      • + + +
      • + #add_image + + Axlsx::Drawing + +
      • + + +
      • + #add_image Axlsx::Worksheet @@ -329,6 +345,14 @@
      • + #add_row + + Axlsx::Worksheet + +
      • + + +
      • #add_series Axlsx::Chart @@ -336,7 +360,7 @@
      • -
      • +
      • #add_style Axlsx::Styles @@ -344,7 +368,7 @@
      • -
      • +
      • #add_worksheet Axlsx::Workbook @@ -352,7 +376,7 @@
      • -
      • +
      • #alignment Axlsx::Xf @@ -360,7 +384,7 @@
      • -
      • +
      • #allowed_types Axlsx::SimpleTypedList @@ -368,7 +392,7 @@
      • -
      • +
      • #anchor Axlsx::GraphicFrame @@ -376,6 +400,14 @@
      • +
      • + #anchor + + Axlsx::Pic + +
      • + +
      • #anchors @@ -633,33 +665,33 @@
      • - #chart + #chart - Axlsx::Series + Axlsx::GraphicFrame
      • - #chart + #chart - Axlsx::GraphicFrame + Axlsx::Series
      • - #charts + #charts - Axlsx::Workbook + Axlsx::Drawing
      • - #charts + #charts - Axlsx::Drawing + Axlsx::Workbook
      • @@ -689,25 +721,25 @@
      • - #color + #color - Axlsx::GradientStop + Axlsx::Font
      • - #color + #color - Axlsx::Font + Axlsx::BorderPr
      • - #color + #color - Axlsx::BorderPr + Axlsx::GradientStop
      • @@ -777,31 +809,31 @@
      • - #data + #data - Axlsx::PieSeries + Axlsx::BarSeries
      • - #data + #data - Axlsx::BarSeries + Axlsx::LineSeries
      • - #data + #data - Axlsx::LineSeries + Axlsx::PieSeries
      • - date1904 + #date1904 Axlsx::Workbook @@ -809,7 +841,7 @@
      • - #date1904 + date1904 Axlsx::Workbook @@ -873,6 +905,14 @@
      • + #descr + + Axlsx::Pic + +
      • + + +
      • #diagonalDown Axlsx::Border @@ -880,7 +920,7 @@
      • -
      • +
      • #diagonalUp Axlsx::Border @@ -888,6 +928,14 @@
      • +
      • + #drawing + + Axlsx::TwoCellAnchor + +
      • + +
      • #drawing @@ -897,9 +945,9 @@
      • - #drawing + #drawing - Axlsx::TwoCellAnchor + Axlsx::OneCellAnchor
      • @@ -953,6 +1001,14 @@
      • + #extname + + Axlsx::Pic + +
      • + + +
      • #family Axlsx::Font @@ -960,7 +1016,7 @@
      • -
      • +
      • #fgColor Axlsx::PatternFill @@ -968,6 +1024,14 @@
      • +
      • + #file_name + + Axlsx::Pic + +
      • + +
      • #fillId @@ -1025,39 +1089,39 @@
      • - #from + #from - Axlsx::Chart + Axlsx::TwoCellAnchor
      • - #from + #from - Axlsx::TwoCellAnchor + Axlsx::Chart
      • - #gapDepth + #from - Axlsx::Line3DChart + Axlsx::OneCellAnchor
      • - #gapDepth + #gapDepth - Axlsx::Bar3DChart + Axlsx::Line3DChart
      • - #gapWidth + #gapDepth Axlsx::Bar3DChart @@ -1065,17 +1129,17 @@
      • - #graphic_frame + #gapWidth - Axlsx::Chart + Axlsx::Bar3DChart
      • - #graphic_frame + #graphic_frame - Axlsx::TwoCellAnchor + Axlsx::Chart
      • @@ -1105,14 +1169,22 @@
      • - #hidden + #height - Axlsx::CellProtection + Axlsx::OneCellAnchor
      • + #height + + Axlsx::Pic + +
      • + + +
      • #hidden Axlsx::CellStyle @@ -1120,6 +1192,14 @@
      • +
      • + #hidden + + Axlsx::CellProtection + +
      • + +
      • #horizontal @@ -1145,49 +1225,49 @@
      • - #indent + #image_src - Axlsx::CellAlignment + Axlsx::Pic
      • - #index + #images - Axlsx::TwoCellAnchor + Axlsx::Drawing
      • - #index + #images - Axlsx::Series + Axlsx::Workbook
      • - #index + #indent - Axlsx::Chart + Axlsx::CellAlignment
      • - #index + #index - Axlsx::Drawing + Axlsx::Chart
      • - #index + #index - Axlsx::Worksheet + Axlsx::Cell
      • @@ -1201,153 +1281,153 @@
      • - #index + #index - Axlsx::Cell + Axlsx::Worksheet
      • - #initalize + #index - Axlsx::App + Axlsx::Series
      • - #initialize + #index - Axlsx::SerAxis + Axlsx::OneCellAnchor
      • - #initialize + #index - Axlsx::Fill + Axlsx::Pic
      • - #initialize + #index - Axlsx::TableStyles + Axlsx::Drawing
      • - #initialize + #index - Axlsx::SimpleTypedList + Axlsx::TwoCellAnchor
      • - #initialize + #initalize - Axlsx::Relationship + Axlsx::App
      • - #initialize + #initialize - Axlsx::CellStyle + Axlsx::BarSeries
      • - #initialize + #initialize - Axlsx::Bar3DChart + Axlsx::Title
      • - #initialize + #initialize - Axlsx::Marker + Axlsx::SimpleTypedList
      • - #initialize + #initialize - Axlsx::View3D + Axlsx::Bar3DChart
      • - #initialize + #initialize - Axlsx::Core + Axlsx::GradientStop
      • - #initialize + #initialize - Axlsx::TableStyle + Axlsx::CatAxisData
      • - #initialize + #initialize - Axlsx::Axis + Axlsx::CatAxis
      • - #initialize + #initialize - Axlsx::GradientStop + Axlsx::ContentType
      • - #initialize + #initialize - Axlsx::Pie3DChart + Axlsx::Marker
      • - #initialize + #initialize - Axlsx::CellProtection + Axlsx::Xf
      • - #initialize + #initialize - Axlsx::Xf + Axlsx::Row
      • - #initialize + #initialize - Axlsx::BarSeries + Axlsx::LineSeries
      • @@ -1361,41 +1441,41 @@
      • - #initialize + #initialize - Axlsx::Package + Axlsx::TableStyles
      • - #initialize + #initialize - Axlsx::TableStyleElement + Axlsx::Default
      • - #initialize + #initialize - Axlsx::Drawing + Axlsx::Font
      • - #initialize + #initialize - Axlsx::Series + Axlsx::TableStyleElement
      • - #initialize + #initialize - Axlsx::TwoCellAnchor + Axlsx::Core
      • @@ -1409,25 +1489,25 @@
      • - #initialize + #initialize - Axlsx::Default + Axlsx::Worksheet
      • - #initialize + #initialize - Axlsx::CatAxis + Axlsx::CellProtection
      • - #initialize + #initialize - Axlsx::Color + Axlsx::Pie3DChart
      • @@ -1441,126 +1521,134 @@
      • - #initialize + #initialize - Axlsx::PatternFill + Axlsx::CellAlignment
      • - #initialize + #initialize - Axlsx::CatAxisData + Axlsx::Pic
      • - #initialize + #initialize - Axlsx::Relationships + Axlsx::PieSeries
      • - #initialize + #initialize - Axlsx::Row + Axlsx::TableStyle
      • - #initialize + #initialize - Axlsx::Scaling + Axlsx::GraphicFrame
      • - #initialize + #initialize - Axlsx::Workbook + Axlsx::Line3DChart
      • - #initialize + #initialize - Axlsx::NumFmt + Axlsx::BorderPr
      • - #initialize + #initialize - Axlsx::CellAlignment + Axlsx::Drawing
      • - #initialize + #initialize - Axlsx::Title + Axlsx::Override
      • - #initialize + #initialize - Axlsx::Worksheet + Axlsx::Styles
      • - #initialize + #initialize - Axlsx::GraphicFrame + Axlsx::Fill
      • - #initialize + #initialize - Axlsx::Font + Axlsx::OneCellAnchor
      • - #initialize + #initialize - Axlsx::Styles + Axlsx::View3D
      • - #initialize + #initialize - Axlsx::ValAxis + Axlsx::Workbook
      • - #initialize + #initialize - Axlsx::PieSeries + Axlsx::CellStyle
      • + #initialize + + Axlsx::SerAxis + +
      • + + +
      • #initialize Axlsx::Cell @@ -1568,71 +1656,103 @@
      • +
      • + #initialize + + Axlsx::Relationship + +
      • + +
      • - #initialize + #initialize - Axlsx::LineSeries + Axlsx::Package
      • - #initialize + #initialize - Axlsx::Override + Axlsx::ValAxis
      • - #initialize + #initialize - Axlsx::BorderPr + Axlsx::PatternFill
      • - #initialize + #initialize - Axlsx::ContentType + Axlsx::Series
      • - #initialize + #initialize - Axlsx::Line3DChart + Axlsx::Axis
      • - #justifyLastLine + #initialize - Axlsx::CellAlignment + Axlsx::TwoCellAnchor
      • - #labels + #initialize - Axlsx::LineSeries + Axlsx::Relationships
      • - #labels + #initialize - Axlsx::BarSeries + Axlsx::NumFmt
      • + #initialize + + Axlsx::Color + +
      • + + +
      • + #initialize + + Axlsx::Scaling + +
      • + + +
      • + #justifyLastLine + + Axlsx::CellAlignment + +
      • + + +
      • #labels Axlsx::PieSeries @@ -1640,7 +1760,23 @@
      • +
      • + #labels + + Axlsx::LineSeries + +
      • + +
      • + #labels + + Axlsx::BarSeries + +
      • + + +
      • #lblAlgn Axlsx::CatAxis @@ -1648,7 +1784,7 @@
      • -
      • +
      • #lblOffset Axlsx::CatAxis @@ -1656,7 +1792,7 @@
      • -
      • +
      • #left Axlsx::GradientFill @@ -1664,7 +1800,7 @@
      • -
      • +
      • #lock Axlsx::SimpleTypedList @@ -1672,7 +1808,7 @@
      • -
      • +
      • #locked Axlsx::CellProtection @@ -1680,7 +1816,7 @@
      • -
      • +
      • #locked_at Axlsx::SimpleTypedList @@ -1688,7 +1824,7 @@
      • -
      • +
      • #logBase Axlsx::Scaling @@ -1696,7 +1832,7 @@
      • -
      • +
      • #max Axlsx::Scaling @@ -1704,7 +1840,7 @@
      • -
      • +
      • #method_missing Axlsx::SimpleTypedList @@ -1712,7 +1848,7 @@
      • -
      • +
      • #min Axlsx::Scaling @@ -1720,6 +1856,14 @@
      • +
      • + #name + + Axlsx::Worksheet + +
      • + +
      • #name @@ -1729,33 +1873,33 @@
      • - #name + #name - Axlsx::TableStyle + Axlsx::BorderPr
      • - #name + #name - Axlsx::Font + Axlsx::TableStyle
      • - #name + #name - Axlsx::Worksheet + Axlsx::Pic
      • - #name + #name - Axlsx::BorderPr + Axlsx::Font
      • @@ -1784,6 +1928,22 @@ +
      • + #object + + Axlsx::OneCellAnchor + +
      • + + +
      • + #object + + Axlsx::TwoCellAnchor + +
      • + +
      • #order @@ -1801,17 +1961,17 @@
      • - #outline + #outline - Axlsx::Border + Axlsx::Font
      • - #outline + #outline - Axlsx::Font + Axlsx::Border
      • @@ -1857,17 +2017,17 @@
      • - #pn + #pn - Axlsx::Worksheet + Axlsx::Drawing
      • - #pn + #pn - Axlsx::Drawing + Axlsx::Pic
      • @@ -1881,6 +2041,14 @@
      • + #pn + + Axlsx::Worksheet + +
      • + + +
      • #position Axlsx::GradientStop @@ -1888,7 +2056,7 @@
      • -
      • +
      • #protected? Axlsx::SimpleTypedList @@ -1896,7 +2064,7 @@
      • -
      • +
      • #protection Axlsx::Xf @@ -1904,7 +2072,7 @@
      • -
      • +
      • #prs Axlsx::Border @@ -1912,7 +2080,7 @@
      • -
      • +
      • #push Axlsx::SimpleTypedList @@ -1920,7 +2088,7 @@
      • -
      • +
      • #quotePrefix Axlsx::Xf @@ -1928,7 +2096,7 @@
      • -
      • +
      • #r Axlsx::Cell @@ -1936,7 +2104,7 @@
      • -
      • +
      • #rAngAx Axlsx::View3D @@ -1944,7 +2112,7 @@
      • -
      • +
      • #rId Axlsx::Drawing @@ -1952,7 +2120,7 @@
      • -
      • +
      • #rId Axlsx::GraphicFrame @@ -1960,7 +2128,7 @@
      • -
      • +
      • #rId Axlsx::Worksheet @@ -1968,7 +2136,7 @@
      • -
      • +
      • #r_abs Axlsx::Cell @@ -1976,7 +2144,7 @@
      • -
      • +
      • #range Axlsx::Title @@ -1984,7 +2152,7 @@
      • -
      • +
      • #readingOrder Axlsx::CellAlignment @@ -1992,7 +2160,7 @@
      • -
      • +
      • #relationships Axlsx::Worksheet @@ -2000,15 +2168,15 @@
      • -
      • - #relationships +
      • + #relationships - Axlsx::Drawing + Axlsx::Package
      • -
      • +
      • #relationships Axlsx::Workbook @@ -2016,15 +2184,15 @@
      • -
      • - #relationships +
      • + #relationships - Axlsx::Package + Axlsx::Drawing
      • -
      • +
      • #relativeIndent Axlsx::CellAlignment @@ -2032,23 +2200,23 @@
      • -
      • - #rels_pn +
      • + #rels_pn - Axlsx::Drawing + Axlsx::Worksheet
      • -
      • - #rels_pn +
      • + #rels_pn - Axlsx::Worksheet + Axlsx::Drawing
      • -
      • +
      • #rgb Axlsx::Color @@ -2056,7 +2224,7 @@
      • -
      • +
      • #right Axlsx::GradientFill @@ -2064,7 +2232,7 @@
      • -
      • +
      • #rotX Axlsx::View3D @@ -2072,7 +2240,7 @@
      • -
      • +
      • #rotY Axlsx::View3D @@ -2080,7 +2248,7 @@
      • -
      • +
      • #row Axlsx::Cell @@ -2088,7 +2256,7 @@
      • -
      • +
      • #row Axlsx::Marker @@ -2096,7 +2264,7 @@
      • -
      • +
      • #rowOff Axlsx::Marker @@ -2104,7 +2272,7 @@
      • -
      • +
      • #rows Axlsx::Worksheet @@ -2112,7 +2280,7 @@
      • -
      • +
      • #scaling Axlsx::Axis @@ -2120,7 +2288,7 @@
      • -
      • +
      • #serAxis Axlsx::Line3DChart @@ -2128,7 +2296,7 @@
      • -
      • +
      • #serialize Axlsx::Package @@ -2136,7 +2304,7 @@
      • -
      • +
      • #serialize_as Axlsx::SimpleTypedList @@ -2144,7 +2312,7 @@
      • -
      • +
      • #series Axlsx::Chart @@ -2152,7 +2320,7 @@
      • -
      • +
      • #series_type Axlsx::Chart @@ -2160,7 +2328,7 @@
      • -
      • +
      • #shadow Axlsx::Font @@ -2168,7 +2336,7 @@
      • -
      • +
      • #shape Axlsx::Bar3DChart @@ -2176,7 +2344,7 @@
      • -
      • +
      • #shape Axlsx::BarSeries @@ -2184,7 +2352,7 @@
      • -
      • +
      • #show_legend Axlsx::Chart @@ -2192,7 +2360,7 @@
      • -
      • +
      • #shrinkToFit Axlsx::CellAlignment @@ -2200,7 +2368,7 @@
      • -
      • +
      • #size Axlsx::TableStyleElement @@ -2208,7 +2376,7 @@
      • -
      • +
      • #start_at Axlsx::Chart @@ -2216,6 +2384,14 @@
      • +
      • + #start_at + + Axlsx::Pic + +
      • + +
      • #stop @@ -2233,25 +2409,25 @@
      • - #style + #style - Axlsx::BorderPr + Axlsx::Chart
      • - #style + #style - Axlsx::Cell + Axlsx::BorderPr
      • - #style + #style - Axlsx::Chart + Axlsx::Cell
      • @@ -2353,425 +2529,441 @@
      • - #to + #to + + Axlsx::TwoCellAnchor + +
      • + + +
      • + #to + + Axlsx::Chart + +
      • + + +
      • + #to_xml - Axlsx::Chart + Axlsx::GradientStop
      • - #to + #to_xml - Axlsx::TwoCellAnchor + Axlsx::TableStyles
      • - #to_xml + #to_xml - Axlsx::SimpleTypedList + Axlsx::Cell
      • - #to_xml + #to_xml - Axlsx::Drawing + Axlsx::OneCellAnchor
      • - #to_xml + #to_xml - Axlsx::Relationship + Axlsx::Marker
      • - #to_xml + #to_xml - Axlsx::CellStyle + Axlsx::Row
      • - #to_xml + #to_xml - Axlsx::View3D + Axlsx::ContentType
      • - #to_xml + #to_xml - Axlsx::Bar3DChart + Axlsx::Title
      • - #to_xml + #to_xml - Axlsx::Fill + Axlsx::CatAxisData
      • - #to_xml + #to_xml - Axlsx::Default + Axlsx::Pie3DChart
      • - #to_xml + #to_xml - Axlsx::App + Axlsx::Override
      • - #to_xml + #to_xml - Axlsx::Core + Axlsx::Default
      • - #to_xml + #to_xml - Axlsx::Row + Axlsx::Border
      • - #to_xml + #to_xml - Axlsx::Axis + Axlsx::Font
      • - #to_xml + #to_xml - Axlsx::BorderPr + Axlsx::Styles
      • - #to_xml + #to_xml - Axlsx::Relationships + Axlsx::GraphicFrame
      • - #to_xml + #to_xml - Axlsx::Series + Axlsx::View3D
      • - #to_xml + #to_xml - Axlsx::Override + Axlsx::TableStyle
      • - #to_xml + #to_xml - Axlsx::PatternFill + Axlsx::CellAlignment
      • - #to_xml + #to_xml - Axlsx::TableStyle + Axlsx::Scaling
      • - #to_xml + #to_xml - Axlsx::GraphicFrame + Axlsx::PieSeries
      • - #to_xml + #to_xml - Axlsx::Font + Axlsx::ValAxisData
      • - #to_xml + #to_xml - Axlsx::BarSeries + Axlsx::SerAxis
      • - #to_xml + #to_xml - Axlsx::Worksheet + Axlsx::Line3DChart
      • - #to_xml + #to_xml - Axlsx::Pie3DChart + Axlsx::ValAxis
      • - #to_xml + #to_xml - Axlsx::SeriesTitle + Axlsx::PatternFill
      • - #to_xml + #to_xml - Axlsx::TableStyles + Axlsx::Drawing
      • - #to_xml + #to_xml - Axlsx::ContentType + Axlsx::Series
      • - #to_xml + #to_xml - Axlsx::ValAxisData + Axlsx::Relationship
      • - #to_xml + #to_xml - Axlsx::GradientFill + Axlsx::Relationships
      • - #to_xml + #to_xml - Axlsx::Line3DChart + Axlsx::CellStyle
      • - #to_xml + #to_xml - Axlsx::LineSeries + Axlsx::Xf
      • - #to_xml + #to_xml - Axlsx::ValAxis + Axlsx::Fill
      • - #to_xml + #to_xml - Axlsx::Chart + Axlsx::Axis
      • - #to_xml + #to_xml - Axlsx::TwoCellAnchor + Axlsx::NumFmt
      • - #to_xml + #to_xml - Axlsx::Workbook + Axlsx::Chart
      • - #to_xml + #to_xml - Axlsx::CellAlignment + Axlsx::CatAxis
      • - #to_xml + #to_xml - Axlsx::Scaling + Axlsx::Worksheet
      • - #to_xml + #to_xml - Axlsx::Title + Axlsx::BorderPr
      • - #to_xml + #to_xml - Axlsx::Cell + Axlsx::SeriesTitle
      • - #to_xml + #to_xml - Axlsx::CatAxisData + Axlsx::Color
      • - #to_xml + #to_xml - Axlsx::Marker + Axlsx::CellProtection
      • - #to_xml + #to_xml - Axlsx::GradientStop + Axlsx::SimpleTypedList
      • - #to_xml + #to_xml - Axlsx::CellProtection + Axlsx::Core
      • - #to_xml + #to_xml - Axlsx::SerAxis + Axlsx::TableStyleElement
      • - #to_xml + #to_xml - Axlsx::Styles + Axlsx::LineSeries
      • - #to_xml + #to_xml - Axlsx::PieSeries + Axlsx::BarSeries
      • - #to_xml + #to_xml - Axlsx::CatAxis + Axlsx::GradientFill
      • - #to_xml + #to_xml - Axlsx::Xf + Axlsx::Workbook
      • - #to_xml + #to_xml - Axlsx::NumFmt + Axlsx::App
      • - #to_xml + #to_xml - Axlsx::Color + Axlsx::TwoCellAnchor
      • - #to_xml + #to_xml - Axlsx::TableStyleElement + Axlsx::Bar3DChart
      • - #to_xml + #to_xml - Axlsx::Border + Axlsx::Pic
      • @@ -2785,9 +2977,9 @@
      • - #type + #type - Axlsx::GradientFill + Axlsx::Cell
      • @@ -2801,9 +2993,9 @@
      • - #type + #type - Axlsx::Cell + Axlsx::GradientFill
      • @@ -2841,33 +3033,33 @@
      • - #validate + validate - Axlsx::Package + Axlsx::RestrictionValidator
      • - validate + validate - Axlsx::RestrictionValidator + Axlsx::RegexValidator
      • - validate + validate - Axlsx::RegexValidator + Axlsx::DataTypeValidator
      • - validate + #validate - Axlsx::DataTypeValidator + Axlsx::Package
      • @@ -3001,30 +3193,38 @@
      • - #workbook + #width - Axlsx::Worksheet + Axlsx::OneCellAnchor
      • - #workbook + #width - Axlsx::Package + Axlsx::Pic
      • - #worksheet + #workbook - Axlsx::Row + Axlsx::Package
      • + #workbook + + Axlsx::Worksheet + +
      • + + +
      • #worksheet Axlsx::Drawing @@ -3032,6 +3232,14 @@
      • +
      • + #worksheet + + Axlsx::Row + +
      • + +
      • #worksheets diff --git a/doc/top-level-namespace.html b/doc/top-level-namespace.html index 61239b8e..b323bcd6 100644 --- a/doc/top-level-namespace.html +++ b/doc/top-level-namespace.html @@ -94,7 +94,7 @@ diff --git a/examples/example.rb b/examples/example.rb index cb405fe2..15b2205c 100644 --- a/examples/example.rb +++ b/examples/example.rb @@ -82,5 +82,18 @@ chart.add_series :data=>sheet.rows.first.cells[(1..-1)], :title=> sheet.rows.first.cells.first chart.add_series :data=>sheet.rows.last.cells[(1..-1)], :title=> sheet.rows.last.cells.first end + end p.serialize("example6.xlsx") + +#Add an Image + + p = Axlsx::Package.new + p.workbook.add_worksheet do |sheet| + sheet.add_image(:image_src => (File.dirname(__FILE__) + "/image1.png")) do |image| + image.width=720 + image.height=666 + image.start_at 2, 2 + end + end + p.serialize("example7.xlsx") diff --git a/examples/image1.gif b/examples/image1.gif new file mode 100644 index 00000000..06d56d2b Binary files /dev/null and b/examples/image1.gif differ diff --git a/examples/image1.jpeg b/examples/image1.jpeg new file mode 100644 index 00000000..ce1d0c56 Binary files /dev/null and b/examples/image1.jpeg differ diff --git a/examples/image1.jpg b/examples/image1.jpg new file mode 100644 index 00000000..25efc268 Binary files /dev/null and b/examples/image1.jpg differ diff --git a/examples/image1.png b/examples/image1.png new file mode 100644 index 00000000..20d9e3b8 Binary files /dev/null and b/examples/image1.png differ diff --git a/lib/axlsx/drawing/bar_series.rb b/lib/axlsx/drawing/bar_series.rb index 5e10eb0e..c4bffa8c 100644 --- a/lib/axlsx/drawing/bar_series.rb +++ b/lib/axlsx/drawing/bar_series.rb @@ -51,7 +51,6 @@ module Axlsx private - # assigns the data for this series def data=(v) DataTypeValidator.validate "Series.data", [SimpleTypedList], v; @data = v; end diff --git a/lib/axlsx/drawing/cat_axis_data.rb b/lib/axlsx/drawing/cat_axis_data.rb index 83dfa56e..60e6ee9d 100644 --- a/lib/axlsx/drawing/cat_axis_data.rb +++ b/lib/axlsx/drawing/cat_axis_data.rb @@ -7,6 +7,7 @@ module Axlsx def initialize(data=[]) super Object @list.concat data if data.is_a?(Array) + data.each { |i| @list << i } if data.is_a?(SimpleTypedList) end # Serializes the category axis data diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb index bf4a1bff..6be9cbfe 100644 --- a/lib/axlsx/drawing/chart.rb +++ b/lib/axlsx/drawing/chart.rb @@ -90,7 +90,6 @@ module Axlsx # backwards compatibility to allow chart.to and chart.from access to anchor markers # @note This will be disconinued in version 2.0.0. please use the start_at method - # def from @graphic_frame.anchor.from end diff --git a/lib/axlsx/drawing/drawing.rb b/lib/axlsx/drawing/drawing.rb index 385cd592..17347cd1 100644 --- a/lib/axlsx/drawing/drawing.rb +++ b/lib/axlsx/drawing/drawing.rb @@ -16,6 +16,8 @@ module Axlsx require 'axlsx/drawing/val_axis_data.rb' require 'axlsx/drawing/marker.rb' + + require 'axlsx/drawing/one_cell_anchor.rb' require 'axlsx/drawing/two_cell_anchor.rb' require 'axlsx/drawing/graphic_frame.rb' @@ -25,6 +27,9 @@ module Axlsx require 'axlsx/drawing/bar_3D_chart.rb' require 'axlsx/drawing/line_3D_chart.rb' + + require 'axlsx/drawing/pic.rb' + # A Drawing is a canvas for charts. Each worksheet has a single drawing that manages anchors. # The anchors reference the charts via graphical frames. This is not a trivial relationship so please do follow the advice in the note. # @note The recommended way to manage drawings is to use the Worksheet.add_chart method. @@ -46,6 +51,10 @@ module Axlsx # @return [Array] attr_reader :charts + # An array of image objects that are associated with this drawing's anchors + # @return [Array] + attr_reader :images + # The index of this drawing in the owning workbooks's drawings collection. # @return [Integer] attr_reader :index @@ -72,20 +81,33 @@ module Axlsx DataTypeValidator.validate "Drawing.worksheet", Worksheet, worksheet @worksheet = worksheet @worksheet.workbook.drawings << self - @anchors = SimpleTypedList.new TwoCellAnchor + @anchors = SimpleTypedList.new [TwoCellAnchor, OneCellAnchor] + end + + # Adds an image to the chart + # @note The recommended way to manage images is to use Worksheet.add_image. Please refer to that method for documentation. + # @see Worksheet#add_image + def add_image(options={}) + OneCellAnchor.new(self, options) + @anchors.last.object end - # Adds a chart to the drawing. # @note The recommended way to manage charts is to use Worksheet.add_chart. Please refer to that method for documentation. # @see Worksheet#add_chart def add_chart(chart_type, options={}) - TwoCellAnchor.new(self, chart_type, options) - @anchors.last.graphic_frame.chart + TwoCellAnchor.new(self, options) + @anchors.last.add_chart(chart_type, options) end def charts - @anchors.map { |a| a.graphic_frame.chart } + charts = @anchors.select { |a| a.object.is_a?(GraphicFrame) } + charts.map { |a| a.object.chart } + end + + def images + images = @anchors.select { |a| a.object.is_a?(Pic) } + images.map { |a| a.object } end def index @@ -106,10 +128,12 @@ module Axlsx def relationships r = Relationships.new - @anchors.each do |anchor| - chart = anchor.graphic_frame.chart + charts.each do |chart| r << Relationship.new(CHART_R, "../#{chart.pn}") end + images.each do |image| + r << Relationship.new(IMAGE_R, "../#{image.pn}") + end r end diff --git a/lib/axlsx/drawing/graphic_frame.rb b/lib/axlsx/drawing/graphic_frame.rb index 5e09fb8a..e8e5ba21 100644 --- a/lib/axlsx/drawing/graphic_frame.rb +++ b/lib/axlsx/drawing/graphic_frame.rb @@ -4,8 +4,6 @@ module Axlsx # @see Worksheet#add_chart class GraphicFrame - #TODO add in support for other graphical objects, primarily images. - # A reference to the chart object associated with this frame # @return [Chart] attr_reader :chart diff --git a/lib/axlsx/drawing/line_series.rb b/lib/axlsx/drawing/line_series.rb index eea1e0ee..40beeb84 100644 --- a/lib/axlsx/drawing/line_series.rb +++ b/lib/axlsx/drawing/line_series.rb @@ -26,7 +26,6 @@ module Axlsx # Serializes the series # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. # @return [String] - # TODO create series_cat and series_val classes as this serialization is duplicated def to_xml(xml) super(xml) do |xml| @labels.to_xml(xml) unless @labels.nil? diff --git a/lib/axlsx/drawing/one_cell_anchor.rb b/lib/axlsx/drawing/one_cell_anchor.rb new file mode 100644 index 00000000..caa0edae --- /dev/null +++ b/lib/axlsx/drawing/one_cell_anchor.rb @@ -0,0 +1,89 @@ +module Axlsx + # This class details a single cell anchor for drawings. + # @note The recommended way to manage drawings, images and charts is Worksheet#add_chart or Worksheet#add_image. + # @see Worksheet#add_chart + # @see Worksheet#add_image + class OneCellAnchor + + # A marker that defines the from cell anchor. The default from column and row are 0 and 0 respectively + # @return [Marker] + attr_reader :from + + # The object this anchor hosts + # @return [Pic] + attr_reader :object + + # The drawing that holds this anchor + # @return [Drawing] + attr_reader :drawing + + # The index of this anchor in the drawing + # @return [Integer] + attr_reader :index + + + # the width of the graphic object in pixels. + # this is converted to EMU at a 92 ppi resolution + # @return [Integer] + attr_accessor :width + + # the height of the graphic object in pixels + # this is converted to EMU at a 92 ppi resolution + # @return [Integer] + attr_accessor :height + + + # Creates a new OneCellAnchor object and an Pic associated with it. + # @param [Drawing] drawing + # @option options [Array] start_at the col, row to start at + # @option options [Integer] width + # @option options [Integer] height + # @option options [String] image_src the file location of the image you will render + # @option options [String] name the name attribute for the rendered image + # @option options [String] descr the description of the image rendered + def initialize(drawing, options={}) + @drawing = drawing + @width = 0 + @height = 0 + drawing.anchors << self + @from = Marker.new + options.each do |o| + self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" + end + @object = Pic.new(self, options) + end + + def height=(v) Axlsx::validate_unsigned_int(v); @height = v; end + def width=(v) Axlsx::validate_unsigned_int(v); @width = v; end + + def index + @drawing.anchors.index(self) + end + + # Serializes the anchor + # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. + # @return [String] + def to_xml(xml) + xml.send('xdr:oneCellAnchor') { + xml.send('xdr:from') { + from.to_xml(xml) + } + xml.send('xdr:ext', ext) + @object.to_xml(xml) + xml.send('xdr:clientData') + } + end + + private + + # converts the pixel width and height to EMU units and returns a hash of + # !{:cx=>[Integer], :cy=>[Integer] + # @return [Hash] + def ext + cy = @height * 914400 / 96 + cx = @width * 914400 / 96 + {:cy=>cy, :cx=>cx} + end + + end +end diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb new file mode 100644 index 00000000..7043df35 --- /dev/null +++ b/lib/axlsx/drawing/pic.rb @@ -0,0 +1,158 @@ +# -*- coding: utf-8 -*- +module Axlsx + # a Pic object represents an image in your worksheet + # Worksheet#add_image is the recommended way to manage images in your sheets + # @see Worksheet#add_image + class Pic + + # allowed file extenstions + ALLOWED_EXTENSIONS = ['gif', 'jpeg', 'png', 'jpg'] + + # The name to use for this picture + # @return [String] + attr_accessor :name + + # providing access to the anchor's width attribute + # @param [Integer] v + # @see OneCellAnchor.width + attr_accessor :width + + # providing access to update the anchor's height attribute + # @param [Integer] v + # @see OneCellAnchor.width + attr_accessor :height + + # A description of the picture + # @return [String] + attr_accessor :descr + + # The path to the image you want to include + # Only local images are supported at this time and only jpg support + # @return [String] + attr_accessor :image_src + + # The anchor for this image + # @return [OneCellAnchor] + attr_reader :anchor + + # returns the extension of image_src without the preceeding '.' + # @return [String] + attr_reader :extname + + # The file name of image_src without any path information + # @return [String] + attr_reader :file_name + + # The part name for this image used in serialization and relationship building + # @return [String] + attr_reader :pn + + # The index of this image in the workbooks images collections + # @return [Index] + attr_reader :index + + # The name of the image file, sans directory info + # @return [String] + attr_reader :file_name + + # Creates a new Pic(ture) object + # @param [Anchor] anchor the anchor that holds this image + # @option options [String] name + # @option options [String] descr + # @option options [String] image_src + # @option options [Array] start_at + # @option options [Intger] width + # @option options [Intger] height + def initialize(anchor, options={}) + @anchor = anchor + @anchor.drawing.worksheet.workbook.images << self + options.each do |o| + self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" + end + start_at *options[:start_at] if options[:start_at] + yield self if block_given? + end + + def image_src=(v) + Axlsx::validate_string(v) + RestrictionValidator.validate 'Pic.image_src', ALLOWED_EXTENSIONS, File.extname(v).delete('.') + raise ArgumentError, "File does not exist" unless File.exist?(v) + @image_src = v + end + + def name=(v) Axlsx::validate_string(v); @name = v; end + def descr=(v) Axlsx::validate_string(v); @descr = v; end + + def file_name + File.basename(image_src) unless image_src.nil? + end + + def extname + File.extname(image_src).delete('.') unless image_src.nil? + end + + def index + @anchor.drawing.worksheet.workbook.images.index(self) + end + + def pn + "#{IMAGE_PN % [(index+1), extname]}" + end + + def width + @anchor.width + end + + def width=(v) + @anchor.width = v + end + + def height=(v) + @anchor.height = v + end + + def height + @anchor.height + end + + # This is a short cut method to set the start anchor position + # If you need finer granularity in positioning use + # graphic_frame.anchor.from.colOff / rowOff + # @param [Integer] x The column + # @param [Integer] y The row + # @return [Marker] + def start_at(x, y) + @anchor.from.col = x + @anchor.from.row = y + end + + # Serializes the picture + # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. + # @return [String] + def to_xml(xml) + xml.send('xdr:pic') { + xml.send('xdr:nvPicPr') { + xml.send('xdr:cNvPr', :id=>"2", :name=>name, :descr=>descr) + xml.send('xdr:cNvPicPr') { + xml.send('a:picLocks', :noChangeAspect=>1) + } + } + xml.send('xdr:blipFill') { + xml.send('a:blip', :'xmlns:r' => XML_NS_R, :'r:embed'=>"rId1") + xml.send('a:stretch') { + xml.send('a:fillRect') + } + } + xml.send('xdr:spPr') { + xml.send('a:xfrm') { + xml.send('a:off', :x=>0, :y=>0) + xml.send('a:ext', :cx=>2336800, :cy=>2161540) + } + xml.send('a:prstGeom', :prst=>:rect) { + xml.send('a:avLst') + } + } + } + end + end +end diff --git a/lib/axlsx/drawing/pie_3D_chart.rb b/lib/axlsx/drawing/pie_3D_chart.rb index dacba313..3cd6e377 100644 --- a/lib/axlsx/drawing/pie_3D_chart.rb +++ b/lib/axlsx/drawing/pie_3D_chart.rb @@ -25,7 +25,6 @@ module Axlsx super(frame, options) @series_type = PieSeries @view3D = View3D.new({:rotX=>30, :perspective=>30}.merge(options)) - end # Serializes the pie chart diff --git a/lib/axlsx/drawing/two_cell_anchor.rb b/lib/axlsx/drawing/two_cell_anchor.rb index 62491b8c..73e2fe20 100644 --- a/lib/axlsx/drawing/two_cell_anchor.rb +++ b/lib/axlsx/drawing/two_cell_anchor.rb @@ -12,8 +12,13 @@ module Axlsx attr_reader :to # The frame for your chart + # @note this will be discontinued in version 2.0 please use object # @return [GraphicFrame] - attr_reader :graphic_frame + # attr_reader :graphic_frame + + # The object this anchor hosts + # @return [Pic, GraphicFrame] + attr_reader :object # The drawing that holds this anchor # @return [Drawing] @@ -27,15 +32,23 @@ module Axlsx # graphic_frame's chart. That means that you can do stuff like # c = worksheet.add_chart Axlsx::Chart # c.start_at 5, 9 + # @note the chart_type parameter will be replaced with object in v. 2.0.0 # @param [Drawing] drawing # @param [Class] chart_type This is passed to the graphic frame for instantiation. must be Chart or a subclass of Chart + # @param object The object this anchor holds. # @option options [Array] start_at the col, row to start at # @option options [Array] end_at the col, row to end at - def initialize(drawing, chart_type, options) + def initialize(drawing, options={}) @drawing = drawing drawing.anchors << self @from, @to = Marker.new, Marker.new(:col => 5, :row=>10) - @graphic_frame = GraphicFrame.new(self, chart_type, options) + end + + # Creates a graphic frame and chart object associated with this anchor + # @return [Chart] + def add_chart(chart_type, options) + @object = GraphicFrame.new(self, chart_type, options) + @object.chart end def index @@ -53,7 +66,7 @@ module Axlsx xml.send('xdr:to') { to.to_xml(xml) } - @graphic_frame.to_xml(xml) + @object.to_xml(xml) xml.send('xdr:clientData') } end diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index 25656d04..91df81df 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -54,10 +54,21 @@ module Axlsx # # You will find a file called test.xlsx def serialize(output, confirm_valid=false) return false unless !confirm_valid || self.validate.empty? - f = File.new(output, "w") - Zip::ZipOutputStream.open(f.path) do |zip| - parts.each{ |part| zip.put_next_entry(part[:entry]); zip.puts(part[:doc]) } + p = parts + Zip::ZipOutputStream.open(output) do |zip| + p.each do |part| + zip.put_next_entry(part[:entry]); zip.puts(part[:doc]) unless part[:doc].nil? + end end + Zip::ZipFile.open(output) do |zip| + p.each do |part| + if part[:path] + zip.add(part[:entry], part[:path], &proc{ true }) + end + end + end + + true end @@ -78,7 +89,7 @@ module Axlsx # p.validate.each { |error| puts error.message } def validate errors = [] - parts.each { |part| errors.concat validate_single_doc(part[:schema], part[:doc]) } + parts.each { |part| errors.concat validate_single_doc(part[:schema], part[:doc]) unless part[:schema].nil? } errors end @@ -105,7 +116,11 @@ module Axlsx workbook.charts.each do |chart| @parts << {:entry => "xl/#{chart.pn}", :doc => chart.to_xml, :schema => DRAWING_XSD} end - + + workbook.images.each do |image| + @parts << {:entry => "xl/#{image.pn}", :path => image.image_src} + end + workbook.worksheets.each do |sheet| @parts << {:entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships.to_xml, :schema => RELS_XSD} @parts << {:entry => "xl/#{sheet.pn}", :doc => sheet.to_xml, :schema => SML_XSD} @@ -147,6 +162,17 @@ module Axlsx c_types << Axlsx::Override.new(:PartName => "/xl/#{sheet.pn}", :ContentType => WORKSHEET_CT) end + exts = workbook.images.map { |image| image.extname } + exts.uniq.each do |ext| + ct = if ['jpeg', 'jpg'].include?(ext) + JPEG_CT + elsif ext == 'gif' + GIF_CT + elsif ext == 'png' + PNG_CT + end + c_types << Axlsx::Default.new(:ContentType => ct, :Extension => ext ) + end c_types end diff --git a/lib/axlsx/rels/relationship.rb b/lib/axlsx/rels/relationship.rb index 57b9afc0..a76c0c25 100644 --- a/lib/axlsx/rels/relationship.rb +++ b/lib/axlsx/rels/relationship.rb @@ -29,8 +29,7 @@ module Axlsx def Target=(v) Axlsx::validate_string v; @Target = v end def Type=(v) Axlsx::validate_relationship_type v; @Type = v end - # Serializes the relationship - # TODO: use object.rId to get this infomation + # Serializes the relationship # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. # @param [String] rId the reference id of the object. # @return [String] diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb index cb7d7607..50dd6f27 100644 --- a/lib/axlsx/util/constants.rb +++ b/lib/axlsx/util/constants.rb @@ -70,6 +70,9 @@ module Axlsx # chart rels namespace CHART_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart" + # image rels namespace + IMAGE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" + # table content type TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml" @@ -100,12 +103,30 @@ module Axlsx # chart content type CHART_CT = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml" + # jpeg content type + JPEG_CT = "image/jpeg" + + # gif content type + GIF_CT = "image/gif" + + # png content type + PNG_CT = "image/png" + #drawing content type DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml" # xml content type extensions XML_EX = "xml" + # jpeg extension + JPEG_EX = "jpeg" + + # gif extension + GIF_EX = "gif" + + # png extension + PNG_EX = "png" + # rels content type extension RELS_EX = "rels" @@ -145,6 +166,9 @@ module Axlsx # chart part CHART_PN = "charts/chart%d.xml" + # chart part + IMAGE_PN = "media/image%d.%s" + # App validation schema APP_XSD = "lib/schema/shared-documentPropertiesExtended.xsd" diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb index 01a1850a..827030c7 100644 --- a/lib/axlsx/util/validators.rb +++ b/lib/axlsx/util/validators.rb @@ -112,14 +112,14 @@ module Axlsx # TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, DRAWING_CT are allowed # @param [Any] v The value validated def self.validate_content_type(v) - RestrictionValidator.validate :content_type, [TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, DRAWING_CT], v + RestrictionValidator.validate :content_type, [TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, JPEG_CT, GIF_CT, PNG_CT, DRAWING_CT], v end # Requires that the value is a valid relationship_type # XML_NS_R, TABLE_R, WORKBOOK_R, WORKSHEET_R, APP_R, RELS_R, CORE_R, STYLES_R, CHART_R, DRAWING_R are allowed # @param [Any] v The value validated def self.validate_relationship_type(v) - RestrictionValidator.validate :relationship_type, [XML_NS_R, TABLE_R, WORKBOOK_R, WORKSHEET_R, APP_R, RELS_R, CORE_R, STYLES_R, CHART_R, DRAWING_R], v + RestrictionValidator.validate :relationship_type, [XML_NS_R, TABLE_R, WORKBOOK_R, WORKSHEET_R, APP_R, RELS_R, CORE_R, STYLES_R, CHART_R, DRAWING_R, IMAGE_R], v end # Requires that the value is a valid table element type diff --git a/lib/axlsx/version.rb b/lib/axlsx/version.rb index 0f3e00b6..ed7a1ff1 100644 --- a/lib/axlsx/version.rb +++ b/lib/axlsx/version.rb @@ -1,4 +1,4 @@ module Axlsx # version - VERSION="1.0.7" + VERSION="1.0.8" end diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb index 00da5247..76a3803c 100644 --- a/lib/axlsx/workbook/workbook.rb +++ b/lib/axlsx/workbook/workbook.rb @@ -44,6 +44,13 @@ require 'axlsx/workbook/worksheet/worksheet.rb' # @return [SimpleTypedList] attr_reader :charts + # A colllection of images associated with this workbook + # @note The recommended way to manage images is Worksheet#add_image + # @see Worksheet#add_image + # @see Pic + # @return [SimpleTypedList] + attr_reader :images + # A colllection of drawings associated with this workbook # @note The recommended way to manage drawings is Worksheet#add_chart # @see Worksheet#add_chart @@ -77,6 +84,7 @@ require 'axlsx/workbook/worksheet/worksheet.rb' @worksheets = SimpleTypedList.new Worksheet @drawings = SimpleTypedList.new Drawing @charts = SimpleTypedList.new Chart + @images = SimpleTypedList.new Pic self.date1904= options[:date1904] unless options[:date1904].nil? yield self if block_given? end diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index c82dbde9..861bb8ef 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -119,6 +119,15 @@ module Axlsx chart end + # Adds a media item to the worksheets drawing + # @param [Class] media_type + # @option options [] unknown + def add_image(options={}) + image = drawing.add_image(options) + yield image if block_given? + image + end + # Serializes the worksheet document # @return [String] def to_xml @@ -188,7 +197,7 @@ module Axlsx # @return [Float] # @param [Hash] A hash of auto_fit_data def auto_width(col) - mdw = 6.0 # maximum digit with is always 6.0 in testable fonts so instead of beating RMagick every time, I am hardcoding it here. + mdw = 6.0 # maximum digit with is always 6.0 with RMagick's default font mdw_count = 0 best_guess = 1.5 #direct testing shows the results of the documented formula to be a bit too small. This is a best guess scaling font_scale = col[:sz].to_f / (self.workbook.styles.fonts[0].sz.to_f || 11.0) diff --git a/test/drawing/tc_drawing.rb b/test/drawing/tc_drawing.rb index 474f5b51..7dd21c32 100644 --- a/test/drawing/tc_drawing.rb +++ b/test/drawing/tc_drawing.rb @@ -18,13 +18,22 @@ class TestDrawing < Test::Unit::TestCase chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1]) assert(chart.is_a?(Axlsx::Pie3DChart), "must create a chart") assert_equal(@ws.workbook.charts.last, chart, "must be added to workbook charts collection") - assert_equal(@ws.drawing.anchors.last.graphic_frame.chart, chart, "an anchor has been created and holds a reference to this chart") + assert_equal(@ws.drawing.anchors.last.object.chart, chart, "an anchor has been created and holds a reference to this chart") anchor = @ws.drawing.anchors.last assert_equal([anchor.from.row, anchor.from.col], [0,0], "options for start at are applied") assert_equal([anchor.to.row, anchor.to.col], [1,1], "options for start at are applied") assert_equal(chart.title.text, "bob", "option for title is applied") end + def test_add_image + src = File.dirname(__FILE__) + "/../../examples/image1.jpeg" + image = @ws.add_image(:image_src => src, :start_at=>[0,0], :width=>600, :height=>400) + assert(@ws.drawing.anchors.last.is_a?(Axlsx::OneCellAnchor)) + assert(image.is_a?(Axlsx::Pic)) + assert_equal(600, image.width) + assert_equal(400, image.height) + end + def test_charts assert(@ws.drawing.charts.empty?) chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1]) diff --git a/test/drawing/tc_one_cell_anchor.rb b/test/drawing/tc_one_cell_anchor.rb new file mode 100644 index 00000000..d2618622 --- /dev/null +++ b/test/drawing/tc_one_cell_anchor.rb @@ -0,0 +1,67 @@ +require 'test/unit' +require 'axlsx.rb' + +class TestOneCellAnchor < Test::Unit::TestCase + + def setup + @p = Axlsx::Package.new + @ws = @p.workbook.add_worksheet + @test_img = File.dirname(__FILE__) + "/../../examples/image1.jpeg" + @image = @ws.add_image :image_src => @test_img + @anchor = @image.anchor + end + + def teardown + end + + def test_initialization + assert(@anchor.from.col == 0) + assert(@anchor.from.row == 0) + assert(@anchor.width == 0) + assert(@anchor.height == 0) + end + + def test_from + assert(@anchor.from.is_a?(Axlsx::Marker)) + end + + def test_object + assert(@anchor.object.is_a?(Axlsx::Pic)) + end + + def test_index + assert(@anchor.index, @anchor.drawing.anchors.index(@anchor)) + end + + def test_width + assert_raise(ArgumentError) { @anchor.width = "a" } + assert_nothing_raised { @anchor.width = 600 } + assert_equal(@anchor.width, 600) + end + + def test_height + assert_raise(ArgumentError) { @anchor.height = "a" } + assert_nothing_raised { @anchor.height = 400 } + assert_equal(400, @anchor.height) + end + + def test_ext + ext = @anchor.send(:ext) + assert_equal(ext[:cx], (@anchor.width * 914400 / 96)) + assert_equal(ext[:cy], (@anchor.height * 914400 / 96)) + end + + def test_options + assert_raise(ArgumentError, 'invalid start_at') { @ws.add_image :image_src=>@test_img, :start_at=>[1] } + i = @ws.add_image :image_src=>@test_img, :start_at => [1,2], :width=>100, :height=>200, :name=>"someimage", :descr=>"a neat image" + + assert_equal("a neat image", i.descr) + assert_equal("someimage", i.name) + assert_equal(200, i.height) + assert_equal(100, i.width) + assert_equal(1, i.anchor.from.col) + assert_equal(2, i.anchor.from.row) + assert_equal(@test_img, i.image_src) + end + +end diff --git a/test/drawing/tc_pic.rb b/test/drawing/tc_pic.rb new file mode 100644 index 00000000..2d6c603d --- /dev/null +++ b/test/drawing/tc_pic.rb @@ -0,0 +1,71 @@ +require 'test/unit' +require 'axlsx.rb' + +class TestPic < Test::Unit::TestCase + + def setup + @p = Axlsx::Package.new + ws = @p.workbook.add_worksheet + @test_img = File.dirname(__FILE__) + "/../../examples/image1.jpeg" + @image = ws.add_image :image_src => @test_img + end + + def teardown + end + + def test_initialization + assert_equal(@p.workbook.images.first, @image) + assert_equal(@image.image_src, @test_img) + end + + def test_name + assert_raise(ArgumentError) { @image.name = 49 } + assert_nothing_raised { @image.name = "unknown" } + assert_equal(@image.name, "unknown") + end + + def test_start_at + assert_raise(ArgumentError) { @image.start_at "a", 1 } + assert_nothing_raised { @image.start_at 6, 7 } + assert_equal(@image.anchor.from.col, 6) + assert_equal(@image.anchor.from.row, 7) + end + + def test_width + assert_raise(ArgumentError) { @image.width = "a" } + assert_nothing_raised { @image.width = 600 } + assert_equal(@image.width, 600) + end + + def test_height + assert_raise(ArgumentError) { @image.height = "a" } + assert_nothing_raised { @image.height = 600 } + assert_equal(600, @image.height) + end + + def test_image_src + assert_raise(ArgumentError) { @image.image_src = 49 } + assert_raise(ArgumentError) { @image.image_src = 'Unknown' } + assert_raise(ArgumentError) { @image.image_src = __FILE__ } + assert_nothing_raised { @image.image_src = @test_img } + assert_equal(@image.image_src, @test_img) + end + + def test_descr + assert_raise(ArgumentError) { @image.descr = 49 } + assert_nothing_raised { @image.descr = "test" } + assert_equal(@image.descr, "test") + end + + def test_to_xml + schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD)) + doc = Nokogiri::XML(@image.anchor.drawing.to_xml) + errors = [] + schema.validate(doc).each do |error| + errors.push error + puts error.message + end + assert(errors.empty?, "error free validation") + end + +end diff --git a/test/tc_package.rb b/test/tc_package.rb index 1cba34c1..ad511161 100644 --- a/test/tc_package.rb +++ b/test/tc_package.rb @@ -16,8 +16,6 @@ class TestPackage < Test::Unit::TestCase assert(Axlsx::Package.new.workbook.worksheets.size == 0, 'Workbook should not have sheets by default') end - # TODO this test needs better file access validation! - # as does serialization! def test_serialization fname = 'axlsx_test_serialization.xlsx' assert_nothing_raised do -- cgit v1.2.3