xlsxrb 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +88 -0
  3. data/README.md +25 -3
  4. data/lib/xlsxrb/dsl_helpers.rb +65 -1
  5. data/lib/xlsxrb/elements/styles.rb +15 -6
  6. data/lib/xlsxrb/elements/worksheet.rb +2 -2
  7. data/lib/xlsxrb/number_formatter.rb +26 -8
  8. data/lib/xlsxrb/ooxml/cfb.rb +11 -3
  9. data/lib/xlsxrb/ooxml/crypto/agile.rb +48 -10
  10. data/lib/xlsxrb/ooxml/crypto/standard.rb +5 -1
  11. data/lib/xlsxrb/ooxml/crypto.rb +3 -0
  12. data/lib/xlsxrb/ooxml/shared_strings_parser.rb +26 -8
  13. data/lib/xlsxrb/ooxml/utils.rb +13 -0
  14. data/lib/xlsxrb/ooxml/workbook_writer.rb +43 -21
  15. data/lib/xlsxrb/ooxml/worksheet_parser.rb +116 -12
  16. data/lib/xlsxrb/ooxml/worksheet_writer.rb +338 -259
  17. data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +206 -201
  18. data/lib/xlsxrb/ooxml/writer/features_xml.rb +109 -102
  19. data/lib/xlsxrb/ooxml/writer/styles_xml.rb +46 -46
  20. data/lib/xlsxrb/ooxml/writer.rb +167 -160
  21. data/lib/xlsxrb/ooxml/xml_builder.rb +35 -7
  22. data/lib/xlsxrb/ooxml/xml_parser.rb +34 -1
  23. data/lib/xlsxrb/ooxml/zip_reader.rb +95 -68
  24. data/lib/xlsxrb/ooxml/zip_writer.rb +16 -0
  25. data/lib/xlsxrb/stream_row.rb +2 -2
  26. data/lib/xlsxrb/stream_sheet.rb +26 -11
  27. data/lib/xlsxrb/stream_writer.rb +212 -86
  28. data/lib/xlsxrb/style_builder.rb +339 -0
  29. data/lib/xlsxrb/version.rb +1 -1
  30. data/lib/xlsxrb/workbook_builder.rb +239 -88
  31. data/lib/xlsxrb/worksheet_builder.rb +847 -139
  32. data/lib/xlsxrb.rb +87 -21
  33. data/sig/generated/xlsxrb/dsl_helpers.rbs +37 -0
  34. data/sig/generated/xlsxrb/elements/styles.rbs +5 -0
  35. data/sig/generated/xlsxrb/number_formatter.rbs +7 -0
  36. data/sig/generated/xlsxrb/ooxml/cfb.rbs +2 -0
  37. data/sig/generated/xlsxrb/ooxml/crypto/agile.rbs +10 -0
  38. data/sig/generated/xlsxrb/ooxml/shared_strings_parser.rbs +7 -0
  39. data/sig/generated/xlsxrb/ooxml/utils.rbs +10 -0
  40. data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +13 -0
  41. data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +40 -0
  42. data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +53 -0
  43. data/sig/generated/xlsxrb/ooxml/writer/features_xml.rbs +3 -0
  44. data/sig/generated/xlsxrb/ooxml/writer.rbs +4 -0
  45. data/sig/generated/xlsxrb/ooxml/xml_builder.rbs +19 -2
  46. data/sig/generated/xlsxrb/ooxml/xml_parser.rbs +10 -0
  47. data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +12 -1
  48. data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +8 -0
  49. data/sig/generated/xlsxrb/stream_row.rbs +2 -2
  50. data/sig/generated/xlsxrb/stream_sheet.rbs +9 -0
  51. data/sig/generated/xlsxrb/stream_writer.rbs +46 -6
  52. data/sig/generated/xlsxrb/style_builder.rbs +261 -0
  53. data/sig/generated/xlsxrb/workbook_builder.rbs +42 -9
  54. data/sig/generated/xlsxrb/worksheet_builder.rbs +618 -4
  55. data/sig/generated/xlsxrb.rbs +53 -8
  56. metadata +9 -3
@@ -27,6 +27,17 @@ module Xlsxrb
27
27
  class Error < StandardError
28
28
  end
29
29
 
30
+ # @api private
31
+ module Deprecation
32
+ LIB_DIR: untyped
33
+
34
+ # Warns that a feature is deprecated, at the location +uplevel+ frames above the caller,
35
+ # or, with +uplevel: nil+, at the first caller outside this library, for methods that
36
+ # are reached both directly and through another xlsxrb method.
37
+ # : (String message, ?uplevel: Integer?) -> void
38
+ def self.warn: (String message, ?uplevel: Integer?) -> void
39
+ end
40
+
30
41
  # Raised when parsing malformed or invalid XML structures.
31
42
  class ParseError < Error
32
43
  end
@@ -408,6 +419,26 @@ module Xlsxrb
408
419
  # : (untyped name, ?replace_char: String) -> String
409
420
  def self.sanitize_sheet_name: (untyped name, ?replace_char: String) -> String
410
421
 
422
+ # Cuts text to what a cell holds: 32,767 characters counted in UTF-16 code units, as
423
+ # Excel counts them, so a character outside the Basic Multilingual Plane, such as an emoji,
424
+ # counts as two. A character is never split. Writing longer text raises ArgumentError
425
+ # with +strict_excel_mode+ (the default); call this first to keep the start of the text
426
+ # instead.
427
+ #
428
+ # Text of 32,767 bytes or fewer always fits, so it is returned as is after its byte size
429
+ # is checked, without counting its characters. Longer text is returned as a new UTF-8
430
+ # String, even if it fits.
431
+ #
432
+ # @example
433
+ # Xlsxrb.truncate_cell_text("x" * 40_000).length #=> 32767
434
+ # Xlsxrb.truncate_cell_text("😀" * 20_000).length #=> 16383
435
+ #
436
+ # @param text [String]
437
+ # @return [String]
438
+ # @api public
439
+ # : (String text) -> String
440
+ def self.truncate_cell_text: (String text) -> String
441
+
411
442
  # Reads an XLSX file (streaming and lazy-loaded by default) from a file path, IO stream, or binary String.
412
443
  #
413
444
  # Sheets and rows are streamed lazily with O(1) constant memory. If a block is given,
@@ -462,30 +493,36 @@ module Xlsxrb
462
493
 
463
494
  # Writes an XLSX file or IO stream (streaming or in-memory), or returns a binary string.
464
495
  #
465
- # @overload write(?target, password: nil, encryption_mode: :standard, strict_excel_mode: true, &block)
496
+ # @overload write(?target, password: nil, encryption_mode: nil, strict_excel_mode: true, &block)
466
497
  # Streaming write: yields a {StreamWriter} context for high-speed, zero-allocation XLSX generation.
467
498
  # If target is omitted, returns the generated XLSX as an in-memory binary String.
468
499
  # @param target [String, IO, StringIO, nil] Optional destination file path or writable IO object.
469
500
  # @param password [String, nil] Optional password to encrypt the generated XLSX file.
470
- # @param encryption_mode [Symbol] Encryption algorithm (:standard or :agile).
501
+ # @param encryption_mode [Symbol, nil] Encryption scheme used with a password: `:agile` (AES-256, with a check
502
+ # that the file is unchanged) or `:standard` (AES-128; deprecated, and an error from 0.3.0). When omitted,
503
+ # Standard is written in 0.2 and Agile from 0.3.0. See docs/adr/0013-write-agile-encryption-read-both.md.
471
504
  # @param strict_excel_mode [Boolean] Whether to enforce Microsoft Excel specification limits.
472
505
  # @yield [stream_writer]
473
506
  # @yieldparam stream_writer [Xlsxrb::StreamWriter]
474
507
  # @return [String, void] Binary data if target is omitted, or void if written to target.
475
508
  #
476
- # @overload write(workbook, password: nil, encryption_mode: :standard)
509
+ # @overload write(workbook, password: nil, encryption_mode: nil)
477
510
  # In-memory write: exports the workbook to an in-memory binary String.
478
511
  # @param workbook [Elements::Workbook] The workbook to write.
479
512
  # @param password [String, nil] Optional password to encrypt the binary string.
480
- # @param encryption_mode [Symbol] Encryption algorithm (:standard or :agile).
513
+ # @param encryption_mode [Symbol, nil] Encryption scheme used with a password: `:agile` (AES-256, with a check
514
+ # that the file is unchanged) or `:standard` (AES-128; deprecated, and an error from 0.3.0). When omitted,
515
+ # Standard is written in 0.2 and Agile from 0.3.0. See docs/adr/0013-write-agile-encryption-read-both.md.
481
516
  # @return [String] Binary data representing the XLSX file.
482
517
  #
483
- # @overload write(target, workbook, password: nil, encryption_mode: :standard)
518
+ # @overload write(target, workbook, password: nil, encryption_mode: nil)
484
519
  # In-memory write: writes the workbook to a file path or IO stream.
485
520
  # @param target [String, IO, StringIO] Destination file path or writable IO object.
486
521
  # @param workbook [Elements::Workbook] The workbook to write.
487
522
  # @param password [String, nil] Optional password to encrypt the output file.
488
- # @param encryption_mode [Symbol] Encryption algorithm (:standard or :agile).
523
+ # @param encryption_mode [Symbol, nil] Encryption scheme used with a password: `:agile` (AES-256, with a check
524
+ # that the file is unchanged) or `:standard` (AES-128; deprecated, and an error from 0.3.0). When omitted,
525
+ # Standard is written in 0.2 and Agile from 0.3.0. See docs/adr/0013-write-agile-encryption-read-both.md.
489
526
  # @return [void]
490
527
  #
491
528
  # @example Streaming write to file
@@ -514,8 +551,8 @@ module Xlsxrb
514
551
  # @param compression_level [Integer, nil] ZIP deflate compression level (0..9, or Zlib::DEFAULT_COMPRESSION
515
552
  # for zlib's level 6). Defaults to {DEFAULT_COMPRESSION_LEVEL}. Higher levels write smaller files more slowly;
516
553
  # level 0 stores entries without compression. See docs/adr/0009-default-zip-compression-level.md.
517
- # : (?untyped target_or_workbook, ?Elements::Workbook | untyped workbook_or_nil, ?password: String?, ?encryption_mode: Symbol, ?strict_excel_mode: bool, ?default_font: untyped?, ?shared_strings: bool, ?compression_level: Integer | nil) ?{ (StreamWriter) -> void } -> untyped
518
- def self.write: (?untyped target_or_workbook, ?Elements::Workbook | untyped workbook_or_nil, ?password: String?, ?encryption_mode: Symbol, ?strict_excel_mode: bool, ?default_font: untyped?, ?shared_strings: bool, ?compression_level: Integer | nil) ?{ (StreamWriter) -> void } -> untyped
554
+ # : (?untyped target_or_workbook, ?Elements::Workbook | untyped workbook_or_nil, ?password: String?, ?encryption_mode: Symbol?, ?strict_excel_mode: bool, ?default_font: untyped?, ?shared_strings: bool, ?compression_level: Integer | nil) ?{ (StreamWriter) -> void } -> untyped
555
+ def self.write: (?untyped target_or_workbook, ?Elements::Workbook | untyped workbook_or_nil, ?password: String?, ?encryption_mode: Symbol?, ?strict_excel_mode: bool, ?default_font: untyped?, ?shared_strings: bool, ?compression_level: Integer | nil) ?{ (StreamWriter) -> void } -> untyped
519
556
 
520
557
  # Builds an in-memory {Elements::Workbook} using a declarative DSL.
521
558
  #
@@ -527,6 +564,10 @@ module Xlsxrb
527
564
  # end
528
565
  # end
529
566
  #
567
+ # @note Planned for version 0.3.0: Cell#format_code of the built cells will be the
568
+ # number format of each cell's resolved style, as in a loaded workbook; cells styled
569
+ # :default or :none will have style index 0; and a style index given in cell_styles
570
+ # will be kept only in Cell#style_index.
530
571
  # @param strict_excel_mode [Boolean] Whether to enforce Microsoft Excel specification limits.
531
572
  # @param default_font [Hash, nil] Optional default font options.
532
573
  # @yield [builder]
@@ -607,6 +648,10 @@ module Xlsxrb
607
648
  # : (untyped raw_row, ?Hash[String, untyped] hyperlinks, ?(Array[untyped] | Hash[String, untyped]) comments, ?Hash[untyped, untyped]? styles, ?date1904: bool, ?threaded_comments: (Array[untyped] | Hash[String, untyped])) -> (Elements::Row | untyped)
608
649
  private def self.build_row_from_raw: (untyped raw_row, ?Hash[String, untyped] hyperlinks, ?Array[untyped] | Hash[String, untyped] comments, ?Hash[untyped, untyped]? styles, ?date1904: bool, ?threaded_comments: Array[untyped] | Hash[String, untyped]) -> (Elements::Row | untyped)
609
650
 
651
+ # The scheme to encrypt with. Standard stays the default in 0.2; asking for it by name warns.
652
+ # : (Symbol? encryption_mode) -> Symbol
653
+ private def self.write_encryption_mode: (Symbol? encryption_mode) -> Symbol
654
+
610
655
  # : (untyped source, String? password) -> untyped
611
656
  private def self.prepare_source_io: (untyped source, String? password) -> untyped
612
657
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xlsxrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - niku
@@ -29,14 +29,20 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '3.0'
32
+ version: '3.4'
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 3.4.2
33
36
  type: :runtime
34
37
  prerelease: false
35
38
  version_requirements: !ruby/object:Gem::Requirement
36
39
  requirements:
37
40
  - - "~>"
38
41
  - !ruby/object:Gem::Version
39
- version: '3.0'
42
+ version: '3.4'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 3.4.2
40
46
  description: A streaming-capable, low-memory XLSX reading and writing library for
41
47
  Ruby, relying solely on standard libraries and bundled gems.
42
48
  email: