从Excel读取超过255个字符 [英] Reading more than 255 characters from excel
问题描述
我正在尝试从excel中读取工作表数据(尝试了oldedb和odbc),发现限制为255个字符.
我尝试按照其他线程中的建议使用Range
对象
I am trying to read a sheet data from excel (tried both oldedb and odbc) and found out that there is 255 characters limit.
I tried using Range
object as suggested in other threads
(SELECT * FROM [ref_MethodInput$A1:S362])
但仍然没有运气.因此,除了使用互操作之外,还有其他方法可以克服此问题吗?也不建议进行注册表编辑,因为这需要在所有客户端计算机上进行注册表编辑.
but still no luck. So apart from using interop is there any other way to overcome this? Registry edit is also not advisable as that would need registry edits in all client machines.
推荐答案
下面的代码对我有用. 从excel(.xls和.xlsx)文件中导入数据(适用于超过255个字符的列值).
below code work for me. import data from excel (.xls & .xlsx) file (work for column value more than 255 character).
using Excel;
try
{
FileStream stream = File.Open(strFilePath, FileMode.Open, FileAccess.Read);
IExcelDataReader excelReader = null;
if (extension.Trim() == ".xls")
{
excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
}
else if (extension.Trim() == ".xlsx")
{
excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
}
excelReader.IsFirstRowAsColumnNames = true;
DataSet result = excelReader.AsDataSet();
excelReader.Close();
}
catch (Exception err)
{
mResult.Message = err.Message;
}
下载nuget软件包: 1)PCLStorage(版本:1.0.2) 2)ExcelDataReader-DevNet45(版本:1.0.0.2)
Download nuget packages: 1) PCLStorage (Version: 1.0.2) 2) ExcelDataReader-DevNet45 (version: 1.0.0.2)
这篇关于从Excel读取超过255个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!