使用closedXML C#库,我怎么能弄清楚哪些数据导致试图挽救此错误时 [英] Using closedXML C# library, How can I figure out what data is causing this error when trying to save

查看:874
本文介绍了使用closedXML C#库,我怎么能弄清楚哪些数据导致试图挽救此错误时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用 ClosedXML 出口到Excel中的一个C#应用程序。它工作正常,但只是碰到了一个问题,当我打的:

I have a C# app that exports to Excel using ClosedXML. It works fine but just ran into an issue where when i hit the :

  var ms = new MemoryStream();
  workbook.SaveAs(ms);



我得到一个异常:

I get an exception:

' ', hexadecimal value 0x0B, is an invalid character

它确定数据相关的,因为它,我看某些数据它的工作原理是导致这个问题很好,但是其他数据。

Its definitely data related because it I look at certain data it works fine but other data it causes this issue.

我怎么能找出哪些性格导致了问题?此外,一旦我明白这一点,什么是发现哪里这个角色是我的数据中的最佳方式是什么?

how can i figure out which character is causing the issue? Also, once I figure that out, what is the best way of finding where this character is within my data?

推荐答案

既然你在你投入ClosedXML表中的数据/串无效字符,你必须要找到他们,并把他们救出来。

Since you have invalid characters in the data / strings you put into the ClosedXML sheet, you have to find them and get them out.

最简单的解决方案是增加

The simplest solution is to add

.Replace((0x0B).ToString(), " ")

为您的所有字符串摆脱垂直选项卡,​​并用空格代替它们。

to all your strings to get rid of the vertical tabs and replace them with spaces.

这篇关于使用closedXML C#库,我怎么能弄清楚哪些数据导致试图挽救此错误时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆