public void StartGenerator() { ExcelApp excelApp = null; COMAddIn comAddIn = null; if (IsEikonExcelDisable) { SetEikonExcelDisable(ref excelApp, ref comAddIn); } try { Start(); SaveTaskResult(); } catch (Exception ex) { throw ex; } finally { if (IsEikonExcelDisable) { SetEikonExcelAble(ref excelApp, ref comAddIn); } AddResult("Log file", Logger.FilePath, "log"); } }
public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { Application onApp = (Application)Application; this.addInsList = onApp.COMAddIns; this.lTools = addInsList.Item(1); }
dynamic GetAddin() { PPT.Application ppt = new PPT.Application(); COMAddIn mg = null; foreach (COMAddIn addin in ppt.COMAddIns) { if (addin.ProgId == "AddInID") { mg = addin; break; } } dynamic mgAddin = mg?.Object; mg.ReleaseCOM(); mg = null; ppt.ReleaseCOM(); ppt = null; return(mgAddin); }
public void UnloadBKTAddIn(IRibbonControl control) { COMAddIn bkt = GetBKT(); if (bkt == null) { Show("BKT not found"); return; } bkt.Connect = false; }
private void SetEikonExcelAble(ref ExcelApp excelApp, ref COMAddIn comAddIn) { if (excelApp == null) { return; } excelApp.ExcelAppInstance.AlertBeforeOverwriting = false; excelApp.ExcelAppInstance.DisplayAlerts = false; if (comAddIn != null) { comAddIn.Connect = true; } excelApp.Dispose(); }
private COMAddIn GetBKT() { if (app == null) { return(null); } COMAddIn bkt = null; try { bkt = app.COMAddIns.Item("BKT.AddIn"); return(bkt); } catch (Exception) { return(null); } }
public void OnConnection( object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { addInUtilities = new AddInUtilities(this); COMAddIn comAddIn = (COMAddIn)addInInst; comAddIn.Object = addInUtilities; applicationObject = (Excel.Application)application; addInInstance = addInInst; if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup) { OnStartupComplete(ref custom); } }
public void ReloadBKTAddIn(IRibbonControl control) { COMAddIn bkt = GetBKT(); if (bkt == null) { Show("BKT not found"); return; } if (bkt.Connect) { bkt.Connect = false; bkt.Connect = true; } else { bkt.Connect = true; } }
private void SetEikonExcelDisable(ref ExcelApp excelApp, ref COMAddIn comAddIn) { excelApp = new ExcelApp(false, false); if (excelApp == null) { string msg = "Excel could not be started. Check that your office installation and project reference are correct!"; Logger.Log(msg, Logger.LogType.Error); return; } COMAddIns addIns = excelApp.ExcelAppInstance.COMAddIns; foreach (COMAddIn item in addIns) { //Disable Eikon Excel. if (item.ProgId.Trim().Equals("PowerlinkCOMAddIn.COMAddIn")) { item.Connect = false; comAddIn = item; } } }
private word.Application createWord() { word.Application app = new word.Application(); app.Visible = true; Thread.Sleep(2000); //disable the pdw plugin COMAddIn pdwAddin = null; COMAddIns addins = app.COMAddIns; foreach (COMAddIn addin in addins) { if (addin.Description.Equals("Pdw")) { addin.Connect = false; pdwAddin = addin; break; } } Thread.Sleep(1000); return(app); }
private void button8_Click(object sender, EventArgs e) { word.Application app = new word.Application(); app.Visible = true; Thread.Sleep(2000); //disable the pdw plugin COMAddIn pdwAddin = null; COMAddIns addins = app.COMAddIns; foreach (COMAddIn addin in addins) { if (addin.Description.Equals("Pdw")) { addin.Connect = false; pdwAddin = addin; break; } } Thread.Sleep(1000); string tempFile = textBox_pdw.Text; string wordFile = tempFile.Split('.')[0] + ".docx"; File.Copy(tempFile, wordFile, true); word.Document doc = app.Documents.Open(wordFile); //change properties of document //foreach (DocumentProperty docPro in doc.CustomDocumentProperties) //{ // if (docPro.Name.StartsWith("Pronto_ImportedExcelFileName")) // { // docPro.Value = textBox_pdwpder.Text; // } //} //remove pde template and add pder file. PdeContent pdeImported = null; string xsl = null; foreach (CustomXMLPart xmlPart in doc.CustomXMLParts) { if (xmlPart.BuiltIn) { continue; } XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(xmlPart.XML); if (customObject.ContentType == ContentType.ImportedPde) { pdeImported = ObjectSerializeHelper.Deserialize <PdeContent>(customObject.Content); } else if (customObject.ContentType == ContentType.Xslt) { xsl = customObject.Content; } xmlPart.Delete(); } //add pder file CustomXMLPart xmlPart_pder = doc.CustomXMLParts.Add(); pdeImported.FileContent = FileHelper.ExcelToBase64(textBox_pdwpder.Text); //pdeImported.FullFileName = textBox_pdwpder.Text; XmlObject pderObj = new XmlObject(); pderObj.ContentType = ContentType.ImportedPde; pderObj.Content = ObjectSerializeHelper.SerializeToString <PdeContent>(pdeImported); xmlPart_pder.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(pderObj)); //add xml data file XmlDocument dataXml = new XmlDocument(); dataXml.Load(textBox_pdwd.Text); XmlObject pdwrXml = new XmlObject(dataXml.InnerXml, ContentType.PdwrXml); CustomXMLPart xmlPart_xml = doc.CustomXMLParts.Add(); xmlPart_xml.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(pdwrXml)); //add xsl file XmlObject xslObj = new XmlObject(); xslObj.ContentType = ContentType.PdwrXsl; xslObj.Content = xsl; CustomXMLPart xmlpart_xsl = doc.CustomXMLParts.Add(); xmlpart_xsl.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(xslObj)); //add pdwr setting XmlObject settObj = new XmlObject(); settObj.ContentType = ContentType.PdwrSettings; settObj.Content = "<?xml version=\"1.0\" encoding=\"utf-16\"?><RenderSettings xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Media>Docx</Media><Channel>Display</Channel></RenderSettings>"; CustomXMLPart xmlpart_sett = doc.CustomXMLParts.Add(); xmlpart_sett.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(settObj)); doc.Save(); doc.Close(); pdwAddin.Connect = true; app.Quit(); File.Copy(wordFile, wordFile.Split('.')[0] + ".pdwr", true); MessageBox.Show("Create pdwr file success."); }