我从数据库去出数据后,想以excel文件的格式显示在页面,但是没有成功,请教各位?
解决方案 »
- 高手帮帮忙!当前提供程序不支持从单一执行返回多个记录集。
- 关于使用AJAX,后台处理并发问题??
- 一个比较别扭的问题,关于数据显示的。。。。。。。。。。。。。。。。。。
- ××××××××××××××高分求一正则表达式××××××××××××
- VISUAL 2005可以使用SQL 2000的数据库吗?
- 我取不到node的父节点,该怎么取?有思路也可以。急!
- jquery请求ashx出现错误提示,状态是200,莫明其妙
- TreeView控件选中节点样式的问题
- 轻松得分
- 取用户控件属性的问题
- 还是动态绑定dropdownlist控件问题的问题,,,大侠帮我啊!!!!!!!!!!!!!!!!!
- 页面上有一个小三角,点击这个展载页面,再点合上这个页面,大家知道是怎么做出来的吗?有点类似于CSDN的导航条
private void doExport(DataSet ds)
{
DateTime begin=DateTime.Now;
Excel.Application excel= new Excel.Application();
DateTime end=DateTime.Now;
int rowIndex=1;
int colIndex=0;
excel.Application.Workbooks.Add(true);
System.Data.DataTable table=ds.Tables[0] ;
foreach(DataColumn col in table.Columns)
{
colIndex++;
excel.Cells[1,colIndex]=col.ColumnName;
} foreach(DataRow row in table.Rows)
{
rowIndex++;
colIndex=0;
foreach(DataColumn col in table.Columns)
{
colIndex++;
excel.Cells[rowIndex,colIndex]=row[col.ColumnName].ToString();
}
}
excel.Visible=true;
Process[] myProcesses;
myProcesses = Process.GetProcessesByName("EXCEL");
foreach(Process myProcess in myProcesses)
{
DateTime startTime = myProcess.StartTime; if(startTime > begin && startTime < end)
{
myProcess.Kill();
}
}
}
response.Clear();
response.WriteFile(strFilePath);
response.ContentType = "application/octet-stream";
string httpHeader="inline;filename=backup.Xls";
//filename=backup.Xls";
response.AppendHeader("Content-Disposition", httpHeader );
response.Flush();
//System.IO.File.Delete(path + fileName);
response.End();
加上这句
没有一个实际的路竟啊!
Dim sr As System.IO.BinaryReader
Dim b() As Byte f = New System.IO.FileStream(Server.MapPath("1.xls"), IO.FileMode.OpenOrCreate, IO.FileAccess.ReadWrite)
sr = New System.IO.BinaryReader(f, System.Text.Encoding.Default)
b = sr.ReadBytes(f.Length)
sr.Close()
Response.ContentType = "Application/octet-stream"
Response.Clear()
Response.AddHeader("Content-Disposition", "filename = 1.xls")
Response.BinaryWrite(b)
Response.End()
<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name=GENERATOR>
<meta content="Visual Basic .NET 7.1" name=CODE_LANGUAGE>
<meta content=JavaScript name=vs_defaultClientScript>
<meta content=http://schemas.microsoft.com/intellisense/ie5 name=vs_targetSchema>
</HEAD>
<body>
<form id=Form1 method=post runat="server"><asp:button id=Button1 runat="server" Text="Button"></asp:Button><asp:datagrid id=DataGrid1 runat="server"></asp:DataGrid></FORM>
</body>
</HTML>
{
string excelFilePath=@"D:\Book1.xls";
Excel.Application myExcel=new Excel.ApplicationClass( ) ;
object oMissing = System.Reflection.Missing.Value ;
myExcel.Application.Workbooks.Open(excelFilePath,oMissing,oMissing,oMissing,oMissing,oMissing, oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing) ;
Excel.Workbook myBook = myExcel.Workbooks[1] ;
Excel.Worksheet mySheet = (Excel.Worksheet)myBook.Worksheets[1] ;
System.Data.DataTable dt=new System.Data.DataTable("rycjsb");
dt.Columns.Add("F1", System.Type.GetType("System.String"));
dt.Columns.Add("F2", System.Type.GetType("System.String"));
dt.Columns.Add("F3", System.Type.GetType("System.String"));
dt.Columns.Add("F4", System.Type.GetType("System.String"));
dt.Columns.Add("F5", System.Type.GetType("System.String"));
DataSet myDs = new DataSet();
myDs.Tables.Add(dt);
DataRow myRow;
myDs.Clear();
for( int i = 2 ; i <= 4 ; i ++ )
{
myRow = myDs.Tables["rycjsb"].NewRow();
for( int j = 1 ; j <= 5 ; j ++ )
{
Excel.Range r=(Excel.Range)mySheet.Cells[i,j];
string strValue=r.Text.ToString();
string aa=strValue;
string columnname="F"+j.ToString();
myRow[columnname]=strValue;
}
myDs.Tables["rycjsb"].Rows.Add(myRow);
}
DataGrid1.DataSource=myDs.Tables["rycjsb"].DefaultView;
DataGrid1.DataBind();
}