获取不包含N/A值的Excel范围C# [英] Get Excel range without N/A values C#
问题描述
我们目前正在以这种方式将Excel工作表的内容转换为二维数组:
we are currently getting the content of an Excel Sheet into a bidimensional array this way:
Excel.Range rango = excelSheet.UsedRange;
object[,] excelData = (object[,])rango.Value2;
然后,该信息用于存储在数据库中,但是问题是,在数组中,一些N/A值来自Excel,并且在保存到数据库时会引起麻烦(我们稍后尝试使用批量插入)是有没有办法在获取范围时替换空字符串的N/A值?我已经尝试过遍历整个数组,但是这样做不可行,因为我们最多可以拥有300万条记录,并且花费的时间太长.
And later the info is used to store in a Database but, the issue is that within the array some N/A values come from Excel and cause troubles when saving to the Database (we try later with a bulk insert), is there any way to replace the N/A values for empty strings when getting the range? I have tried looping through the array but this is not viable since we can have up to 3 million records and it takes too long.
谢谢.
推荐答案
感谢您的评论,我做到了这一点:
Thanks for the comments, I did the trick this way:
Excel.Range rango = excelSheet.UsedRange;
rango.Replace("#N/A","");
object[,] excelData = (object[,])rango.Value2;
希望这对以后的人有帮助.
Hope this helps someone in the future.
这篇关于获取不包含N/A值的Excel范围C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!