xlsx-handlebars 0.2.1

A Rust library for processing XLSX files with Handlebars templates, supporting WASM, Node.js, Deno, and browsers
Documentation
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::JsValue;

pub mod errors;
pub mod imagesize;
mod template;
pub mod utils;

// 重新导出常用的类型和函数
pub use errors::XlsxError;
pub use utils::{to_column_index, to_column_name, timestamp_to_excel_date, excel_date_to_timestamp};

// WASM 平台:导出 WASM 兼容的渲染函数
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
pub fn render_template(
    zip_bytes: Vec<u8>,
    data_json: &str,
) -> Result<JsValue, JsValue> {
    let data: serde_json::Value = serde_json::from_str(data_json)
            .map_err(|e| JsValue::from_str(&format!("JSON Parse Error: {e}")))?;

    // 调用模板渲染函数
    let result = template::render_template(zip_bytes, &data)
        .map_err(|e| JsValue::from_str(&e.to_string()))?;

    // 返回结果
    Ok(JsValue::from(result))
}

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
pub fn wasm_to_column_name(current: &str, increment: u32) -> String {
    utils::to_column_name(current, increment)
}

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
pub fn wasm_to_column_index(col_name: &str) -> u32 {
    utils::to_column_index(col_name)
}

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
pub fn wasm_timestamp_to_excel_date(timestamp_ms: i64) -> f64 {
    utils::timestamp_to_excel_date(timestamp_ms)
}

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
pub fn wasm_excel_date_to_timestamp(excel_date: f64) -> Option<i64> {
    utils::excel_date_to_timestamp(excel_date)
}

// 非 WASM 平台:直接导出原生 Rust 函数
#[cfg(not(target_arch = "wasm32"))]
pub use template::render_template;