rust_xlsxwriter

repository·main·Indexed 20 days ago

https://github.com/jmcnamara/rust_xlsxwriter

A high-performance Rust library for writing Excel 2007 (.xlsx) files, rewritten from the Python XlsxWriter library. It supports a wide range of features including complex chart types (Area, Bar, Column, Line, Pie, etc.), conditional formatting (color scales, data bars, icon sets), embedded images, VBA macro integration, and custom workbook themes. The library provides options for constant and low memory modes and supports the IntoExcelData trait for writing generic data types.

Tokens
11.2K
Snippets
12
Records
61
Agent score
69%

What's inside rust_xlsxwriter

  1. Overview of available chart types

    main

    The rust_xlsxwriter library supports a wide variety of Excel charts, including:

    • Standard Charts: Area, Bar, Column, Line, Pie, Doughnut, Radar, Scatter, and Stock charts.
    • Specialized Charts: Clustered category charts, Combined charts, Gauge charts (constructed via doughnut and pie charts), Pareto charts, and Sparklines (mini-charts that fit in a single cell).
    • Advanced Chart Features: Charts with secondary axes, charts with data tables, charts with gradient fills, and charts with fill patterns.
    • Chartsheets: Creating dedicated chartsheets.
  2. Insert and configure images

    main

    Images can be inserted into worksheets with various configurations:

    • Creation: Create image objects from buffers (u8 buffer) or standard file paths.
    • Sizing: Scale images by width/height, scale to a fixed size, or use worksheet.insert_image_fit_to_cell() to fit an image to a cell.
    • Accessibility: Set alternative text (alt_text) or mark an image as decorative to improve accessibility for screen readers.
    • Behavior: Configure how the image behaves (object movement) when cells underneath it are changed.
  3. Manage workbook properties and macros

    main

    Advanced workbook management includes:

    • Document Properties: Set custom/user-defined workbook properties. You can also control the creation date to ensure consistent file checksums.
    • VBA Macros: Add VBA projects to .xlsm files (e.g., adding, calculating, naming, saving, or signed macros).
  4. Add and customize notes to cells

    main

    Notes (formerly comments) can be added to cells with the following capabilities:

    • Basic Usage: Create and add a new note to a cell.
    • Customization: Set the author's name, change the background color, and adjust the note's dimensions (width/height).
    • Visibility: Control whether the note is visible by default.
    • Reuse: Reset the text of an existing Note object to reuse it for different cells.
  5. Write and format datetimes in Excel

    main

    The library provides several ways to write formatted dates and times into a worksheet:

    • Standard Datetimes/HMS: Write formatted datetimes or times (including milliseconds).
    • From Components: Create datetimes from Year-Month-Day (YMD) or from Hours-Minutes-Seconds (HMS).
    • From External Sources: Write datetimes parsed from strings, from Unix timestamps, or from Excel serial datetime values.
    • Excel Conversion: Use the ExcelDateTime::to_excel() method to convert datetime objects into the format Excel expects.
  6. Configure chart elements and formatting

    main

    The library provides extensive control over chart aesthetics and components:

    • Chart Components: Add data tables, drop lines, high-low lines, and up-down bars.
    • Series & Points: Set individual segment colors for Pie charts, adjust chart rotation for pie/doughnut charts, and set the hole size for doughnut charts.
    • Visual Areas: Format the chart plot area (the area between axes) and apply solid fills or specific colors to chart elements.
    • Titles: Set chart titles and customize their font properties.
    • Trendlines: Add trendlines to data series, set their type (e.g., polynomial), customize their names, and format their data labels. You can also hide trendline names from the legend.
  7. Add shapes and textboxes to worksheets

    main

    You can add shapes, such as textboxes, and customize their appearance:

    • Font Styling: Set font properties (bold, italic, name, size, color) specifically for text within a shape.
    • Shape Styling: Customize the shape's appearance, including line properties and gradient fills.
  8. Configure Data Validation for worksheet cells

    main

    You can restrict user input in worksheet cells using data validation. Supported validation types include:

    • Decimal Numbers: Restrict to floating point values, either in a fixed range or based on a formula from another cell.
    • Whole Numbers: Restrict to integers, either in a fixed range or based on a formula.
    • Lists: Restrict input to a selection of values from a dropdown list. The list can be provided as a set of strings or a cell range.
    • Text Length: Restrict input to strings within a specific character length range.
    • Time: Restrict input to time values within a fixed range.

    Additionally, you can enhance validation by:

    • Setting an input message to explain required input to the user.
    • Setting a custom error title and error message to display when invalid data is entered.
  9. Configure Chart Axes

    main

    The library provides extensive control over chart axes, including:

    • Bounds: Setting max/min values or date axis ranges (doc_chart_axis_set_max, doc_chart_axis_set_max_date).
    • Formatting: Setting number formats, font names, and font sizes (doc_chart_axis_set_num_format, doc_chart_axis_set_name_font).
    • Gridlines: Turning major/minor gridlines on/off or formatting their lines (doc_chart_axis_set_major_gridlines, doc_chart_axis_set_minor_gridlines_line).
    • Ticks: Setting tick intervals and major/minor tick types (doc_chart_axis_set_tick_interval, doc_chart_axis_set_major_tick_type).
    • Display: Hiding axes, setting label positions, or reversing the plotting direction (doc_chart_axis_set_hidden, doc_chart_axis_set_label_position, doc_chart_axis_set_reverse).
    • Specialized Axes: Setting date axes or logarithmic bases (doc_chart_axis_set_date_axis, doc_chart_axis_set_log_base).
  10. Format Chart Series and Data Labels

    main

    You can customize how data is presented in a chart series:

    • Data Labels: Add labels with specific fonts, number formats, or positions, and show category names or percentages (doc_chart_data_labels, doc_chart_data_labels_set_num_format, doc_chart_data_labels_show_percentage).
    • Series Appearance: Set the series name, invert colors if negative, or set a secondary axis (doc_chart_series_set_name, doc_chart_series_set_invert_if_negative, doc_chart_series_set_secondary_axis).
    • Error Bars: Add error bars to a data series (doc_chart_error_bars_intro).
  11. Customize Chart Visual Styles

    main

    The library allows deep customization of chart elements using various formatting options:

    • Fonts: Set bold, italic, color, name, size, and rotation for any chart element (doc_chart_font, doc_chart_font_set_bold, doc_chart_font_set_rotation).
    • Fills: Apply solid, gradient, or pattern fills, and manage transparency (doc_chart_gradient_fill, doc_chart_pattern_fill, doc_chart_line_set_transparency).
    • Lines/Borders: Format line width, dash type, and color, or remove borders/lines entirely (doc_chart_line_set_width, doc_chart_line_set_dash_type, doc_chart_format_set_no_border).
    • Markers: Add and customize markers (type and size) for line charts (doc_chart_marker, doc_chart_marker_set_type).