我使用C#以XML格式寫出OpenDocument電子表格。沒有問題,寫雙重價值,它做工精細,就像這樣:如何在OpenDocument中保存.NET DateTime
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);
}
然而,試圖挽救DateTime值的時候,我不能讓他們正確顯示。這是我到目前爲止,它顯示「2012」的單元格,而不是指定的日期格式:
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);
}
我花了相當長一段時間的各種代碼段,我發現玩,但沒有成功。關於這個問題,有沒有可以幫助我的慷慨靈魂?
非常感謝!
感謝喬恩 - 不幸的是CultureInfo.InvariantCulture不起作用,你對格式的建議更改也不會。我有一種感覺,答案與OpenDocument XML屬性的黑色藝術有關。非常感謝您的幫助! – 2012-04-24 14:39:25