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/blue-skies/archive/2010/07/19/1780838.html

你可能感兴趣的:(OpenXml开发-填充Excel2007单元格的子函数)