从Excel读取超过255个字符 [英] Reading more than 255 characters from excel

查看:253
本文介绍了从Excel读取超过255个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从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屋!

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