zoukankan      html  css  js  c++  java
  • C#读取Word表格中的数据

    using 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

  • 相关阅读:
    Maker DAO 与稳定币 Dai
    0x 协议治理体系,Part-2:Q&A
    Gnosis白皮书
    Digix:密码学资产中的黄金标准
    闪电网络主心骨——HTLC(哈希时间锁定)简介
    如何减少PDF文件的大小
    以太坊:创建 ERC-20 token
    Sublime Text 3 快捷键大全
    数据库学习第二季第三集:各种编程语言从数据库中获得数据方式小结
    数据库学习第二季第三集:各种编程语言从数据库中获得数据方式小结
  • 原文地址:https://www.cnblogs.com/andylaufzf/p/2243967.html
Copyright © 2011-2022 走看看