C#のコードからの自動化を使用して作成しているWord文書にマージンを設定したいと思います。
を使用してプロセスを開始しましたがActiveDocument.TopMargin =
、vbに類似したC#コードが見つかりません。Word.InchesToPoint(.5)
助けていただければ幸いです。
C#のコードからの自動化を使用して作成しているWord文書にマージンを設定したいと思います。
を使用してプロセスを開始しましたがActiveDocument.TopMargin =
、vbに類似したC#コードが見つかりません。Word.InchesToPoint(.5)
助けていただければ幸いです。
時には最も簡単な方法が機能します。このコード行は問題を解決しました
oWord.ActiveDocument.PageSetup.TopMargin = (float)50;
Wordアプリケーションのインスタンスを取得する必要があります。
Word.Application oWord = new Word.Application();
oWord.InchesToPoint((float)0.5);
リファレンスを参照してください:http: //msdn.microsoft.com/en-us/library/ff197549.aspx
次のように、Word Application オブジェクトの InchesToPoints メソッドを使用できます。
Word.Application wrdApplication = new Word.Application();
Word.Document wrdDocument;
wrdApplication.Visible = true;
wrdDocument = wrdApplication.Documents.Add();
wrdDocument.PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape;
wrdDocument.PageSetup.TopMargin = wrdApplication.InchesToPoints(0.5f);
wrdDocument.PageSetup.BottomMargin = wrdApplication.InchesToPoints(0.5f);
wrdDocument.PageSetup.LeftMargin = wrdApplication.InchesToPoints(0.5f);
wrdDocument.PageSetup.RightMargin = wrdApplication.InchesToPoints(0.5f);
または、必要に応じて、自分で作成することもできます...
private float InchesToPoints(float fInches)
{
return fInches * 72.0f;
}
次のような場合に使用できます。
Word.Application wrdApplication = new Word.Application();
Word.Document wrdDocument;
wrdDocument = wrdApplication.Documents.Add();
wrdDocument.PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape;
wrdDocument.PageSetup.TopMargin = InchesToPoints(0.5f); //half an inch in points
wrdDocument.PageSetup.BottomMargin = InchesToPoints(0.5f);
wrdDocument.PageSetup.LeftMargin = InchesToPoints(0.5f);
wrdDocument.PageSetup.RightMargin = InchesToPoints(0.5f);
wrdApplication.Visible = true;
Word は、その間隔で 1 インチあたり 72 ポイントを使用します。