我正在使用c#编程语言将数据集导出到现有的Excel工作表。因此,我需要指定要插入的数据的确切列和行(列G,行3)。请注意,数据集只有1列。我已经提到了我正在使用的编码。但它没有将数据集传递到我需要的位置。请帮忙
dt = compareDataTables(Oracle, MIT);
dataGridView1.DataSource = dt;
//inserting to Excel file
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(textBox1.Text, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
int i = 0;
int j = 0;
for (i = 0; i <= dataGridView1.RowCount - 1; i++)
{
for (j = 0; j <= dataGridView1.ColumnCount - 1; j++)
{
DataGridViewCell cell = dataGridView1[j, i];
xlWorkSheet.Cells["3", "G"] = cell.Value;
}
}
xlWorkBook.Save();
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
答案 0 :(得分:0)
为什么xlWorkSheet.Cells [“3”,“G”]是硬编码的?它每次都在写数据