Search This Blog

Showing posts with label Office. Show all posts
Showing posts with label Office. Show all posts

Saturday, June 6, 2015

Interop.Word Documents.Open is null


If you are still looking for the answer I have found it just a moment ago for my project.

Open DCOM Config Settings:

    Start -> dcomcnfg.exe
    Computer
    Local Computer
    Config DCOM
    Search for Microsoft Word 97-2003 Documents -> Properties

Tab Identity, change from Launching User to Interactive User


Interop.Word Documents.Open is null

https://support.microsoft.com/en-us/kb/176799

http://forums.asp.net/t/1232621.aspx?Interop+Word+Document+Add+returning+null

http://forums.asp.net/t/1902899.aspx?Cannot+open+a+Word+doc

Wednesday, July 17, 2013


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
using System.Reflection;
using Excel = Microsoft.Office.Interop.Excel;


namespace Read_Excel_Windows_Forms
{
    public partial class Form1 : Form
    {
        OleDbConnection con;
        DataTable dt;
        public Form1()
        {
            InitializeComponent();
            InitializeOpenFileDialog();
        }

        private void InitializeOpenFileDialog()
        {
            this.openFileDialog1.Title = "Select an excel file";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            GetExcelFields();
        }

        public void GetExcelFields()
        {
            DialogResult dr = this.openFileDialog1.ShowDialog();
            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0;HDR=YES;IMEX=1;""", openFileDialog1.FileName);
                string query = String.Format("select * from [{0}$]", "Sheet1");
                OleDbConnection con = new OleDbConnection(connectionString);
                con.Open();
                OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
                DataTable dt = new DataTable();
                dataAdapter.Fill(dt);
                int cnt = dt.Columns.Count;
                //int i = 1;
                List<ExcelItemPairs> data = new List<ExcelItemPairs>();
                foreach (DataColumn col in dt.Columns)
                {
                    comboBox1.DisplayMember = "Value";
                    comboBox1.Items.Add(new ExcelItemPairs() { Value= Convert.ToString(col.ColumnName), Type=Convert.ToString(col.DataType)});
                }
             
                DataSet dataSet = new DataSet();
                dataAdapter.Fill(dataSet);
                dataGridView1.DataSource = dataSet.Tables[0];
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ExcelItemPairs objType = (ExcelItemPairs)comboBox1.SelectedItem;
            label1.Text = objType.Type;
        }
    }
}