Hallo liebe Community.
Ich habe eine kurze Frage.
Ich bin gerade dabei die Daten von einer C# dataGridView in eine Word Tabelle zu exportieren,
bekomme es aber irgendwie nicht richtig hin.
Hier mein jetziger Code:
Code
private void BefuelleTable()
{
var word = new Word.Application();
word.Visible = true;
var wdDoc = word.Documents.Open(this.TXT_WDATEI.Text);
Word.Table wdTab = wdDoc.Tables[1];
object beforeRow = wdDoc.Tables[1].Rows[1];
int nRow = dataGridView1.Rows.Count;
int nCol = dataGridView1.Columns.Count;
for (int a = 2; a <= nRow; a++) // Links nach rechts
{
wdDoc.Tables[1].Rows.Add(ref beforeRow);
}
wdTab.Cell(1, 1).Range.Text = "PC";
wdTab.Cell(1, 2).Range.Text = "Computername";
wdTab.Cell(1, 3).Range.Text = "IP Adresse";
for (int i = 2; i <= nRow; i++)
{
for (int j = 1; j <= nCol; j++)
{
string strText = (string)dataGridView1.Rows[i].Cells[j].Value;
wdTab.Cell(i, j).Range.Text = strText;
}
}
}
Alles anzeigen
Ich hoffe das mir irgendjemand helfen kann.