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

推荐订阅源

IT之家
IT之家
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
L
LangChain Blog
爱范儿
爱范儿
博客园_首页
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 三生石上(FineUI控件)
大猫的无限游戏
大猫的无限游戏
宝玉的分享
宝玉的分享
GbyAI
GbyAI
H
Help Net Security
A
About on SuperTechFans
Recent Announcements
Recent Announcements
Hugging Face - Blog
Hugging Face - Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
雷峰网
雷峰网
D
Docker
博客园 - Franky
有赞技术团队
有赞技术团队
G
Google Developers Blog

博客园 - !LEO

采用WF实现审批备案的流程定义 Inside Microsoft Windows SharePoint Services 3.0 Saas安全性问题讨论 NHibernate事务中执行SQL Winform+WebService分层模型 Winform+WebService离线处理 使用BackgroundWorker控件进行异步处理 在多个方法中共享database object的方式 Reporting Service 初体验 解决vs2005 安装项目不支持中文的问题 Mutex类解决进程线程互斥问题 Javascript调用C#静态函数 javascript:URL编解码和父子窗口交互 VisualStudio2005应用CSS和JavaScrpt的问题 两款oralce开发工具 NBear 不错 今日测试总结 SSIS计算行号 一起学习SSIS
C#读取Word表格中的数据
!LEO · 2008-02-13 · via 博客园 - !LEO

 1using System;
 2using System.Collections.Generic;
 3using System.ComponentModel;
 4using System.Data;
 5using System.Drawing;
 6using System.Text;
 7using System.Windows.Forms;
 8using Interop.Word;
 9
10namespace DataAccessTest
11{
12    public partial class WordTableRead : Form
13    {
14        public WordTableRead()
15        {
16            InitializeComponent();
17        }

18
19        private void button1_Click(object sender, EventArgs e)
20        {
21            ApplicationClass cls = null;
22            Document doc = null;
23            Interop.Word.Table table = null;
24            object missing = System.Reflection.Missing.Value;
25            int rowIndex = 1, colIndex = 2;
26
27            object path = @"C:\temp3.doc";
28            cls = new ApplicationClass();
29
30            try
31            {
32                doc = cls.Documents.Open(ref path, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
33                table = doc.Tables.Item(1);
34
35                string text = table.Cell(rowIndex, colIndex).Range.Text;
36                this.textBox1.Text = text.Substring(0, text.Length - 1);    //去除尾部的mark                
37            }

38            catch (Exception ex)
39            {
40                if (ex is System.Runtime.InteropServices.COMException)
41                {
42                    MessageBox.Show(((System.Runtime.InteropServices.COMException)(ex)).ErrorCode.ToString());
43                }

44            }

45            finally
46            {
47                if( doc != null ) doc.Close(ref missing, ref missing, ref missing);
48                cls.Quit(ref missing, ref missing, ref missing);
49            }

50        }

51    }

52}

引用的dll https://files.cnblogs.com/liguancong/Interop.Word.rar