Yes, we have a .Net Gateway configured, and we have imported the .Net dll through the Studio wizard.
We have activated gateway log, but it doesn't say anything.
From an Ensemble Bussiness Operation we call the .Net method. The code is this:
Class bo.GenerarWord Extends EnsLib.DotNetGateway.AbstractOperation
{
Parameter INVOCATION = "Queue";
Method generarDocumento(pRequest As msg.WordRequest, Output pResponse As msg.WordResponse) As %Status
{
#dim sc as %status
#dim gateway as %Net.Remote.Gateway
set pResponse = ##class(msg.WordResponse).%New()
set sc = ..GetConnection(.gateway)
if $$$ISERR(sc){
set pResponse.mensaje = "Error ("_sc_"):"_$System.Status.GetErrorText(sc)
}else{
#dim ce as cysnet.MiClase.entity.ControlError
#dim we as cysnet.MiClase.entity.WordEntity
#dim plantilla as %String
#dim documento as %String
set ce = ##class(cysnet.MiClase.entity.ControlError).%New(gateway)
set we = ##class(cysnet.MiClase.entity.WordEntity).%New(gateway)
set plantilla = "C:\InterSystems\Ensemble\mgr\DLLWORDENS2\dlls\PlantillaTuneada.doc"
set documento = "C:\InterSystems\Ensemble\mgr\DLLWORDENS2\dlls\"
//set we.setuTitulo = "TITULO_ENS"
do dao.EscribirWord(ce,plantilla,documento,we,"PRUEBA_ENS")
$$$LOGINFO(ce.getuDebbug())
}
set pResponse.mensaje = "OK"
Quit $$$OK
}
XData MessageMap
{
<MapItems>
<MapItem MessageType="msg.WordRequest">
<Method>generarDocumento</Method>
</MapItem>
</MapItems>
}
The .Net code is this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using cysnet.MiClase.entity;
using System.IO;
using Microsoft.Office.Interop.Word;
namespace cysnet.MiClase
{
public class MiClase
{
public String EscribirWord(ControlError ce, String fullPathPlantilla, String pathDocumento, WordEntity we, String numDocumento)
{
if (ce == null)
{
ce = new ControlError();
}
ce.Reset();
ce.Debbug = fullPathPlantilla + " || " + pathDocumento + " || " + numDocumento + " || ";
ce.Debbug += " Iniciando método";
String resultado = "";
Application MSWord = new Application();
Document documento;
try
{
object oMissing = System.Reflection.Missing.Value;
ce.Debbug += "RUTA DEL NUEVO DOCUMENTO:"+ pathDocumento + numDocumento +".docx";
documento = MSWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
ce.Debbug += " Abriendo plantilla Word";
//Abrir Palntilla
documento = MSWord.Documents.Open(fullPathPlantilla);
ce.Debbug += " Escribiendo en marcadores";
//Editar marcadores
documento.Bookmarks["Titulo"].Range.Text = we.Titulo;
ce.Debbug += " Guardando documento Word";
//Guardar copia de la plantilla como documento
documento.SaveAs(pathDocumento+numDocumento+".dot");
ce.Debbug += " Cerrando documento Word";
//Cerrar documento
documento.Close();
ce.Debbug += " Operación realizada con éxito";
}
catch (Exception e)
{
ce.MessageError = e.Message;
ce.IsError = true;
}
finally
{
ce.Debbug += " Cerrando aplicación MsWord";
//Cerrar la aplicación
MSWord.Quit();
}
return resultado;
}
}
}
I have cleaned it a bit to be more legible. It has comments in spanish. I hope it doesn't matter.
- Log in to post comments