Skip to content

Commit

Permalink
release: 0.80.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcnamara committed Dec 7, 2024
1 parent 22e43d4 commit 5730012
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 31 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,31 @@ This is the changelog/release notes for the `rust_xlsxwriter` crate.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.80.0] - 2024-12-07

### Fixed

- Fixed issue where unnecessary heap memory was being used to zip worksheets in
`constant_memory` mode. This version is a recommended upgrade for anyone using
that mode/feature.

[Issue #120]

[Issue #120]: https://github.com/jmcnamara/rust_xlsxwriter/issues/120

### Added

- Added the [`utility::cell_autofit_width()`] function to allow users to
calculate a string auto-fit width so that they can implement their own
auto-fit functionality with additional logic.

[`utility::cell_autofit_width()`]:
https://docs.rs/rust_xlsxwriter/latest/rust_xlsxwriter/utility/fn.cell_autofit_width.html

- Updated polars dependency to 0.44 to pick up latest Polars additions for
[`polars_excel_writer`].


## [0.79.4] - 2024-11-18

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repository = "https://github.com/jmcnamara/rust_xlsxwriter"
keywords = ["excel", "xlsx"]
readme = "README.md"
license = "MIT OR Apache-2.0"
version = "0.79.4"
version = "0.80.0"
edition = "2021"
rust-version = "1.73.0" # For zip.rs compatibility.

Expand Down
4 changes: 4 additions & 0 deletions examples/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,10 @@ documentation and generally show how an individual function works.
* `doc_worksheet_set_cell_format.rs` - Demonstrates setting the format of a
worksheet cell separately from writing the cell data.

* `doc_worksheet_set_column_autofir_width.rs` - Demonstrates "auto"-fitting
the the width of a column in Excel based on the maximum string width. See
also the [`Worksheet::autofit()`] command.

* `doc_worksheet_set_column_format.rs` - Demonstrates setting the format
for a column in Excel.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! The following example demonstrates "auto"-fitting the the width of a column
//! in Excel based on the maximum string width. See also the
//! [`Worksheet::autofit()`] command.
use rust_xlsxwriter::{autofit_cell_width, Workbook, XlsxError};
use rust_xlsxwriter::{cell_autofit_width, Workbook, XlsxError};

fn main() -> Result<(), XlsxError> {
let mut workbook = Workbook::new();
Expand All @@ -20,10 +20,10 @@ fn main() -> Result<(), XlsxError> {
worksheet.write_column(0, 0, cities)?;

// Find the maximum column width in pixels.
let max_width = cities.iter().map(|s| autofit_cell_width(s)).max().unwrap();
let max_width = cities.iter().map(|s| cell_autofit_width(s)).max().unwrap();

// Set the column width as if it was auto-fitted.
worksheet.set_column_auto_width(0, max_width)?;
worksheet.set_column_autofit_width(0, max_width)?;

workbook.save("worksheet.xlsx")?;

Expand Down
20 changes: 7 additions & 13 deletions src/tutorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ A getting started tutorial for `rust_xlsxwriter`.
- [Modify main.rs](#modify-mainrs)
- [Run the application](#run-the-application)
- [Tutorial](#tutorial)
- [Reading ahead](#reading-ahead)
- [Tutorial Part 1: Adding data to a worksheet](#tutorial-part-1-adding-data-to-a-worksheet)
- [Tutorial Part 2: Adding some formatting](#tutorial-part-2-adding-some-formatting)
- [Tutorial Part 3: Adding dates and more formatting](#tutorial-part-3-adding-dates-and-more-formatting)
Expand Down Expand Up @@ -120,16 +119,11 @@ To look at some of the basic but more useful features of the
`rust_xlsxwriter` library we will create an application to summarize some
monthly expenses into a spreadsheet.
## Reading ahead
The tutorial presents a simple direct approach so as not to confuse the reader
with information that isn't required for an initial understanding. If there is
The tutorial presents a direct approach so as not to confuse the reader
with information that isn't initially relevant. If there is
more advanced information that might be interesting at a later stage it will be
highlighted in a "Reading ahead" section like this:
highlighted as "Extra information".
> **Reading ahead**:
>
> Some more advanced information.
## Tutorial Part 1: Adding data to a worksheet
Expand Down Expand Up @@ -218,7 +212,7 @@ location in the worksheet:
}
```
> **Reading ahead**:
> **Extra information**:
>
> There are other type specific write methods such as
> [`Worksheet::write_string()`](crate::Worksheet::write_string) and
Expand Down Expand Up @@ -255,7 +249,7 @@ spreadsheet shown in the image above.:
workbook.save("tutorial1.xlsx")?;
```
> **Reading ahead**:
> **Extra information**:
>
> The [`Workbook::save()`](crate::Workbook::save) method takes a [`std::path`]
> argument which can be a `Path`, `PathBuf` or a filename string. It is also
Expand Down Expand Up @@ -444,7 +438,7 @@ to display them in the desired way. To handle dates and times with
`rust_xlsxwriter` we create them using a [`ExcelDateTime`](crate::ExcelDateTime)
instance and format them with an Excel number format.
> **Reading ahead**:
> **Extra information**:
> If you enable the `chrono` feature in `rust_xlsxwriter` you can also use
> [`chrono::NaiveDateTime`], [`chrono::NaiveDate`] or [`chrono::NaiveTime`]
Expand Down Expand Up @@ -626,7 +620,7 @@ numbers and converts them to a string range like `B2:B5`:
```
> **Reading ahead**:
> **Extra information**:
>
> The `cell_range()` function and other similar functions are detailed in the
> [`utility`](crate::utility) documentation.
Expand Down
18 changes: 9 additions & 9 deletions src/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,13 +776,13 @@ pub(crate) fn validate_vba_name(name: &str) -> Result<(), XlsxError> {
/// you may wish to handle auto-fitting yourself and apply additional logic to
/// limit the maximum and minimum ranges.
///
/// The `autofit_cell_width()` function can be used to perform the required
/// The `cell_autofit_width()` function can be used to perform the required
/// calculation. It works by estimating the pixel width of a string based on the
/// width of each character. It also adds a 7 pixel padding for the cell
/// boundary in the same way that Excel does.
///
/// You can use the calculated width in conjunction with the
/// [`Worksheet::set_column_auto_width()`](crate::Worksheet::set_column_auto_width)
/// [`Worksheet::set_column_autofit_width()`](crate::Worksheet::set_column_autofit_width)
/// method, see the example below.
///
/// Notes:
Expand All @@ -794,7 +794,7 @@ pub(crate) fn validate_vba_name(name: &str) -> Result<(), XlsxError> {
/// - If you are autofitting a header with an autofilter dropdown you should add
/// an additional 6 pixels to account for the dropdown symbol.
///
/// - When dealing with large data sets you can use `autofit_cell_width()` with
/// - When dealing with large data sets you can use `cell_autofit_width()` with
/// just 50 or 100 rows of data as a performance optimization . This will
/// produce a reasonably accurate autofit for the first visible page of data
/// without incurring the performance penalty of calculating widths for
Expand All @@ -811,9 +811,9 @@ pub(crate) fn validate_vba_name(name: &str) -> Result<(), XlsxError> {
/// [`Worksheet::autofit()`](crate::Worksheet::autofit) command.
///
/// ```
/// # // This code is available in examples/doc_worksheet_set_column_auto_width.rs
/// # // This code is available in examples/doc_worksheet_set_column_autofit_width.rs
/// #
/// # use rust_xlsxwriter::{Workbook, XlsxError, autofit_cell_width};
/// # use rust_xlsxwriter::{Workbook, XlsxError, cell_autofit_width};
/// #
/// # fn main() -> Result<(), XlsxError> {
/// # let mut workbook = Workbook::new();
Expand All @@ -828,10 +828,10 @@ pub(crate) fn validate_vba_name(name: &str) -> Result<(), XlsxError> {
/// worksheet.write_column(0, 0, cities)?;
///
/// // Find the maximum column width in pixels.
/// let max_width = cities.iter().map(|s| autofit_cell_width(s)).max().unwrap();
/// let max_width = cities.iter().map(|s| cell_autofit_width(s)).max().unwrap();
///
/// // Set the column width as if it was auto-fitted.
/// worksheet.set_column_auto_width(0, max_width)?;
/// worksheet.set_column_autofit_width(0, max_width)?;
/// #
/// # workbook.save("worksheet.xlsx")?;
/// #
Expand All @@ -842,9 +842,9 @@ pub(crate) fn validate_vba_name(name: &str) -> Result<(), XlsxError> {
/// Output file:
///
/// <img
/// src="https://rustxlsxwriter.github.io/images/worksheet_set_column_auto_width.png">
/// src="https://rustxlsxwriter.github.io/images/worksheet_set_column_autofit_width.png">
///
pub fn autofit_cell_width(string: &str) -> u16 {
pub fn cell_autofit_width(string: &str) -> u16 {
let cell_padding = 7;

pixel_width(string) + cell_padding
Expand Down
4 changes: 2 additions & 2 deletions src/worksheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6580,7 +6580,7 @@ impl Worksheet {
/// of digits is decreased. It also doesn't apply to columns that have been
/// set manually.
///
/// The `Worksheet::set_column_auto_width()` method emulates this auto-fit
/// The `Worksheet::set_column_autofit_width()` method emulates this auto-fit
/// behavior whereas the [`Worksheet::set_column_width_pixels()`] method,
/// see above, is equivalent to setting the width manually.
///
Expand All @@ -6598,7 +6598,7 @@ impl Worksheet {
/// - [`XlsxError::RowColumnLimitError`] - Column exceeds Excel's worksheet
/// limits.
///
pub fn set_column_auto_width(
pub fn set_column_autofit_width(
&mut self,
col: ColNum,
width: u16,
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/autofit03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright 2022-2024, John McNamara, jmcnamara@cpan.org

use crate::common;
use rust_xlsxwriter::{autofit_cell_width, Workbook, XlsxError};
use rust_xlsxwriter::{cell_autofit_width, Workbook, XlsxError};

// Test to demonstrate autofit.
fn create_new_xlsx_file_1(filename: &str) -> Result<(), XlsxError> {
Expand Down Expand Up @@ -54,8 +54,8 @@ fn create_new_xlsx_file_3(filename: &str) -> Result<(), XlsxError> {
worksheet.write_string(0, 0, "A")?;
worksheet.write_string(0, 1, "A")?;

let max_col_width = autofit_cell_width("A");
worksheet.set_column_auto_width(0, max_col_width)?;
let max_col_width = cell_autofit_width("A");
worksheet.set_column_autofit_width(0, max_col_width)?;

worksheet.set_column_width(1, 1.57143)?;

Expand Down

0 comments on commit 5730012

Please sign in to comment.