I have 2 projects in a solution :One is Console Project where communicate with PLC and another is Excel add-in project.
My Problem: using .dll (x32bit) and run on Excel 64bit. Control button by Ribbon button to connect or disconnect to PLC. So, I added Excel add-in project in Console Project's references to use Excel add-in public class. But, i cannot call constructor of VSTO Addin
public ThisAddIn(global::Microsoft.Office.Tools.Word.ApplicationFactory factory, global::System.IServiceProvider serviceProvider) :
base(factory, serviceProvider, "AddIn", "ThisAddIn") {
Globals.Factory = factory;
}
Here my code in Console:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using Microsoft.Office.Tools.Ribbon;
using PLC2EXCEL_Addin;
using DATABUILDERAXLibLB;
using Microsoft.Office.Tools.Ribbon;
using System.Runtime.InteropServices;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Excel;
namespace PLC2EXCEL
{
class Program
{
public static DBCommManager dBCommManager = new DBCommManager();
static void Main(string[] args)
{
dBCommManager.PLC=DBPlcId.DBPLC_KV3000;
dBCommManager.Peer = "USB";
//Microsoft.Office.Tools.Excel.ApplicationFactory _fatory ;
//_fatory.GetRibbonFactory();
//ThisAddIn thisAddIn = new ThisAddIn(Microsoft.Office.Tools.Excel.ApplicationFactory,IServerProvider); //i am not sure about this
PLC2EXCEL_Ribbon pLC2EXCEL_Ribbon = new PLC2EXCEL_Ribbon();
if (pLC2EXCEL_Ribbon != null)
pLC2EXCEL_Ribbon.connectPLC_btn.Click += new RibbonControlEventHandler(startPLC2Excel);
dBCommManager.Connect();
Console.WriteLine("Connect PLC OK");
Console.ReadLine();
}
public event EventHandler startPLC2Excel1;
public static void startPLC2Excel(object sender, RibbonControlEventArgs eventArgs)
{
//DATABUILDERAXLibLB.DBCommManager dBCommManager = new DBCommManager();
//dBCommManager.PLC = DBPlcId.DBPLC_KV3000;
//dBCommManager.Peer = "USB";
dBCommManager.Connect();
Console.WriteLine("Connect PLC OK");
Console.ReadLine();
}
}
}
And code in Ribbon of Excel Addin:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Tools.Ribbon;
namespace PLC2EXCEL_Addin
{
public partial class PLC2EXCEL_Ribbon
{
private void PLC2EXCEL_Ribbon_Load(object sender, RibbonUIEventArgs e)
{
}
[ComVisible(true)]
public void connectPLC_btn_Click(object sender, RibbonControlEventArgs e) //How to catch this event from Console project
{
//Catch event
MessageBox.Show("Connect to PLC");
}
public void abc() { }
}
}
Sorry any inconvenience, this is my first post. Thank in advance.
Impossible to use .dll 32bit on 64bit Excel,So I have solved my problem by create 2 separate projects:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.