Caxlsx:一个用于生成包含图表、图像和模式验证的xlsx文件的Ruby gem。
Caxlsx: Ruby gem for xlsx generation with charts, images, schema validation

原始链接: https://github.com/caxlsx/caxlsx

## Caxlsx:Ruby Excel 电子表格生成 Caxlsx(前身为 Axlsx)是一个 Ruby gem,用于生成 Excel (.xlsx) 电子表格。它允许开发者创建包含图表、图像、公式、自定义样式等复杂文档,而无需深入了解 Office Open XML 规范。 主要特性包括自动数据类型检测、灵活的列宽控制、对各种图表类型(3D 饼图、折线图、柱状图等)的支持,以及对单元格、行和整个工作簿的强大样式选项。Caxlsx 优先保证文档有效性,并与 Google Docs、LibreOffice 和 Numbers 等软件具有互操作性(存在一些限制)。 **重要更新:** 该项目已被分叉,现在由社区组织 **Caxlsx** ([https://github.com/caxlsx](https://github.com/caxlsx)) 维护。相关的 gem 也已迁移到那里。鼓励用户加入 Caxlsx Slack 频道以获取支持。 详细文档和示例可在网上和 gem 本身内找到。安全性通过默认公式转义来解决,可以根据需要进行配置。

## Caxlsx:一个 Ruby XLSX 生成的 Gem 一个新的 Ruby gem,**Caxlsx**,用于生成 Excel (.xlsx) 文件,具有图表、图像和模式验证等功能,已经在 Hacker News 上分享。它似乎是之前维护的 **axlsx** gem 的社区驱动的延续。 贡献者们怀念最初的 axlsx 项目及其维护者,称赞其对新开源贡献者的友好环境。讨论强调了过去在诸如条件格式和特定区域数字格式等功能上的贡献。 目前至少有一个开发者正在生产环境中使用 Caxlsx,它提供了强大的格式化能力。一个相关的资源,一个 Excel 的 Vim 插件也被分享,吸引了同时喜欢这两种工具的用户。该 gem 的 GitHub 仓库地址是 [https://github.com/caxlsx](https://github.com/caxlsx)。
相关文章

原文

Test RuboCop Gem Version downloads

Notice: Community Axlsx Organization

To better maintain the Axlsx ecosystem, all related gems have been forked or moved to the following community organization:

https://github.com/caxlsx

Join the Caxlsx Slack channel

Axlsx is an Office Open XML Spreadsheet generator for the Ruby programming language. With Axlsx you can create Excel worksheets with charts, images (with links), automated and fixed column widths, customized styles, functions, tables, conditional formatting, print options, comments, merged cells, auto filters, file and stream serialization as well as full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification.

Screen 1

  1. Author xlsx documents: Caxlsx is made to let you easily and quickly generate professional xlsx based reports that can be validated before serialization.

  2. Generate 3D Pie, Line, Scatter and Bar Charts: With Caxlsx chart generation and management is as easy as a few lines of code. You can build charts based off data in your worksheet or generate charts without any data in your sheet at all. Customize gridlines, label rotation and series colors as well.

  3. Custom Styles: With guaranteed document validity, you can style borders, alignment, fills, fonts, and number formats in a single line of code. Those styles can be applied to an entire row, or a single cell anywhere in your workbook.

  4. Automatic type support: Caxlsx will automatically determine the type of data you are generating. In this release Float, Integer, String, Date, Time and Boolean types are automatically identified and serialized to your spreadsheet.

  5. Automatic and fixed column widths: Caxlsx will automatically determine the appropriate width for your columns based on the content in the worksheet, or use any value you specify for the really funky stuff.

  6. Support for automatically formatted 1904 and 1900 epochs configurable in the workbook.

  7. Add jpg, gif and png images to worksheets with hyperlinks

  8. Reference cells in your worksheet with "A1" and "A1:D4" style references or from the workbook using "Sheet1!A3:B4" style references

  9. Cell level style overrides for default and customized style objects

  10. Support for formulas, merging, row and column outlining as well as cell level input data validation.

  11. Auto filtering tables with worksheet.auto_filter as well as support for Tables

  12. Export using shared strings or inline strings so we can inter-op with iWork Numbers (sans charts for now).

  13. Output to file or StringIO

  14. Support for page margins and print options

  15. Support for workbook-level encryption and password protection (requires ooxml_crypt gem which only supports MRI Ruby.)

  16. Support for sheet-level password and non-password protection.

  17. First stage interoperability support for GoogleDocs, LibreOffice, and Numbers.

  18. Support for defined names, which gives you repeated header rows for printing.

  19. Data labels for charts as well as series color customization.

  20. Support for sheet headers and footers

  21. Pivot Tables

  22. Page Breaks

Supported Ruby versions: Caxlsx supports Ruby 2.6 and newer.

Here's a teaser that kicks about 2% of what the gem can do.

Axlsx::Package.new do |p|
  p.workbook.add_worksheet(:name => "Pie Chart") do |sheet|
    sheet.add_row ["Simple Pie Chart"]
    %w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
    sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,5], :end_at => [10, 20], :title => "example 3: Pie Chart") do |chart|
      chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"],  :colors => ['FF0000', '00FF00', '0000FF']
    end
  end
  p.serialize('simple.xlsx')
end

Please see the examples folder for further information on what you can do with this gem Chances are that it has already been implemented. If it hasn't, let's take a look at adding it in.

Detailed documentation is available at:

https://www.rubydoc.info/gems/caxlsx/

Additional documentation is listed below:

You can run the documentation on your local by running the following:

gem install webrick
yard server

⚠ Please do not create issues for questions regarding the usage of axlsx / caxlsx. Look through this README, the examples folder, and the FAQ, and also check questions tagged axlsx on Stack Overflow.

Feel free to add your question (including an answer!) to the FAQ if you think it is of general interest.

Plugins, Integrations, and Extensions

Currently the following additional gems are available:

  • acts_as_caxlsx
    • Provides simple ActiveRecord integration
  • caxlsx_rails
    • Provides a .axlsx renderer to Rails so you can move all your spreadsheet code from your controller into view files.
  • activeadmin-caxlsx
    • An Active Admin plugin that includes DSL to create downloadable reports.
  • ooxml_crypt
    • Required to enable workbook encryption and password protection.

To prevent Formula Injection vulnerabilities, as of version 4.0, axlsx escapes all formulas by default. To permit formulas on a specific cell, please use:

cell.escape_formulas = false

You may set escape_formulas on the workbook, worksheet, row and/or cell level. Refer to examples/escape_formula.md for details.

To allow formulas globally by default (which was the behavior in axlsx 3.x and prior), you may set the following in an initializer:

Axlsx.escape_formulas = false

Known Software Interoperability Issues

As axslx implements the Office Open XML (ECMA-376 spec) much of the functionality is interoperable with other spreadsheet software. Below is a listing of some known issues.

  1. Libre Office

    • You must specify colors for your series. see examples/chart_colors.rb for an example.
    • You must use data in your sheet for charts. You cannot use hard coded values.
    • Chart axis and gridlines do not render. I have a feeling this is related to themes, which axlsx does not implement at this time.
  2. Google Docs

    • Images are known to not work with google docs
    • border colors do not work
  3. Apple Numbers

    • charts do not render
    • you must set 'use_shared_strings' to true. This is most conveniently done just before rendering by calling Package.use_shared_strings = true prior to serialization.
p = Axlsx::Package.new
p.workbook.add_worksheet(:name => "Basic Worksheet") do |sheet|
  sheet.add_row ["First Column", "Second", "Third"]
  sheet.add_row [1, 2, 3]
end
p.use_shared_strings = true
p.serialize('simple.xlsx')

See CONTRIBUTING.md

Originally created by Randy Morgan - @randym

Forked in 2019, to enable the community to maintain the Axlsx ecosystem - https://github.com/caxlsx

Open source software is a community effort. None of this could have been done without the help of our Contributors.

联系我们 contact @ memedata.com