OpenXml开发-填充Excel2007单元格的子函数
作者:互联网
//开始一个新行
public static void WriteStartRow(XmlWriter writer, int
row)
{
writer.WriteStartElement(Prefixes.SpreadsheetML, "row",
Namespaces.SpreadsheetML);
writer.WriteAttributeString("r",
row.ToString());
}
//添加内容为文本的单元格
public static
void WriteStringCell(XmlWriter writer, string column, int row, string
text)
{
writer.WriteStartElement(Prefixes.SpreadsheetML, "c",
Namespaces.SpreadsheetML);
writer.WriteAttributeString("r",
column + row.ToString());
writer.WriteAttributeString("t", "s");
int stringIndex =
SharedStrings.LookupString(text);
writer.WriteElementString(Prefixes.SpreadsheetML, "v",
Namespaces.SpreadsheetML, stringIndex.ToString());
writer.WriteEndElement();
}
//添加内容为数字的单于格
public static void WriteNumberCell(XmlWriter writer, string column, int row,
decimal value)
{
writer.WriteStartElement(Prefixes.SpreadsheetML, "c",
Namespaces.SpreadsheetML);
writer.WriteAttributeString("r",
column + row.ToString());
writer.WriteElementString(Prefixes.SpreadsheetML, "v",
Namespaces.SpreadsheetML, value.ToString("#0.00"));
writer.WriteEndElement();
}
//添加内容为公式的单元格
public static void WriteFormulaCell(XmlWriter writer, string column, int row,
string formula)
{
writer.WriteStartElement(Prefixes.SpreadsheetML, "c",
Namespaces.SpreadsheetML);
writer.WriteAttributeString("r",
column + row.ToString());
writer.WriteElementString(Prefixes.SpreadsheetML, "f",
Namespaces.SpreadsheetML, formula);
writer.WriteEndElement();
}
转载于:https://www.cnblogs.com/hjzhang/archive/2009/12/04/2043573.html
标签:单元格,writer,Excel2007,Prefixes,子函数,Namespaces,ToString,SpreadsheetML,row 来源: https://blog.csdn.net/weixin_30346033/article/details/98052899