Open Excel file usint Interop using C#

0

I have this code in C# y used to open a Excel file.

Excel.Application oXL = new Excel.Application();
Excel._Workbook oWB;

String filename = "C:\\plantilla2.xlsx";

oWB = oXL.Workbooks.Open(filename, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);

MessageBox.Show("FIN");

This code worked fine two days ago. I have not changed anything and now I get an error in the line where opens the excel file. First I see a message "Excel is trying to recover information"

And after that I get the exception "Error in remote procedure call. (Excepción de HRESULT: 0x800706BE)"

I don't know what is going wrong. I have checked the references as explained in this web. http://csharp.net-informations.com/excel/csharp-open-excel.htm

c#
excel
asked on Stack Overflow Oct 10, 2016 by Kezern • edited Oct 10, 2016 by Kezern

3 Answers

0

Looks like RPC service down. Are you insure that service "Remote Procedure Call (RPC)" here "Control Panel\Administrative Tools\Services" have a "Running" state ?

answered on Stack Overflow Oct 10, 2016 by Sergey Vaulin
0

I don't know what has happened. I have restarted the computer and now it works.

answered on Stack Overflow Oct 11, 2016 by Kezern
0

This should help.

using System;
using System.Drawing;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel; 

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                System.Data.OleDb.OleDbConnection MyConnection ;
                System.Data.DataSet DtSet ;
                System.Data.OleDb.OleDbDataAdapter MyCommand ;
                MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\\csharp.net-informations.xls';Extended Properties=Excel 8.0;");
                MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
                MyCommand.TableMappings.Add("Table", "TestTable");
                DtSet = new System.Data.DataSet();
                MyCommand.Fill(DtSet);
                dataGridView1.DataSource = DtSet.Tables[0];
                MyConnection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show (ex.ToString());
            }
        }
   }
}

See this link.

http://csharp.net-informations.com/excel/csharp-excel-oledb.htm

answered on Stack Overflow Dec 28, 2016 by (unknown user)

User contributions licensed under CC BY-SA 3.0