thscharler / spreadsheet-ods

Apache License 2.0
29 stars 6 forks source link

date / currency value formats not working; xmlns:number missing in root elment #22

Closed rbi closed 3 years ago

rbi commented 3 years ago

how to reproduce

use std::path::Path;
use std::error::Error;

use chrono::{NaiveDateTime, NaiveDate, NaiveTime};
use spreadsheet_ods::*;

pub fn write() -> Result<(), impl Error> {

    let mut work_book = WorkBook::new();

    let date_format = work_book.add_format(format::create_date_dmy_format("date_format"));
    let date_style = work_book.add_cellstyle(CellStyle::new("date", &date_format));

    let mut sheet = Sheet::new_with_name("some sheet");
    let value = NaiveDateTime::new(NaiveDate::from_ymd(2021, 05, 02), NaiveTime::from_hms(12,23,24));
    sheet.set_styled_value(0, 0, value, &date_style);

    work_book.push_sheet(sheet);
    write_ods(&work_book, Path::new("out.ods"))
}

what happened

what should happen

analysis

The XML namespace xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" seams missing from content.xml. This is what xmllint says when formatting the file.

content.xml:2: namespace error : Namespace prefix number for style on day is not defined
tyle><number:date-style style:name="date_format"><number:day number:style="long"

Manually adding xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" to content.xml and putting it back into out.ods seams to fix the issue.

thscharler commented 3 years ago

Yes, I notized this too, just forgot to publish a patch. Done.