Sha256: 413bc9f46ffaf3f765716e4174a86643b1bdff5668a59f48db508cfce1b70690

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

# -*- coding: utf-8 -*-
# frozen_string_literal: true

require 'write_xlsx/package/xml_writer_simple'
require 'write_xlsx/utility'

module Writexlsx
  module Package
    #
    # RichValueRel - A class for writing the Excel XLSX richValueRel.xml file.
    #
    # Used in conjunction with Excel::Writer::XLSX
    #
    # Copyright 2000-2024, John McNamara, jmcnamara@cpan.org
    #
    # Convert to Ruby by Hideo Nakamura, nakamura.hideo@gmail.com
    #
    class RichValueRel
      include Writexlsx::Utility

      attr_writer :value_count

      def initialize
        @writer = Package::XMLWriterSimple.new
        @value_count = 0
      end

      def set_xml_writer(filename)
        @writer.set_xml_writer(filename)
      end

      def assemble_xml_file
        write_xml_declaration do
          write_rich_value_rels
        end
      end

      private

      #
      # Write the <richValueRels> element.
      #
      def write_rich_value_rels
        xmlns = 'http://schemas.microsoft.com/office/spreadsheetml/2022/richvaluerel'
        xmlns_r = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'

        attributes = [
          ['xmlns',   xmlns],
          ['xmlns:r', xmlns_r]
        ]

        @writer.tag_elements('richValueRels', attributes) do
          (0..(@value_count - 1)).each do |index|
            # Write the rel element.
            write_rel(index + 1)
          end
        end
      end

      #
      # Write the <rel> element.
      #
      def write_rel(id)
        attributes = [['r:id',  "rId#{id}"]]

        @writer.empty_tag('rel', attributes)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
write_xlsx-1.12.1 lib/write_xlsx/package/rich_value_rel.rb
write_xlsx-1.12.0 lib/write_xlsx/package/rich_value_rel.rb