jmcnamara / rust_xlsxwriter

A Rust library for creating Excel XLSX files.
https://crates.io/crates/rust_xlsxwriter
Apache License 2.0
250 stars 23 forks source link

Bug: serialized fields are not skipped correctly #76

Closed jmcnamara closed 6 months ago

jmcnamara commented 6 months ago

Current behavior

Skipping serialized fields with rust_xlsxwriter methods (but not with serde) creates non-contiguous headers. See the example below.

Sample code to reproduce

use rust_xlsxwriter::{Workbook, XlsxError, XlsxSerialize};
use serde::Serialize;

fn main() -> Result<(), XlsxError> {
    let mut workbook = Workbook::new();

    // Add a worksheet to the workbook.
    let worksheet = workbook.add_worksheet();

    // Create a serializable struct.
    #[derive(XlsxSerialize, Serialize)]
    struct Produce {
        column1: f64,
        column2: f64,

        #[xlsx(skip)]
        column3: f64,

        column4: f64,
    }

    // Set the serialization location and headers.
    worksheet.set_serialize_headers::<Produce>(0, 0)?;

    // Save the file to disk.
    workbook.save("serialize.xlsx")?;

    Ok(())
}

Environment

- `rust_xlsxwriter` version: 0.61.0

Any other information

screenshot