謝罪。私はStackOverflowを初めて使用していて、コード例でどのように対応するのか分からなかった。以下のコードは、データグリッドビューのテーブルからすべての行をマージフィールドを持つワードドキュメントにエクスポートするためのコードです。現時点では、以下のコードはドキュメント内の最初の行のみを繰り返し、残りの行は表示しません。誰かがこれを書いた方法では不可能かもしれないと言いました。私はそれがどうなるか知っている。DataGridViewの行をWordテンプレートにエクスポート/マージする
ます。private void btnMerge_Click(オブジェクト送信者、EventArgsの電子) {
var application = new Microsoft.Office.Interop.Word.Application();
var document = new Microsoft.Office.Interop.Word.Document();
document = application.Documents.Add(Template: @"C:\Users\euan\documents\agreementtemplate.docx");
application.Visible = true;
for (int i = 0; i < gvCurrentAgreements.Rows.Count; i++)
{
var griddescripton = gvCurrentAgreements.Rows[i].Cells[2].Value.ToString();
var gridprice = gvCurrentAgreements.Rows[i].Cells[4].Value.ToString();
var gridquantity = Convert.ToString(gvCurrentAgreements.Rows[i].Cells[3].Value);
foreach (Microsoft.Office.Interop.Word.Field field in document.Fields)
if (field.Code.Text.Contains("Description"))
{
field.Select();
application.Selection.TypeText(griddescripton);
}
else if (field.Code.Text.Contains("Price"))
{
field.Select();
application.Selection.TypeText(gridprice);
}
else if (field.Code.Text.Contains("Quanitity"))
{
field.Select();
application.Selection.TypeText(gridquantity.ToString());
}
}
}
そして、正確に、あなたの質問は何ですが?質問の下にある[編集]リンクを使用してANDを追加し、コードブロックをコードブロックとして読み取れるように修正してください。 –