C#&XLW 5 – 如何在Excel中显示明智的错误信息引发exception?
使用xlwDotNet,我创build了一个返回一个数字的简单函数。 有时候,出现了一些问题,我试图向Excel传播一个exception消息。
当我使用throw new Exception("Message")
,Excel只显示"System.Exception : "
作为消息回发在多行,消息被切断,因为单元格只显示顶行。
如何将错误消息传播到Excel并禁用所有其他文本,即只显示“消息”而不显示“System.Exception xxxxx”?
你应该使用
private static cellMatrixException ReportMessage(string errorMessage, string mainCategory, string minorCategory) { var theContent = new ArgumentList(mainCategory); theContent.add(minorCategory, errorMessage); return new cellMatrixException(errorMessage, theContent.AllData()); }