Class: Declaration232::XlsmWriter
- Inherits:
-
BaseService
- Object
- BaseService
- Declaration232::XlsmWriter
- Defined in:
- app/services/declaration232/xlsm_writer.rb
Overview
Fills the broker's macro-enabled 232 declaration template with a delivery's
line rows and returns the resulting .xlsm as a binary string.
The template (see TEMPLATE_PATH) carries a VBA project,
category dropdowns, and seven reference sheets the broker expects intact, so
this writer never round-trips the workbook through a spreadsheet library —
it copies every zip entry byte-for-byte and rewrites only the declaration
worksheet's XML: the prepared-by block (H7:H10), the shipment reference
(C12), and the data rows (14+, replaced wholesale with generated row pairs
plus empty styled rows through row 106, the extent of the template's
dropdown validations).
Constant Summary collapse
- SHEET_ENTRY =
Worksheet part for the "232 Declaration" sheet inside the template.
'xl/worksheets/sheet2.xml'- FIRST_DATA_ROW =
First data row / last row covered by the template's dropdown validations.
14- LAST_ROW =
106- DATA_ROW_ATTRS =
Style ids lifted from the template's own row 14 (data) and row 28 (empty).
'spans="1:12" s="21" customFormat="1" x14ac:dyDescent="0.25"'- DATA_STYLES =
{ 'A' => 95, 'B' => 89, 'C' => 96, 'D' => 96, 'E' => 96, 'F' => 96, 'G' => 97, 'H' => 96, 'I' => 96, 'J' => 96, 'K' => 96, 'L' => 90 }.freeze
- EMPTY_ROW_ATTRS =
'spans="1:12" s="24" customFormat="1" ht="24.95" customHeight="1" x14ac:dyDescent="0.25"'- EMPTY_STYLES =
{ 'A' => 25, 'B' => 88, 'C' => 54, 'D' => 22, 'E' => 22, 'F' => 22, 'G' => 31, 'H' => 22, 'I' => 22, 'J' => 22, 'K' => 22, 'L' => 23 }.freeze
- PREPARER_CELLS =
Prepared-by cells and the template style each carries.
{ 'H7' => 35, 'H8' => 98, 'H9' => 35, 'H10' => 100 }.freeze
Instance Attribute Summary
Attributes inherited from BaseService
Instance Method Summary collapse
-
#call ⇒ String
The filled .xlsm, binary.
-
#initialize(delivery) ⇒ XlsmWriter
constructor
A new instance of XlsmWriter.
Methods inherited from BaseService
#log_debug, #log_error, #log_info, #log_warning, #logger, #process, #tagged_logger
Constructor Details
#initialize(delivery) ⇒ XlsmWriter
Returns a new instance of XlsmWriter.
31 32 33 |
# File 'app/services/declaration232/xlsm_writer.rb', line 31 def initialize(delivery) @delivery = delivery end |
Instance Method Details
#call ⇒ String
Returns the filled .xlsm, binary.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/services/declaration232/xlsm_writer.rb', line 36 def call require 'zip' buffer = Zip::OutputStream.write_buffer do |out| Zip::File.open(Declaration232::TEMPLATE_PATH) do |zip| zip.entries.each do |entry| out.put_next_entry(entry.name) data = entry.get_input_stream.read data = fill_sheet(data) if entry.name == SHEET_ENTRY out.write(data) end end end buffer.string end |