わかりました、私は答えを持っています。最終的なコードは次のようになります。
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);
}
鍵となるのは「ce2」の定義です。これは、解凍された *.ods ファイルの styles.xml ファイルで行われます。
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);
}
この日付スタイル N19 は、解凍された *.ods ファイルの content.xml の自動スタイルで参照されます。
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);
}
実際、コードが完全に機能するためには、Jon の提案も必要でした。ありがとう、ジョン。とにかく、確かに黒、黒の芸術... :)