0

Microsoft Office 相互運用機能を使用して Word 文書を作成しようとしています。ドキュメントには、画像と下の表の内容が含まれている必要があります。しかし、コンテンツを追加すると、必要な方法で追加されません。

以下にサンプルコードを用意しました。

MSWord.Application oWordApp;
MSWord.Document oWordDoc;
oWordApp = new MSWord.Application();
oWordApp.Visible = true;
oWordApp.WindowState = MSWord.WdWindowState.wdWindowStateMinimize;
oWordDoc = oWordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

object start = 0;
object end = 0;

Microsoft.Office.Interop.Word.Range oRange = oWordDoc.Range(ref start,ref end);

oWordDoc.InlineShapes.AddPicture(imagepath, ref oMissing, ref oMissing, oRange);

Microsoft.Office.Interop.Word.Table tbl = oWordDoc.Tables.Add(oRange, 10, 2, ref oMissing, ref oMissing);
Random rnd = new Random();
for (int i = 0; i < 10; i++)
{
    tbl.Rows[i + 1].Cells[1].Range.Text = "Item#";
    tbl.Rows[i + 1].Cells[2].Range.Text = "Sample";
}

oWordDoc.SaveAs(svd.FileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                            ref oMissing, ref oMissing, ref oMissing, ref oMissing);
4

1 に答える 1

1

差し込み印刷は試しましたか?このようにして、単語テンプレートを設定し、画像と表を好きなように配置できます。次に、入力フィールドをテンプレートとマージすることだけを心配する必要があります。このようにして、必要に応じて、さまざまな Word 文書用に複数のテンプレートを作成できます。次に例を示します。

Microsoft Word 2010 の差し込み印刷フィールドにテキストを送信する

于 2012-09-11T10:07:49.827 に答える