私は Java 開発者です。しかし、何らかの理由で、自分のタスクを達成するために C# の助けを借りなければなりません。以下に、DLL の作成に使用される C# コードについて説明しました。その DLL は、必要な処理を行うために 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;
}
}
}
}
私はこのフォーラムと他のフォーラムもチェックしましたが、それらのほとんどは、JNI 呼び出しで C++ または C DLL ファイルを使用することについて話しています。Java から C# DLL を呼び出す方法を知っている人がいたら教えてください。