Ejemplo n.º 1
0
        /// <summary>
        /// 行单元格
        /// </summary>
        /// <param name="type"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private string GetCellString(XMLColumnType type, string value)
        {
            string  cellValue = value;
            string  cellStyle = "";
            decimal decimalvalue;

            if (type == XMLColumnType.DateTime)
            {
                DateTime dt;
                if (DateTime.TryParse(value, out dt))
                {
                    cellValue = dt.ToString("yyyy-MM-ddTHH:mm:ss");
                    //cellValue = dt.ToString("yyyy-MM-dd");
                }
                cellStyle = " ss:StyleID='sd'";

                if (string.IsNullOrWhiteSpace(cellValue))
                {
                    type      = XMLColumnType.String;
                    cellStyle = "";
                }
            }
            //如果列的类型是数字类型,且数据能正常转换成decimal类型 ,add by yecs 20160712
            else if (type == XMLColumnType.Number && decimal.TryParse(value, out decimalvalue))
            {
                cellStyle = " ss:StyleID='sc'";
                type      = XMLColumnType.Number;
            }
            else
            {
                Regex reg = new Regex(@"^[-]?\d+[.]?\d*$");
                if (value != null && reg.IsMatch(value))
                {
                    if (value.Contains(".") || value == "0" || (value.Length < 6 && !value.StartsWith("0")) || value.StartsWith("-"))
                    {
                        type = XMLColumnType.Number;
                    }
                    else
                    {
                        type = XMLColumnType.String;
                    }
                }
                else
                {
                    type = XMLColumnType.String;
                }
                cellStyle = " ss:StyleID='sc'";
            }

            return("<Cell" + cellStyle + "><Data ss:Type='" + type.ToString() + "'>" + cellValue + "</Data></Cell>");
        }
Ejemplo n.º 2
0
 public XMLColumn(string columnName, XMLColumnType columnType = XMLColumnType.String, string dataName = "")
 {
     this.ColumnType = columnType;
     this.ColumnName = columnName;
     this.DataName   = dataName;
 }