Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7862373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:06:26+00:00 2026-06-02T23:06:26+00:00

I’m using C# to write out an OpenDocument spreadsheet in XML. No problem with

  • 0

I’m using C# to write out an OpenDocument spreadsheet in XML. No problem with writing double values, which work fine just like this:

    private void SaveFloatCell(XmlNode rowNode, XmlDocument ownerDocument, double number)
    {
        XmlElement cellNode = ownerDocument.CreateElement("table:table-cell", this.GetNamespaceUri("table"));

        XmlAttribute valueType = ownerDocument.CreateAttribute("office:value-type", this.GetNamespaceUri("office"));
        valueType.Value = "float";
        cellNode.Attributes.Append(valueType);

        XmlAttribute value = ownerDocument.CreateAttribute("office:value", this.GetNamespaceUri("office"));
        value.Value = number.ToString(CultureInfo.InvariantCulture);
        cellNode.Attributes.Append(value);

        rowNode.AppendChild(cellNode);
    }

However, when trying to save DateTime values I can’t get them to display properly. This is what I have so far, which displays “2012” in the cell instead of the specified Date format:

    private void SaveDateTimeCell(XmlNode rowNode, XmlDocument ownerDocument, double number, string format)
    {
        XmlElement cellNode = ownerDocument.CreateElement("table:table-cell", this.GetNamespaceUri("table"));

        XmlAttribute valueType = ownerDocument.CreateAttribute("office:value-type", this.GetNamespaceUri("office"));
        valueType.Value = "date";
        cellNode.Attributes.Append(valueType);

        XmlAttribute value = ownerDocument.CreateAttribute("office:value", this.GetNamespaceUri("office"));
        value.Value = Utils.DateTime(number).ToString("yyyy-mm-ddThh:mm:ss");
        cellNode.Attributes.Append(value);

        rowNode.AppendChild(cellNode);
    }

I’ve spent quite a while playing with various code snippets I’ve found, but with no success. On the offchance, is there any generous soul out there that can help me with this?

Many thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:06:28+00:00Added an answer on June 2, 2026 at 11:06 pm

    Ok, I have the answer. The final code looks like this:

        private void SaveDateTimeCell(XmlNode rowNode, XmlDocument ownerDocument, double number, string format)
        {
            XmlElement cellNode = ownerDocument.CreateElement("table:table-cell", this.GetNamespaceUri("table"));
    
            XmlAttribute valueType = ownerDocument.CreateAttribute("office:value-type", this.GetNamespaceUri("office"));
            valueType.Value = "date";
            cellNode.Attributes.Append(valueType);
    
            XmlAttribute value = ownerDocument.CreateAttribute("office:date-value", this.GetNamespaceUri("office"));
            value.Value = Utils.DateTime(number).ToString("yyyy-MM-ddTHH:mm:ss");
            cellNode.Attributes.Append(value);
    
            XmlAttribute tableStyleName = ownerDocument.CreateAttribute("table:style-name", this.GetNamespaceUri("table"));
            tableStyleName.Value = "ce2";
            cellNode.Attributes.Append(tableStyleName);
    
            rowNode.AppendChild(cellNode);
        }
    

    It’s the definition of “ce2” which is key. This is done in the styles.xml file of the unzipped *.ods file:

        private void SaveStyleSheet(XmlNode sheetsRootNode)
        {
            XmlDocument ownerDocument = sheetsRootNode.OwnerDocument;
    
            XmlNode sheetNode = ownerDocument.CreateElement("number:date-style", this.GetNamespaceUri("number"));
    
            XmlAttribute styleName = ownerDocument.CreateAttribute("style:name", this.GetNamespaceUri("style"));
            styleName.Value = "N19";
            sheetNode.Attributes.Append(styleName);
    
            XmlElement numberDay = ownerDocument.CreateElement("number:day", this.GetNamespaceUri("number"));
            XmlAttribute numberStyle = ownerDocument.CreateAttribute("number:style", this.GetNamespaceUri("number"));
            numberStyle.Value = "long";
            numberDay.Attributes.Append(numberStyle);
            sheetNode.AppendChild(numberDay);
    
            XmlElement numberText = ownerDocument.CreateElement("number:text", this.GetNamespaceUri("number"));
            numberText.InnerText = "/";
            sheetNode.AppendChild(numberText);
    
            XmlElement numberMonth = ownerDocument.CreateElement("number:month", this.GetNamespaceUri("number"));
            XmlAttribute numberStyle2 = ownerDocument.CreateAttribute("number:style", this.GetNamespaceUri("number"));
            numberStyle2.Value = "long";
            numberMonth.Attributes.Append(numberStyle2);
            sheetNode.AppendChild(numberMonth);
    
            XmlElement numberText2 = ownerDocument.CreateElement("number:text", this.GetNamespaceUri("number"));
            numberText2.InnerText = "/";
            sheetNode.AppendChild(numberText2);
    
            XmlElement numberYear = ownerDocument.CreateElement("number:year", this.GetNamespaceUri("number"));
            XmlAttribute numberStyle3 = ownerDocument.CreateAttribute("number:style", this.GetNamespaceUri("number"));
            numberStyle3.Value = "long";
            numberYear.Attributes.Append(numberStyle3);
            sheetNode.AppendChild(numberYear);
    
            sheetsRootNode.AppendChild(sheetNode);
        }
    

    This date-style N19 is then referred to in the automatic-styles of the content.xml of the unzipped *.ods file thus:

        private void SaveAutomaticStyleSheet(XmlNode sheetsRootNode)
        {
            XmlDocument ownerDocument = sheetsRootNode.OwnerDocument;
    
            XmlNode sheetNode = ownerDocument.CreateElement("style:style", this.GetNamespaceUri("style"));
    
            XmlAttribute styleName = ownerDocument.CreateAttribute("style:name", this.GetNamespaceUri("style"));
            styleName.Value = "ce2";
            sheetNode.Attributes.Append(styleName);
    
            XmlAttribute styleFamily = ownerDocument.CreateAttribute("style:family", this.GetNamespaceUri("style"));
            styleFamily.Value = "table-cell";
            sheetNode.Attributes.Append(styleFamily);
    
            XmlAttribute styleParentStyleName = ownerDocument.CreateAttribute("style:parent-style-name", this.GetNamespaceUri("style"));
            styleParentStyleName.Value = "Default";
            sheetNode.Attributes.Append(styleParentStyleName);
    
            XmlAttribute styleDataStyleName = ownerDocument.CreateAttribute("style:data-style-name", this.GetNamespaceUri("style"));
            styleDataStyleName.Value = "N19";
            sheetNode.Attributes.Append(styleDataStyleName);
    
            sheetsRootNode.AppendChild(sheetNode);
        }
    

    In fact, Jon’s suggestions were necessary as well for the code to work perfectly. So thanks again Jon. Anyhow, a black, black art indeed … 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.