写入数据库是msdn的例子,应该不会错误读出重新生成文件为什么错误呢?帮忙谢谢
解决方案 »
- 关于登录问题;
- c#里如何分行写代码
- 类库中调用web srevice
- 乐观锁中使用的version是否应该传递到前台?
- Membership应用问题
- 欲寻找了解.NET Remoting的高手
- 表格被字母给撑大了怎么办?
- 请问在asp.net页面中如何在客户端获取客户端的时间?
- 谁能告诉我这是什么原因??????????????
- 大家帮忙,我在写测试代码,不知道怎么写,没接触过!SoapClientMessage and SoapServerMessage
- 如何往oracle中写入blob型数据
- 我想把一个日期字符串:2004-5-7 12:10:18 转换成:2004-5-7,去掉后面的时间 怎么实现呀?
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using JBInfoBase;
using Excel;
namespace JBInfoManage._2052.ASPX.ClassManage
{
/// <summary>
/// ClassExportExcel 的摘要说明。
/// </summary>
public class ClassExportExcel : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(this.Request.QueryString["ClassGuid"]!=null)
{
JBInfoBase.SingMems pSM=new JBInfoBase.SingMems();
string pFileName=this.Request.QueryString["ClassName"].ToString();
System.Data.DataTable pDateTable=pSM.SearchExcelDate(this.Request.QueryString["ClassGuid"].ToString().Trim());
HttpResponse rsp;
rsp=Page.Response;
rsp.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//乱码问题
rsp.AppendHeader("Content-Disposition", "attachment;filename="+pFileName ); //'必要,做成下载文件 Excel.Application oExcel=null;
Excel.Workbook oBook;
Object oMissing=System.Reflection.Missing.Value ;
oExcel=new Excel.Application();
oBook=oExcel.Workbooks.Add(oMissing);
int rows;
int clumns;
// System.Globalization.CultureInfo pa=new System.Globalization.CultureInfo("zh-CHS");
//
// System.Globalization.NumberFormatInfo pN=new System.Globalization.NumberFormatInfo();
rows=pDateTable.Rows.Count-1;
clumns=pDateTable.Columns.Count-1;
for(int i=0;i<=rows;i++)
{
// oExcel.get_Range(oExcel.Cells[i,6],oExcel.Cells[i+1,6]).ClearFormats();
for(int j=0;j<=clumns;j++)
{
if(i==0)
{
oExcel.Cells[1,j+1]=pDateTable.Columns[j].ColumnName.ToString();
}
oExcel.Cells[i+2,j+1]=pDateTable.Rows[i][j].ToString();
}
}
oBook.Saved=true;
oExcel.UserControl=false;
string file=Server.MapPath(".")+"\\" + pFileName;//Server.MapPath(".")服务器保存地址
oExcel.ActiveWorkbook.SaveCopyAs(file);
//oExcel.Quit();
rsp.WriteFile(file);
oExcel.Quit();
oExcel=null;
// rsp.Flush();
// rsp.End();
//JBInfoBase.MakeExcel pME=new JBInfoBase.MakeExcel();
//pME.GenerateFile(this.Page,this.Request.QueryString["ClassName"].ToString(),pDT);
}
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
fs.Write(fsdata,0,len);
就可以了