惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 【当耐特】
Help Net Security
Help Net Security
P
Proofpoint News Feed
J
Java Code Geeks
爱范儿
爱范儿
Last Week in AI
Last Week in AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Full Disclosure
Google DeepMind News
Google DeepMind News
H
Help Net Security
G
Google Developers Blog
Jina AI
Jina AI
Vercel News
Vercel News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
Lohrmann on Cybersecurity
S
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
IT之家
IT之家
Security Archives - TechRepublic
Security Archives - TechRepublic
阮一峰的网络日志
阮一峰的网络日志
N
News and Events Feed by Topic
GbyAI
GbyAI
B
Blog
O
OpenAI News
博客园_首页
Cisco Talos Blog
Cisco Talos Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News: Ask HN
Hacker News: Ask HN
TaoSecurity Blog
TaoSecurity Blog
腾讯CDC
MongoDB | Blog
MongoDB | Blog
M
MIT News - Artificial intelligence
C
Cybersecurity and Infrastructure Security Agency CISA
Cyberwarzone
Cyberwarzone
Webroot Blog
Webroot Blog
Simon Willison's Weblog
Simon Willison's Weblog
Y
Y Combinator Blog
C
Cisco Blogs
A
Arctic Wolf
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Exploit Database - CXSecurity.com
Security Latest
Security Latest
AI
AI
W
WeLiveSecurity
aimingoo的专栏
aimingoo的专栏
The Register - Security
The Register - Security
Project Zero
Project Zero
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
Netflix TechBlog - Medium
Blog — PlanetScale
Blog — PlanetScale

博客园 - 挖豆

关于iframe的滚动条,如何去掉水平滚动条或垂直滚动条 javascript得到网址中传递的参数 的处理函数 页面的焦点:window.onfocus javascript 实现随机数 解析 实现随页面滚动的层(最简单效果) 如何用代码设置滚动条的位置? javascript 网页注册快捷键的函数 关于javascript和c#中日期的两点比较--以防在使用ajax时出错 CSS中的overflow css实现圆角 关于Ajax.net 操作和访问 session application request ajax.net 的使用方法--摘自网上 ArrayList用法 最全的DOS命令集. 如何写批处理文件 读取数据库表的列名,表列的数据类型 ASP内置对象详细介绍 提供一个专业提供连接字符串的网站 Excel连接字符串
在.NET中用MICROSOFT的Excel.Application 部件读取Excel表
挖豆 · 2007-08-13 · via 博客园 - 挖豆

首先
在.NET的解决方案管理器中右键单击工程找到添加引用,在选项卡里选择COM   在列表里找到Excelxx(xx是版本号有9.0;10.0等,对了一定要先安装Excel啊,否则找不到的),选择确定,然后就可以在你的程序中Excel.ApplicationClass了

string excelFilePath = @"C:\Inetpub\wwwroot\news\test.xls";
        Excel.Application myExcel = new Excel.ApplicationClass();
        object oMissing = System.Reflection.Missing.Value;
        myExcel.Application.Workbooks.Open(excelFilePath, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
        Excel.Workbook myBook = myExcel.Workbooks[1];
        Excel.Worksheet mySheet = (Excel.Worksheet)myBook.Worksheets[1];
        System.Data.DataTable dt = new System.Data.DataTable("mytable");
        dt.Columns.Add("F1", System.Type.GetType("System.String"));
        dt.Columns.Add("F2", System.Type.GetType("System.String"));
        dt.Columns.Add("F3", System.Type.GetType("System.String"));
        dt.Columns.Add("F4", System.Type.GetType("System.String"));
        dt.Columns.Add("F5", System.Type.GetType("System.String"));
        DataSet myDs = new DataSet();
        myDs.Tables.Add(dt);
        DataRow myRow;
        myDs.Clear();
        for (int i = 2; i <= 4; i++) //第一行为标题,不读取
        {
            myRow = myDs.Tables["mytable"].NewRow();
            for (int j = 1; j <= 5; j++)
            {
                Excel.Range r = (Excel.Range)mySheet.Cells[i, j];
                string strValue = r.Text.ToString();
                string aa = strValue;
                Response.Write("--"+aa+"--");

              //  string columnname = "F" + j.ToString();
                //myRow[columnname] = strValue;
            }
            Response.Write("</br>");
            //myDs.Tables["mytable"].Rows.Add(myRow);
        }
        //DataGrid1.DataSource = myDs.Tables["mytable"].DefaultView;
       // DataGrid1.DataBind();