for (int i = 1; i <= ViewData.Rows.Count / 65536 + 1; i++)
{
xlworkSheet = (Excel.Worksheet)xlworkBook.Worksheets.get_Item(i);
range = null;
range = xlworkSheet.get_Range("A1", misValue);
range = range.get_Resize(DS.Tables[0].Rows.Count,DS.Tables[0].Columns.Count);
if (65536 * i < DS.Tables[0].Rows.Count)
{
if (i <= 1)
{
for (RRow = RRow; RRow <= 65536 * i - 1; ++RRow)
{
for (int RColm = 0; RColm < ViewData.Cols.Count-1; RColm++)
{
tempArray[RRow, RColm] = DS.Tables[0].Rows[RRow].ItemArray[RColm].ToString();
}
}
range.set_Value(System.Reflection.Missing.Value, tempArray);
Array.Clear(tempArray, 0, tempArray.Length);
tempArray = new string[ViewData.Rows.Count, ViewData.Cols.Count];
}
else
{
int tempRow = 0;
for (RRow = RRow; RRow < ViewData.Rows.Count - 1; ++RRow)
{
for (int RColm = 0; RColm < ViewData.Cols.Count - 1; RColm++)
{
tempArray[tempRow, RColm] = DS.Tables[0].Rows[RRow].ItemArray[RColm].ToString();
}
tempRow++;
}
range.set_Value(System.Reflection.Missing.Value, tempArray);
}
}
else
{
int tempRow = 0;
for (RRow = RRow; RRow < ViewData.Rows.Count - 1; ++RRow)
{
for (int RColm = 0; RColm < ViewData.Cols.Count - 1; RColm++)
{
tempArray[tempRow, RColm] = DS.Tables[0].Rows[RRow].ItemArray[RColm].ToString();
}
tempRow++;
}
range.set_Value(System.Reflection.Missing.Value, tempArray);
xlworkBook.SaveAs("Myfile.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
}
}
xlApp.UserControl = true;
Process pro = Process.Start("myfilepath");
//this is the logic,I have created and success to make.We can do some better from user point of view