2016-05-30 6 views
-1

私は、ステガノグラフィのワードシフトコーディングプロトコルを、Javaアプリケーションを使用してMicrosoft Wordレポートに実装しようとしています。基本的には、既存のレポートを使用し、スペースを編集していくつかの秘密のデータを入れます。幅が広い場合は、1ビットのデータです。それが狭ければ、それは0ビットのデータです。だから私はどのような種類のライブラリが私はこのJavaアプリケーションを構築し始める必要がありますか、またはjavaはこの種のコミニケーションをms-wordでサポートしていないのでしょうか?JavaアプリケーションからMicrosoftウィンドウ間隔を編集するにはどうすればよいですか?

答えて

1

C#とMicrosoft.Office.Interop.Wordをお勧めします。無料のVisual Studioコミュニティバージョン(https://www.visualstudio.com/products/visual-studio-community-vs)を使用して、コンソールアプリケーションを作成し、interop名前空間の参照を追加することができます(プロジェクトエクスプローラで、参照を右クリックし、参照:COM-> Microsoft Word 16.0 Object Libraryを追加します)。

簡単な例:

namespace WordShiftingExample 
{ 
    class Program 
    { 

     private static int[] getSpaces(string text) 
     { 
      System.Collections.ArrayList list = new System.Collections.ArrayList(); 
      int index = 0; 

      while (index != text.LastIndexOf(" ")) 
      { 
       index = text.IndexOf(" ", index + 1); 
       list.Add(index); 
      } 
      return list.ToArray(typeof(int)) as int[]; 
     } 

     static void Main(string[] args) 
     { 
      try 
      { 
       Microsoft.Office.Interop.Word.Application winword = new Microsoft.Office.Interop.Word.Application(); 
       winword.ShowAnimation = false; 
       winword.Visible = false; 
       object missing = System.Reflection.Missing.Value; 

       Microsoft.Office.Interop.Word.Document document = winword.Documents.Add(ref missing, ref missing, ref missing, ref missing); 

       float zero = 0.1F; 
       float one = 0.15F; 

       document.Content.Text = "This is a test document."; 

       //set word-spacing for first two spaces 
       int[] spaces = getSpaces(document.Content.Text); 

       document.Range(spaces[0], spaces[0]+1).Font.Spacing=zero; 
       document.Range(spaces[1], spaces[1]+1).Font.Spacing = one; 

       //read word-spacing for first two spaces 
       System.Diagnostics.Debug.WriteLine(document.Range(spaces[0], spaces[0]+1).Font.Spacing); // prints 0.1 
       System.Diagnostics.Debug.WriteLine(document.Range(spaces[1], spaces[1]+1).Font.Spacing); // prints 0.15 

       //Save the document 
       object filename = System.Environment.GetEnvironmentVariable("USERPROFILE")+"\\temp1.docx"; 
       document.SaveAs2(ref filename); 
       document.Close(ref missing, ref missing, ref missing); 
       document = null; 
       winword.Quit(ref missing, ref missing, ref missing); 
       winword = null; 
      } 
      catch (Exception ex) 
      { 
       System.Diagnostics.Debug.WriteLine(ex.StackTrace); 
      } 
     } 
    } 
} 
関連する問題