http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 6289|回复: 11

[其他] 导入EXCEL

[复制链接]
发表于 2013-4-25 09:31:53 | 显示全部楼层 |阅读模式
在做 EXCEL 导入的时候 如何按   EXCEL 内的表查找啊,EXCEL 是一张报表的样子  我想取单表来做 ???
[code=csharp] /// <summary>
        /// 由EXCEL转换成DataTable(Excel绝对路径)   ICU病人日志
        /// </summary>
        /// <param name="excelPath"></param>
        /// <returns></returns>
        public static DataTable GetDataTableICU1(string excelPath)
        {
            string selectCommandText = "select * from [sheet1$A3:F35] ";
            DataSet dataSet = null;
            dataSet = new DataSet();
            new OleDbDataAdapter(selectCommandText, ExcelConnectionString(excelPath)).Fill(dataSet);
            if (dataSet.Tables.Count > 0)
            {
                return dataSet.Tables[0];
            }
            return null;
        }
        /// <summary>
        /// 构造Excel的连接字符串
        /// </summary>
        /// <param name="excelPath"></param>
        /// <returns></returns>
        private static string ExcelConnectionString(string excelPath)
        {
            if (!excelPath.ToLower().Contains(".xlsx"))
            {
                return string.Format(
                    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0;",
                    excelPath);
            }
            return string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0;HDR=Yes;IMEX=1;'",
                excelPath);
        }[/code]

变成这样 很多数据读不出来


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-4-25 09:36:33 | 显示全部楼层
http://www.sufeinet.com/thread-2029-1-1.html
去看看这个,或者去下载下我的基类库里面有导入的方法
 楼主| 发表于 2013-4-25 09:37:30 | 显示全部楼层
导入是可以的 就是导入的很数据 是红点 的样子
发表于 2013-4-25 09:44:30 | 显示全部楼层
liuyl 发表于 2013-4-25 09:37
导入是可以的 就是导入的很数据 是红点 的样子

在一楼贴下你的代码吧
 楼主| 发表于 2013-4-25 10:00:49 | 显示全部楼层
[code=csharp]        /// <summary>
        /// 由EXCEL转换成DataTable(Excel绝对路径)   ICU病人日志
        /// </summary>
        /// <param name="excelPath"></param>
        /// <returns></returns>
        public static DataTable GetDataTableICU1(string excelPath)
        {
            string selectCommandText = "select * from [sheet1$A3:F35] ";

            DataSet dataSet = null;
            dataSet = new DataSet();
            new OleDbDataAdapter(selectCommandText, ExcelConnectionString(excelPath)).Fill(dataSet);
            if (dataSet.Tables.Count > 0)
            {
                return dataSet.Tables[0];
            }

            return null;
        }

        /// <summary>
        /// 构造Excel的连接字符串
        /// </summary>
        /// <param name="excelPath"></param>
        /// <returns></returns>
        private static string ExcelConnectionString(string excelPath)
        {
            if (!excelPath.ToLower().Contains(".xlsx"))
            {
                return string.Format(
                    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0;",
                    excelPath);
            }
            return string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0;HDR=Yes;IMEX=1;'",
                excelPath);

        }
[/code]
发表于 2013-4-25 10:23:25 | 显示全部楼层
liuyl 发表于 2013-4-25 10:00

导出来是什么效果
 楼主| 发表于 2013-4-25 10:26:50 | 显示全部楼层
未命名.jpg 变成这样 很多数据读不出来

发表于 2013-4-25 10:30:12 | 显示全部楼层
liuyl 发表于 2013-4-25 10:26
变成这样 很多数据读不出来

我建议你先看看读出来的DataTable里是数据格式的数据,你应该会调试吧,在调试模式下看看Dataset里的数据是什么,然后发个图片出来看看
 楼主| 发表于 2013-4-25 10:31:12 | 显示全部楼层
我貌似明白了 , 可能是打开table 的时候数据读取的问题 其实数据已经存在 因为我每次打开那个tabel  数据都不一样,有时候只有 1 2 条显示不出来 ,有时候一大片 ,我去做个遍历试试吧。。。
 楼主| 发表于 2013-4-25 10:36:24 | 显示全部楼层
可以了 其实是table 里面数据展示的问题。 我直接遍历了下table  
其实数据都有在

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-3 16:41

© 2014-2021

快速回复 返回顶部 返回列表