
然后,我们点击root打开之后,单击core_db,在展开的选项中可以看到表。
我们点击“表”后可以看到数据库中的所有表,我们右击表d出的选项中有一个“导出向导”
我们点击导出向导就会d出导出的页面,第一个页面提示我们要使用哪一种导出格式。因为我们是导出到EXCEL表中,所以选择导出的格式为.xls,然后单击“下一步”
第二个小步骤中,我们需要勾选需要导出的表,并设置导出文件所在位置,然后点击下一步
我们可以选择需要导出的表中的哪些数据,默认的是全部栏位。选好之后,单击下一步。
点击下一步之后,我们再次点击下一步,然后点击d出的窗口的右下角的“开始”按钮,就开始导出了。
导出之后,会继续提示我们已经导出成功,然后我们只需要点击关闭按钮,在相应的位置寻找excel表格即可。打开之后就会看到之前在数据库中存储的数据。
以下都只是介绍 *** 作的原理,具体要求要在应用中具体分析改变。1. 此方法常用在form或者Console Application中,使用时须用要添加Reference,具体做法:
右键点击项目添加“Add Reference”,在Tom组件下,选择“Microsoft Excel 14.0 Object Library”,然后在项目中使用
下面注释//it looks like excele table start with 1 not 1
应该为//it looks like excele table start with 1 not 0
[csharp] view plaincopy
private static void exportToExcel(DataTable dt)
{
Excel.Application excel=new Excel.Application()
excel.Application.Workbooks.Add(true)
excel.Visible = true
//get the columns
for (int i = 0i <dt.Columns.Counti++ )
{
//here is started with 1
//it looks like excele table start with 1 not 1
excel.Cells[1, i + 1] = dt.Columns[i].ColumnName.ToString()
}
//get the data in rows
for (int row = 0row <dt.Rows.Countrow++ )
{
for (int col = 0col <dt.Columns.Countcol++)
{
excel.Cells[row+2, col+1] = dt.Rows[row][dt.Columns[col]].ToString()
}
}
//FolderBrowserDialog path = new FolderBrowserDialog()//打开文件对话框
//path.ShowDialog()
//textBox1.Text = path.SelectedPath//选择文件夹
//save excel
//excel.SaveWorkspace()
excel.Quit()
}
2. 在web应用中,可通过HttpContext.Response.write()来实现
[csharp] view plaincopy
protected static void toExcel(DataTable da){
System.Web.HttpContext context = System.Web.HttpContext.Current
context.Response.Clear()
foreach( DataColumn colum in da.Columns){
context.Response.Write(colum.ColumnName+"\t")
}
context.Response.Write(System.Environment.NewLine)
foreach (DataRow row in da.Rows) {
for (int i = 0i <da.Rows.Counti++)
{
context.Response.Write(row[i].ToString()+"\t")
}
context.Response.Write(System.Environment.NewLine)
}
context.Response.ContentType = "application/vnd.ms-excel"
context.Response.AppendHeader("Content-Disposition", "attachmentfilename=plan.xls")
context.Response.End()
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)