- ·上一篇教育:excel表格在线模板怎么去掉
- ·下一篇教育:excel表格怎么自定义组合键
excel表格怎么导出当前代码
1..net 求助关于 导出excel方法的修改 谢谢~!有代码
具体版本问题我还是不清楚,不过你代码的确一点不够规范,
public void CreateExcel(DataSet ds,string typeid,string FileName)
{
HttpResponse resp;
resp = Page.Response;
resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
resp.AppendHeader("Content-Disposition", "attachment;filename=" + FileName);
string colHeaders= "", ls_item="";
int i=0;
//定义表对象与行对像,同时用DataSet对其值进行初始化
DataTable dt=ds.Tables[0];
DataRow[] myRow=dt.Select("");
// typeid=="1"时导出为EXCEL格式文件;typeid=="2"时导出为XML格式文件
if(typeid=="1")
{
//取得数据表各列标题,各标题之间以\t分割,最后一个列标题后加回车符
for(i=0;icolHeaders+=dt.Columns[i].Caption.ToString()+"\t";
colHeaders +=dt.Columns[i].Caption.ToString() +"\n";
//向HTTP输出流中写入取得的数据信息
resp.Write(colHeaders);
//逐行处理数据
foreach(DataRow row in myRow)
{
//在当前行中,逐列获得数据,数据之间以\t分割,结束时加回车符\n
for(i=0;ils_item +=row[i].ToString() + "\t";
ls_item += row[i].ToString() +"\n";
//当前行数据写入HTTP输出流,并且置空ls_item以便下行数据
resp.Write(ls_item);
ls_item="";
}
}
else
{
if(typeid=="2")
{
//从DataSet中直接导出XML数据并且写到HTTP输出流中
resp.Write(ds.GetXml());
}
}
//写缓冲区中的数据到HTTP头文件中
resp.End();
}
2.急啊,excel导入导出代码怎么写啊
/*从数据库提取数据*/ string strconn="packet size=4096;user id=sa;data source=localhost;persist security info=True;initial catalog=Database;password=sa"; SqlConnection sqlconn=new SqlConnection(strconn); sqlconn.Open(); SqlDataAdapter sqldataAdapter=new SqlDataAdapter("Select * from [数据表]",sqlconn); DataSet myds=new DataSet(); sqldataAdapter.Fill(myds); /*在Execl中建立“成果表”的格式表格*/ Excel.ApplicationClass excel=new Excel.ApplicationClass(); excel.Application.Workbooks.Add(true); excel.Cells[1,1] = "单元名称" ; excel.Cells[1,2]="指标及其描述、特征值和权重"; excel.Cells[1,23]="属性"; excel.Cells[2,2]="D"; excel.Cells[2,5]="R"; excel.Cells[2,8]="A"; excel.Cells[2,11]="S"; excel.Cells[2,14]="T"; excel.Cells[2,17]="I"; excel.Cells[2,20]="C"; excel.Cells[2,23]="结果"; excel.Cells[2,24]="等级"; excel.Cells[3,2]="描述"; excel.Cells[3,3]="特征值"; excel.Cells[3,4]="权重"; excel.Cells[3,5]="描述"; excel.Cells[3,6]="特征值"; excel.Cells[3,7]="权重"; excel.Cells[3,8]="描述"; excel.Cells[3,9]="特征值"; excel.Cells[3,10]="权重"; excel.Cells[3,11]="描述"; excel.Cells[3,12]="特征值"; excel.Cells[3,13]="权重"; excel.Cells[3,14]="描述"; excel.Cells[3,15]="特征值"; excel.Cells[3,16]="权重"; excel.Cells[3,17]="描述"; excel.Cells[3,18]="特征值"; excel.Cells[3,19]="权重"; excel.Cells[3,20]="描述"; excel.Cells[3,21]="特征值"; excel.Cells[3,22]="权重"; excel.get_Range(excel.Cells[ 1 , 1 ],excel.Cells[ 3 ,1 ]).MergeCells=true; excel.get_Range(excel.Cells[ 1 , 2 ],excel.Cells[ 1 ,22 ]).MergeCells=true; excel.get_Range(excel.Cells[ 1 , 23 ],excel.Cells[ 1 ,24 ]).MergeCells=true; excel.get_Range(excel.Cells[ 2 , 2 ],excel.Cells[ 2 ,4 ]).MergeCells=true; excel.get_Range(excel.Cells[ 2 , 5 ],excel.Cells[ 2 ,7 ]).MergeCells=true; excel.get_Range(excel.Cells[ 2 , 8],excel.Cells[ 2 ,10 ]).MergeCells=true; excel.get_Range(excel.Cells[ 2 ,11 ],excel.Cells[ 2 ,13 ]).MergeCells=true; excel.get_Range(excel.Cells[ 2 , 14 ],excel.Cells[ 2 ,16 ]).MergeCells=true; excel.get_Range(excel.Cells[ 2 , 17 ],excel.Cells[ 2 ,19 ]).MergeCells=true; excel.get_Range(excel.Cells[ 2 , 20 ],excel.Cells[ 2 ,22 ]).MergeCells=true; excel.get_Range(excel.Cells[ 2 , 23 ],excel.Cells[ 3 ,23 ]).MergeCells=true; excel.get_Range(excel.Cells[ 2 , 24 ],excel.Cells[ 3 ,24 ]).MergeCells=true; /*往Excel格式表格中写入数据*/ int waterdataRows=myds.Tables[0].Rows.Count; int waterdataCols=myds.Tables[0].Columns.Count; for(int i=1;i。
3.vb导出excel代码详解
准备工作,引用EXCEL11.0,与一个grid1控件和一个adodc1控件。
'以下为导出EXCEL'以下放到form中去。Adodc1.connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\pmdb.mdb;Persist Security Info=False" '设置数据库路径Adodc1.CommandType = adCmdText '设置记录源Adodc1.RecordSource = "select * from new ORDER BY 好友姓名"Set Grid1.DataSource = Adodc1'以下放到代码框的最前面。
Private Sub toexcel()On Error GoTo aa: Dim i, j As Integer Dim ex As Object Dim exwbook As Object Dim exsheet As Object Set ex = CreateObject("Excel.Application") '创建EXCEL对象 Set exwbook = ex.Workbooks.Add '打开文件 ex.Visible = True Set exsheet = exwbook.Worksheets("sheet1") '设定工作表 For i = 1 To Grid1.Rows For j = 1 To Grid1.Cols - 1 exsheet.Cells(i, j) = Grid1.TextMatrix(i - 1, j) Next j Next iaa:Exit SubEnd Sub'以下放到一个导出按钮上去就行了。Call toexcel。