Hello,
I am writing a little application which uses a template excel file and
adds some information and then stores the changed file.
The problem is, i don't really know how to add these rows - row by
row. I can insert a range, but when I insert a range the data that is
written below that isn't shifted down like I ment it would/should.
Here is some sample code:
object[,] objData = new Object[strColumns.Length,1];
for (int i = 0; i < strColumns.Length; i++)
{
DataColumnCollection dcc =
myDataSet.AM.Columns;
foreach (DataColumn dc in dcc)
{
if (dc.ColumnName == strColumns[i])
{
objData[i, 0] = "A: " + strColumns[i]
+ " " +
myAMRow.ItemArray[myDataSet.AM.Columns.IndexOf(dc.ColumnName)];
}
}
}
m_objRange = myOverviewWorksheet.get_Range("C" +
(iZeile1+3).ToString(), "C" +
(iZeile1+3+strColumns.Length).ToString());
m_objRange =
m_objRange.get_Resize(strColumns.Length,1);
m_objRange.set_Value(missing, objData);
theWorkbook.SaveAs(strFilePath + "\\" +
myRow.PRONAME + "_" + myAMRow.APNUMMER, missing, missing,
missing, missing, missing, Excel.XlSaveAsAccessMode.xlNoChange,
missing, missing, missing, missing, missing);
theWorkbook.Close(false, missing, missing);
ExcelObj.Quit();
but what I actually want it something like that:
for (int i = 0; i < strColumns.Length; i++)
{
DataColumnCollection dcc =
myDataSet.AM.Columns;
foreach (DataColumn dc in dcc)
{
if (dc.ColumnName == strColumns[i])
{
// insert 3 rows into the worksheet
// row1: A: dc.ColumnName
// row2: myAMRow.column
// row3:
myOverviewWorksheet.insert(rows,
shift down);
}
}
}
theWorkbook.SaveAs(strFilePath + "\\" +
myRow.PRONAME + "_" + myAMRow.APNUMMER, missing, missing,
missing, missing, missing, Excel.XlSaveAsAccessMode.xlNoChange,
missing, missing, missing, missing, missing);
theWorkbook.Close(false, missing, missing);
ExcelObj.Quit();
but somehow I can't get that idea running!!
help, please ;-)
Greetings
Chris