Soy un desarrollador de Java. Pero, por alguna razón, tengo que tomar la ayuda de C# para llevar a cabo mi tarea. He mencionado el código C# que se utiliza para crear una DLL. Esa DLL debe ser utilizada en mi programa Java para hacer lo necesario.Llamando a C# dll desde Java
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;
namespace Yrl.Tracingtool
{
public class DocxUtil
{
public Application Jump(string fileName)
{
object fileNameAsObject = (object)fileName;
Application wordApplication;
try
{
wordApplication = new Application();
object readnly = false;
object missing = System.Reflection.Missing.Value;
wordApplication.Documents.Open(ref fileNameAsObject, ref missing, ref readnly, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing);
object what = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage;
object which = Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToFirst;
object count = 3;
wordApplication.Selection.GoTo(ref what, ref which, ref count, ref missing);
return wordApplication;
}
catch (Exception ex)
{
//LogEntry log = new LogEntry();
//log.Categories.Add("Trace");
//log.Message = ex.ToString();
//Logger.Write(log, "Trace");
throw new System.IO.FileLoadException("File cannot be opened");
}
finally
{
wordApplication = null;
}
}
}
}
He comprobado este foro y en otros foros también, pero la mayoría de ellos hablar sobre el uso de un C++ o archivo DLL C en una llamada JNI. Si alguien tiene conocimiento de llamar a C# DLL desde Java, por favor avíseme.
creo que tendría que utilizar COM? ¿Puede estar mal? – Liam
@duffymo No lo creo. Ese artículo no tiene ninguna información sobre C# DLL. – rajshekhar
Existe una API de Java para el proyecto de Microsoft Documents en Apache, [Apache POI] (http://poi.apache.org/). ¿Podría ser esta una alternativa para mezclar Java y C#? (Por supuesto, no tengo experiencia en el uso de _Apache POI_). –