如何用c#导出一个access数据库里的多张表到EXCEL?
如题,现在我能导出一个数据库里一张表到excel,但是我不知道如果导出里面的多张表环境:工具vs 2005
语言 C#
数据库 access
导出格式xls
private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Access.ApplicationClass oAccess = new Microsoft.Office.Interop.Access.ApplicationClass();
oAccess.Visible = false;
try
{
//ACCESS9:
oAccess.OpenCurrentDatabase("C:\\费用申请.mdb", false, "");
//导出到excel
oAccess.DoCmd.TransferSpreadsheet(Microsoft.Office.Interop.Access.AcDataTransferType.acExport, Microsoft.Office.Interop.Access.AcSpreadSheetType.acSpreadsheetTypeExcel9, "Sheet1", "d:\\费用申请.xls", true, null, null);
//导入txt
// oAccess.DoCmd.TransferText(Access.AcTextTransferType.acExportDelim,"","Enterprise","d:\\wcf.txt",true,"",0);
oAccess.CloseCurrentDatabase();
oAccess.DoCmd.Quit(Microsoft.Office.Interop.Access.AcQuitOption.acQuitSaveNone);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccess);
oAccess = null;
MessageBox.Show("导出成功");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
GC.Collect();
}
}
费用申请.mdb有Sheet1~sheet5 五张表 现在想全部导出到excel里 --------------------编程问答-------------------- 获取access表结构,遍历添加多sheet导出数据
GetOleDbSchemaTable --------------------编程问答-------------------- 即然你可以用oAccess.DoCmd,你应该在Access定义一个宏,去导出相应的数据.
然后用DoCmd执行宏
补充:.NET技术 , C#