summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-12-04 09:55:27 +0900
committerRandy Morgan <[email protected]>2012-12-04 09:55:27 +0900
commit66e1cc2178f78ee225642080b40b9a7811d92b8a (patch)
tree294a15978e2beab8ada28589fd1072b6af26ee57 /lib
parent265f30d9e827d7cfb8721c315c284de52e7395e5 (diff)
downloadcaxlsx-66e1cc2178f78ee225642080b40b9a7811d92b8a.tar.gz
caxlsx-66e1cc2178f78ee225642080b40b9a7811d92b8a.zip
Added sheet_format_pr to help iOS/OSX preview renderers look nice
This is part of https://github.com/randym/axlsx/issues/149
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/workbook/workbook.rb1
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_format_pr.rb60
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb11
3 files changed, 71 insertions, 1 deletions
diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb
index 54dd9df1..576367ba 100644
--- a/lib/axlsx/workbook/workbook.rb
+++ b/lib/axlsx/workbook/workbook.rb
@@ -46,6 +46,7 @@ require 'axlsx/workbook/worksheet/pivot_tables.rb'
require 'axlsx/workbook/worksheet/data_validation.rb'
require 'axlsx/workbook/worksheet/data_validations.rb'
require 'axlsx/workbook/worksheet/sheet_view.rb'
+require 'axlsx/workbook/worksheet/sheet_format_pr.rb'
require 'axlsx/workbook/worksheet/pane.rb'
require 'axlsx/workbook/worksheet/selection.rb'
# The Workbook class is an xlsx workbook that manages worksheets, charts, drawings and styles.
diff --git a/lib/axlsx/workbook/worksheet/sheet_format_pr.rb b/lib/axlsx/workbook/worksheet/sheet_format_pr.rb
new file mode 100644
index 00000000..f6c9df55
--- /dev/null
+++ b/lib/axlsx/workbook/worksheet/sheet_format_pr.rb
@@ -0,0 +1,60 @@
+module Axlsx
+
+ #Sheet formatting properties
+ # <xsd:complexType name="CT_SheetFormatPr">
+ # <xsd:attribute name="baseColWidth" type="xsd:unsignedInt" use="optional" default="8"/>
+ # <xsd:attribute name="defaultColWidth" type="xsd:double" use="optional"/>
+ # <xsd:attribute name="defaultRowHeight" type="xsd:double" use="required"/>
+ # <xsd:attribute name="customHeight" type="xsd:boolean" use="optional" default="false"/>
+ # <xsd:attribute name="zeroHeight" type="xsd:boolean" use="optional" default="false"/>
+ # <xsd:attribute name="thickTop" type="xsd:boolean" use="optional" default="false"/>
+ # <xsd:attribute name="thickBottom" type="xsd:boolean" use="optional" default="false"/>
+ # <xsd:attribute name="outlineLevelRow" type="xsd:unsignedByte" use="optional" default="0"/>
+ # <xsd:attribute name="outlineLevelCol" type="xsd:unsignedByte" use="optional" default="0"/>
+ #</xsd:complexType>
+
+ class SheetFormatPr
+ include Axlsx::SerializedAttributes
+ include Axlsx::OptionsParser
+ include Axlsx::Accessors
+
+ # creates a new sheet_format_pr object
+ # @param [Hash] options initialization options
+ # @option [Integer] base_col_width Specifies the number of characters of the maximum digit width of the normal style's font. This value does not include margin padding or extra padding for gridlines. It is only the number of characters.
+ # @option [Float] default_col_width Default column width measured as the number of characters of the maximum digit width of the normal style's font.
+ # @option [Float] default_row_height Default row height measured in point size. Optimization so we don't have to write the height on all rows. This can be written out if most rows have custom height, to achieve the optimization.
+ # @option [Boolean] custom_height 'True' if defaultRowHeight value has been manually set, or is different from the default value.
+ # @option [Boolean] zero_height 'True' if rows are hidden by default. This setting is an optimization used when most rows of the sheet are hidden.
+ # @option [Boolean] think_top 'True' if rows have a thick top border by default.
+ # @option [Boolean] thick_bottom 'True' if rows have a thick bottom border by default.
+ # @option [Integer] outline_level_row Highest number of outline level for rows in this sheet. These values shall be in synch with the actual sheet outline levels.
+ # @option [Integer] outline_level_col Highest number of outline levels for columns in this sheet. These values shall be in synch with the actual sheet outline levels.
+ #
+ def initialize(options={})
+ set_defaults
+ parse_options options
+ end
+
+ def set_defaults
+ @base_col_width = 8
+ @default_row_height = 18
+ end
+
+ serializable_attributes :base_col_width, :default_col_width, :default_row_height,
+ :custom_height, :zero_height, :thick_top, :thick_bottom,
+ :outline_level_row, :outline_level_col
+
+ float_attr_accessor :default_col_width, :default_row_height
+
+ boolean_attr_accessor :custom_height, :zero_height, :thick_top, :thick_bottom
+
+ unsigned_int_attr_accessor :base_col_width, :outline_level_row, :outline_level_col
+
+ # serializes this object to an xml string
+ # @param @str The string this objects serialization will be appended to
+ # @return [String]
+ def to_xml_string(str='')
+ str << "<sheetFormatPr #{serialized_attributes}/>"
+ end
+ end
+end
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index 4c59e340..832b6f37 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -69,6 +69,15 @@ module Axlsx
@sheet_view
end
+ # The sheet format pr for this worksheet
+ # @return [SheetFormatPr]
+ # @see [SheetFormatPr]
+ def sheet_format_pr
+ @sheet_format_pr ||= SheetFormatPr.new
+ yeild @sheet_format_pr if block_given?
+ @sheet_format_pr
+ end
+
# The workbook that owns this worksheet
# @return [Workbook]
attr_reader :workbook
@@ -613,7 +622,7 @@ module Axlsx
def serializable_parts
- [sheet_pr, dimension, sheet_view, column_info,
+ [sheet_pr, dimension, sheet_view, sheet_format_pr, column_info,
sheet_data, sheet_calc_pr, @sheet_protection, protected_ranges,
auto_filter, merged_cells, conditional_formattings,
data_validations, hyperlinks, print_options, page_margins,