











































stringBuffer.Append((string)ds.Tables[i].Rows[j][k]);
if( k < ds.Tables[i].Columns.Count - 1 )
stringBuffer.Append("/t");
}
stringBuffer.Append("/n");
}
// 利用系统剪切板
System.Windows.Forms.Clipboard.SetDataObject("");
// 将stringBuffer放入剪切板
System.Windows.Forms.Clipboard.SetDataObject(stringBuffer);
// 选中这个sheet页中的第一个单元格(下标从1开始)
((Excel.Range)xlWorksheet.Cells[1,1]).Select();
// 将剪切板里的内容粘贴在Sheet中
xlWorksheet.Paste(oMissing,oMissing);
// 清空系统剪切板
System.Windows.Forms.Clipboard.SetDataObject("");
}
// 保存并关闭这个工作簿
xlWorkbook.Close( Excel.XlSaveAction.xlSaveChanges, oMissing, oMissing );
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkbook);
xlWorkbook = null;
}
catch(Exception ex)

...{
MessageBox.Show(ex.Message);
}
finally

...{
// 释放COM对象
xlApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
GC.Collect();
}
}







































