找回密码
 立即注册

QQ登录

只需一步,快速开始

study1990
金牌服务用户   /  发表于:2015-3-20 10:33  /   查看:4546  /  回复:2
表格中含有两个以上自定义公式时,导出excel报错。

报表导出的时候,调用 ReportTemplate.SaveExcel(path);这个方法
[10:25:00] 林大伟: 报错:捕捉到 System.ApplicationException
  HResult=-2146232832
  Message=Error saving Excel file
  Source=FarPoint.Web.Spread
  StackTrace:
       在 fu.a(String A_0, Stream A_1, ExcelSaveFlags A_2, ExcelWarningList A_3, String A_4)
       在 fu.a(String A_0, ExcelSaveFlags A_1, ExcelWarningList A_2, String A_3)
       在 FarPoint.Web.Spread.FpSpread.SaveExcel(String fileName, ExcelSaveFlags excelSaveFlags, ExcelWarningList warningList, String password)
       在 FarPoint.Web.Spread.FpSpread.SaveExcel(String fileName, String password)
       在 FarPoint.Web.Spread.FpSpread.SaveExcel(String fileName)
       在 WebReport.Controllers.TemplateController.ExportExcel(String rename, FpSpread ReportTemplate) 位置 D:\工作\项目\Report\06.Source\WebReport\Controllers\TemplateController.cs:行号 543
  InnerException: System.ArgumentException
       HResult=-2147024809
       Message=已添加了具有相同键的项。
       Source=mscorlib
       StackTrace:
            在 System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
            在 System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
            在 System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
            在 cm.a(ArrayList A_0, ArrayList A_1, ArrayList A_2, Boolean A_3)
            在 as.b(MemoryStream& A_0)
            在 as.a(MemoryStream[] A_0, Int32 A_1, ExcelSaveFlags A_2)
            在 as.a(Stream A_0, ExcelSaveFlags A_1)
            在 as.a(ExcelSaveFlags A_0)
            在 FarPoint.Excel.ExcelFileHandler.a(String A_0, ExcelSaveFlags A_1, String A_2)
            在 FarPoint.Excel.ExcelFileHandler.Save(String fileName, ExcelSaveFlags saveFlags, String password)
            在 cm.a(String A_0, ExcelSaveFlags A_1, String A_2)
            在 fu.a(String A_0, Stream A_1, ExcelSaveFlags A_2, ExcelWarningList A_3, String A_4)

2 个回复

倒序浏览
study1990
金牌服务用户   /  发表于:2015-3-20 10:35:00
沙发
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. namespace WebReport.Models.Model.Formulas.FormulasOnly.Other
  6. {
  7.     /// <summary>
  8.     /// 汇率获取公式类
  9.     /// 继承公式类的汇率获取公式类
  10.     /// </summary>
  11.     [Serializable]
  12.     public class GetRateFormula:Formula
  13.     {
  14.         double rate = 1;
  15.         string exchName = string.Empty;
  16.         //public GetRateFormula()
  17.         //{
  18.         //    this.FormulaName = "GetRate";
  19.         //}
  20.         public string ExchName
  21.         {
  22.             get { return exchName; }
  23.             set { exchName = value; }
  24.         }
  25.         public double Rate
  26.         {
  27.             get { return rate; }
  28.             set { rate = value; }
  29.         }
  30.         public override object Evaluate(object[] args)
  31.         {
  32.             if (!(-1.0).Equals(Rate))
  33.                 return Rate;
  34.             else return 1;
  35.         }
  36.         public override int MaxArgs
  37.         {
  38.             get { return 0; }
  39.         }
  40.         public override int MinArgs
  41.         {
  42.             get { return 0; }
  43.         }
  44.         public override string Name
  45.         {
  46.             get { return "GetRate"; }
  47.         }
  48.         public new  bool Deserialize(System.Xml.XmlNodeReader r)
  49.         {
  50.             return true;
  51.         }
  52.         public new bool Serialize(System.Xml.XmlTextWriter w)
  53.         {
  54.             return true;
  55.         }
  56.         public override bool AcceptsMissingArgument(int i)
  57.         {
  58.             return true;
  59.         }
  60.         public override bool AcceptsError(int i)
  61.         {
  62.             return true;
  63.         }
  64.         public override bool IgnoresValues(int i)
  65.         {
  66.             return true;
  67.         }
  68.     }
  69. }
复制代码

使用:=getrate()

在两个单元格里,分别写入,导出报错:Error saving Excel file
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-3-20 14:08:00
板凳
回复 2楼study1990的帖子

感谢您的问题反馈。
我对问题理解如下:自定义了公式,同时实现了序列和反序列化的功能。

鉴于目前的信息:Formula 并不是我们提供的类,我们只提供了 FunctionInfo 用于继承并且创建自定义公式,所以我无法做进一步调查,能否提供一个可以直接运行并重现问题的demo。我们再进一步跟进。

谢谢
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部