我是一个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的知识,请让我知道。