Example #1
0
        private void ExcelDataToDic(Dictionary <string, string> dicExcel, Dictionary <string, string> result, Range range,
                                    bool isNewDictionary)
        {
            string name;
            Cell   cell   = range[0, 0];
            Style  style  = cell.GetStyle();
            string custom = style.CultureCustom != null?style.CultureCustom.ToLower() : "";

            string r1C1Formula = cell.R1C1Formula != null?cell.R1C1Formula.ToLower() : "";

            #region 判断该名称管理器是否是全局的  不是则进行分隔取出正确的名字

            if (range.Name.Contains("!"))
            {
                name = range.Name.Split('!')[1] ?? range.Name;
            }
            else
            {
                name = range.Name;
            }

            #endregion

            decimal d;
            if (custom.IndexOf("年", StringComparison.Ordinal) >= 0 && cell.StringValue != "")
            {
                AsposeHelper.AddItem(isNewDictionary ? result : dicExcel, name,
                                     custom.IndexOf("dbnum1", StringComparison.Ordinal) >= 0
                        ? AsposeHelper.ConvertDate(cell.StringValue, "dbnum1")
                        : AsposeHelper.ConvertDate(cell.StringValue));
            }
            else if (custom.IndexOf("dbnum1", StringComparison.Ordinal) >= 0 &&
                     decimal.TryParse(cell.StringValue, out d))
            {
                AsposeHelper.AddItem(isNewDictionary ? result : dicExcel, name,
                                     InternationalNumericFormatter.FormatWithCulture("Ln", Convert.ToDecimal(cell.StringValue),
                                                                                     null, new CultureInfo("zh-CHS")));
            }
            else if (custom.IndexOf("dbnum2", StringComparison.Ordinal) >= 0 ||
                     r1C1Formula.IndexOf("dbnum2", StringComparison.Ordinal) >= 0)
            {
                AsposeHelper.AddItem(isNewDictionary ? result : dicExcel, name,
                                     AsposeHelper.CmycurD(cell.StringValue));
                //InternationalNumericFormatter.FormatWithCulture("L", Convert.ToDecimal(cell.StringValue), null, new CultureInfo("zh-CHS")));
            }
            else
            {
                AsposeHelper.AddItem(isNewDictionary ? result : dicExcel, name, AsposeHelper.TryGetDecimal(cell.DisplayStringValue) ? cell.DisplayStringValue.Trim() : cell.DisplayStringValue);
            }
        }
Example #2
0
 /// <summary>
 /// 值填入excel
 /// </summary>
 /// <param name="cell"></param>
 /// <param name="style"></param>
 /// <param name="value"></param>
 private void PutExcelValue(Cell cell, Style style, string value)
 {
     if ((cell.Type == CellValueType.IsNumeric || cell.NumberCategoryType == NumberCategoryType.Number || cell.NumberCategoryType == NumberCategoryType.Scientific || cell.NumberCategoryType == NumberCategoryType.General || cell.NumberCategoryType == NumberCategoryType.Fraction) && AsposeHelper.TryGetDecimal(value))
     {
         cell.PutValue(Convert.ToDecimal(value));
     }
     else if ((style.IsDateTime || cell.Type == CellValueType.IsDateTime || cell.NumberCategoryType == NumberCategoryType.Date) && AsposeHelper.TryGetDateTime(value))
     {
         cell.PutValue(Convert.ToDateTime(value));
     }
     else if (cell.Type == CellValueType.IsBool && AsposeHelper.TryGetbool(value))
     {
         cell.PutValue(Convert.ToBoolean(value));
     }
     else if (cell.Type == CellValueType.IsNull || cell.Type == CellValueType.IsString)
     {
         cell.PutValue(value);
     }
     else
     {
         cell.PutValue(value);
     }
 }