2

C#のコードからの自動化を使用して作成しているWord文書にマージンを設定したいと思います。

を使用してプロセスを開始しましたがActiveDocument.TopMargin =、vbに類似したC#コードが見つかりません。Word.InchesToPoint(.5) 助けていただければ幸いです。

4

3 に答える 3

8

時には最も簡単な方法が機能します。このコード行は問題を解決しました

oWord.ActiveDocument.PageSetup.TopMargin = (float)50;
于 2012-01-18T02:25:50.213 に答える
3

Wordアプリケーションのインスタンスを取得する必要があります。

Word.Application oWord = new Word.Application();
oWord.InchesToPoint((float)0.5);

リファレンスを参照してください:http: //msdn.microsoft.com/en-us/library/ff197549.aspx

于 2012-01-17T02:50:44.790 に答える
1

次のように、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 ポイントを使用します。

于 2016-03-03T20:19:10.170 に答える