G4560用安卓模拟器那个最流畅流畅吗,不多开

西西软件下载最安全的下载网站、值得信赖的软件下载站!
→ Asp.Net 导出数据格式为Excel 数据的9种方案
官方中文原版
类型:办公软件大小:72.1M语言:中文 评分:.9
Excel 的强大之处在于它不仅仅只能打开Excel格式的文档,它还能打开CSV格式、Tab格式、website table 等多钟格式的文档。它具备自动识别行号,字符,格式化数字等功能,例如:如果你在Excel 单元格中输入数字 && 会自动转化为&1.23457E+11&。背景介绍正因为Excel的强大和易用,大家都喜欢将数据导出为 Excel 备用。这里我会介绍一系列通过Asp.Net导出Excel数据的方法。将导出文件存储到服务器并提供地址给客户端下载,或重定向到文件下载页面:当Response时,数据列以 &\t& 分隔,行以&\n&分隔。好了,现在给大家展示这是怎么做的。使用代码导出方案1:导出全部HTML 数据到 Excel这种方法是将Html中的所有文档内容,包括按钮,表格,图片等所有页面内容导出为 ExcelResponse.Clear();&&&& Response.Buffer =&&&& Response.AppendHeader(&Content-Disposition&,&filename=&+DateTime.Now.ToString(&yyyyMMdd&)+&.xls&);&&&&&&&&&& Response.ContentEncoding = System.Text.Encoding.UTF8;&& Response.ContentType = &&application/ms-excel&;&& this.EnableViewState =这里我们使用了Page的&ContentType& 属性,它默认为&text/Html&,输出到客户端即为Html。如果我们将它改为&ms-excel&,页面将输出Excel格式的内容,客户端就可以下载并存储它了。页面property 还包括:image/JPEG, text/HTML, image/GIF and vnd.ms-excel/msword.方案2:从DataGrid导出数据到Excel尽管上面的方法能帮你导出Excel数据,但它导出了所有的HTML内容,包括按钮、图片等,这并不是我们所需要的。通常,我们仅仅需要导出DataGrid中的数据。System.Web.UI.Control ctl=this.DataGrid1;//DataGrid1 (you created in the windowForm)HttpContext.Current.Response.AppendHeader(&Content-Disposition&,&filename=Excel.xls&);HttpContext.Current.Response.Charset =&UTF-8&;&&&& HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.DHttpContext.Current.Response.ContentType = &application/ms-excel&;ctl.Page.EnableViewState =&&& System.IO.StringWriter& tw = new System.IO.StringWriter() ;System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw);ctl.RenderControl(hw);HttpContext.Current.Response.Write(tw.ToString());HttpContext.Current.Response.End();如果你有多个包含DataGrid 并需导出数据的页面,我们可以封装方法:public void DGToExcel(System.Web.UI.Control ctl)&& { && HttpContext.Current.Response.AppendHeader(&Content-Disposition&,&filename=Excel.xls&); && HttpContext.Current.Response.Charset =&UTF-8&;&&&& && HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; && HttpContext.Current.Response.ContentType =&application/ms-excel&;&& ctl.Page.EnableViewState =&&& && System.IO.StringWriter& tw = new System.IO.StringWriter() ; && System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw); && ctl.RenderControl(hw); && HttpContext.Current.Response.Write(tw.ToString()); && HttpContext.Current.Response.End(); }调用方法:DGToExcel(datagrid1);方案3:自动导出Excel数据使用此方法,你需要 下载免费的.NET组件 ,并使用如下代码(部分)导出数据:private void button1_Click(object sender, EventArgs e){&&& System.Data.OleDb.OleDbConnection oleDbConnection1 = new System.Data.OleDb.OleDbConnection();&&& oleDbConnection1.ConnectionString = @&Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\Database\demo.mdb&;&&& System.Data.OleDb.OleDbCommand oleDbCommand1 = new System.Data.OleDb.OleDbCommand();&&& mandText = &select * from parts&;&&& oleDbCommand1.Connection = oleDbConnection1;&&& System.Data.OleDb.OleDbCommand oleDbCommand2 = new System.Data.OleDb.OleDbCommand();&&& mandText = &select * from country&;&&& oleDbCommand2.Connection = oleDbConnection1;   Spire.DataExport.Delegates.DataParamsEventHandler(this.cellExport3_GetDataParams);&&& oleDbConnection1.Open();&&& try&&& {&&&&&&& cellExport3.SaveToFile();&&& }&&& finally&&& {&&&&&&& oleDbConnection1.Close();&&& }}private void cellExport3_GetDataParams(object sender, Spire.DataExport.EventArgs.DataParamsEventArgs e){&&& if ((e.Sheet == 0) && (e.Col == 6))&&& {&&&&&&& e.FormatText = (sender as Spire.DataExport.XLS.WorkSheet).ExportCell.DataFormats.C&&& }}执行上面的代码,你将得到:此方案导出的Excel文件可以直接在Excel 2010 中打开、编辑和修改。虽然一些特定的功能不可用,但它能够被Excel 2010使用。方案4:从DataSet导出Excel数据依照上面都的方法,我么能很容易的导出DataSet数据到Excel,我们只需要在页面Response 时将DataSet 表中的数据组装为&ms-excel& 格式的数据,并通过Http发送出去。注:ds 代表Dataset,用它来填充DataTable,文件名包含后缀,例如:excel2006.xls。public& void CreateExcel(DataSet ds,string FileName)& { HttpR resp = Page.R resp.ContentEncoding = System.Text.Encoding.GetEncoding(&UTF-8&); resp.AppendHeader(&Content-Disposition&, &filename=&+FileName);&&& string colHeaders= &&, ls_item=&&;&& // Define table object and row object, // and at the same time use DataSet initialize value. DataTable dt=ds.Tables[0]; DataRow[] myRow=dt.Select();//dt.Select(&id&10&)Data Filer can be used as: dt.Select(&id&10&)&&&&&&& int i=0; &&&&&&& int cl=dt.Columns.C //Get column titles of each DataTable and divided by &t&. Press &enter& after the last column title. for(i=0;i&i++) colheaders+=&dt.Columns[i].Caption.ToString()+&t&;& &&& for(i=&0;i&i++)& if(i=&=(cl-1))//(last& +=&dt.Columns[i].Caption.ToString()& &&& ls_item+=&row[i].ToString()+&t&;& /&方案5:从DataView导出Excel数据如果你想导出不规则的行和列到Excel,你可以使用一下方法:public void OutputExcel(DataView dv,string str) { && //dv presents data which will be exported to Excel, str is the name of title&& GC.Collect(); && A// = new Application(); && int rowIndex=4; && int colIndex=1; && _Workbook xBk; && _Worksheet xSt; && excel= new ApplicationClass();&& && xBk = excel.Workbooks.Add(true);&& && xSt = (_Worksheet)xBk.ActiveS && // && // Acquire Title&& // && foreach(DataColumn col in dv.Table.Columns) && { &&& colIndex++; &&& excel.Cells[4,colIndex] = col.ColumnN &&& xSt.get_Range(excel.Cells[4,colIndex],excel.Cells&&& [4,colIndex]).HorizontalAlignment &&& = XlVAlign.xlVAlignC//Set title format as middle && } && // && //Obtain data from table && // && foreach(DataRowView row in dv) && { &&& rowIndex ++; &&& colIndex = 1; &&& foreach(DataColumn col in dv.Table.Columns) &&& { &&&& colIndex ++; &&&& if(col.DataType == System.Type.GetType(&System.DateTime&)) &&&& { &&&&& excel.Cells[rowIndex,colIndex] &&& = (Convert.ToDateTime(row[col.ColumnName].ToString())).ToString(&yyyy-MM-dd&); &&&&& xSt.get_Range(excel.Cells[rowIndex,colIndex],excel.Cells&&& [rowIndex,colIndex]).HorizontalAlignment &&& = XlVAlign.xlVAlignC// Set the style as middle &&&& } &&&& else &&&&& if(col.DataType == System.Type.GetType(&System.String&)) &&&& { &&&&& excel.Cells[rowIndex,colIndex] = &'&+row[col.ColumnName].ToString(); &&&&& xSt.get_Range(excel.Cells[rowIndex,colIndex],excel.Cells&&& [rowIndex,colIndex]).HorizontalAlignment = XlVAlign.xlVAlignC&&&& // Set the style as middle&&&& } &&&& else &&&& { &&&&& excel.Cells[rowIndex,colIndex] = row[col.ColumnName].ToString(); &&&& } &&& } && } && // && //load a Aggregate line&& // && int rowSum = rowIndex + 1; && int colSum = 2; && excel.Cells[rowSum,2] = & Aggregate &;&& xSt.get_Range(excel.Cells[rowSum,2],excel.Cells[rowSum,2]).HorizontalAlignment &&& = XlHAlign.xlHAlignC && // && //Set color for the selected content&& // && xSt.get_Range(excel.Cells[rowSum,colSum],excel.Cells[rowSum,colIndex]).Select(); && xSt.get_Range(excel.Cells[rowSum,colSum],excel.Cells&&& [rowSum,colIndex]).Interior.ColorIndex &&& = 19;//more than 50 types of color for you to choose && // && //obtain title of the whole excelsheet&& // && excel.Cells[2,2] = && // && //Set title format for the whole excelsheet&& // && xSt.get_Range(excel.Cells[2,2],excel.Cells[2,2]).Font.Bold = && xSt.get_Range(excel.Cells[2,2],excel.Cells[2,2]).Font.Size = 22; && // && //Set fittest width && // && xSt.get_Range(excel.Cells[4,2],excel.Cells[rowSum,colIndex]).Select(); && xSt.get_Range(excel.Cells[4,2],excel.Cells[rowSum,colIndex]).Columns.AutoFit(); && // && //Set the tile as Cross and Middle && // && xSt.get_Range(excel.Cells[2,2],excel.Cells[2,colIndex]).Select(); && xSt.get_Range(excel.Cells[2,2],excel.Cells[2,colIndex]).HorizontalAlignment &&& = XlHAlign.xlHAlignCenterAcrossS && // && //Draw borders && // && xSt.get_Range(excel.Cells[4,2],excel.Cells[rowSum,colIndex]).Borders.LineStyle = 1; && xSt.get_Range(excel.Cells[4,2],excel.Cells[rowSum,2]).Borders&& [XlBordersIndex.xlEdgeLeft].Weight&&& = XlBorderWeight.xlT// Set left line as bold&& xSt.get_Range(excel.Cells[4,2],excel.Cells[4,colIndex]).Borders[XlBordersIndex.xlEdgeTop].Weight = XlBorderWeight.xlT// Set upper line as bold&& xSt.get_Range(excel.Cells[4,colIndex],excel.Cells[rowSum,colIndex]).Borders[XlBordersIndex.xlEdgeRight].Weight = XlBorderWeight.xlT//Set right line as bold&& xSt.get_Range(excel.Cells[rowSum,2],excel.Cells[rowSum,colIndex]).Borders[XlBordersIndex.xlEdgeBottom].Weight = XlBorderWeight.xlT//Set bottom line as bold&& // && //Display effect && // && excel.Visible= && //xSt.Export(Server.MapPath(&.&)+&); && xBk.SaveCopyAs(Server.MapPath(&.&)+&&); && ds = &&&&&&&&&&& xBk.Close(false, null,null);&& &&&&&&&&&&& excel.Quit(); &&&&&&&&&&& System.Runtime.InteropServices.Marshal.ReleaseComObject(xBk); &&&&&&&&&&& System.Runtime.InteropServices.Marshal.ReleaseComObject(excel); &&& System.Runtime.InteropServices.Marshal.ReleaseComObject(xSt); &&&&&&&&&&& xBk = &&&&&&&&&&& excel = && xSt = &&&&&&&&&&& GC.Collect(); && string path = Server.MapPath(this.xlfile.Text+&.xls&); && System.IO.FileInfo file = new System.IO.FileInfo(path); && Response.Clear(); && Response.Charset=&UTF-8&; && Response.ContentEncoding=System.Text.Encoding.UTF8; && //Add header, give a default file name for &File Download/Store as&&& Response.AddHeader(&Content-Disposition&, & filename=&+ Server.UrlEncode(file.Name)); && //Add header, set file size to enable browser display download progress&& Response.AddHeader(&Content-Length&, file.Length.ToString());&&& && //Set the return string is unavailable reading for client, and must be downloaded&& Response.ContentType = &application/ms-excel&;& && //Send file string to client && Response.WriteFile(file.FullName); && //Stop execute& && Response.End(); }两种 WinForms 导出Excel 数据的解决方案方案6:SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings[&conn&]); && SqlDataAdapter da=new SqlDataAdapter(&select * from tb1&,conn); && DataSet ds=new DataSet(); && da.Fill(ds,&table1&); && DataTable dt=ds.Tables[&table1&]; && string downloadurl&].ToString()+DateTime.Today.ToString(&yyyyMMdd&)+new Random(DateTime.Now.Millisecond).Next(10000).ToString()+&.csv&;//Store the path of downloadurl in web.config and the format should be set as &date + 4 random number &&& FileStream fs=new FileStream(name,FileMode.Create,FileAccess.Write); && StreamWriter sw=new StreamWriter(fs,System.Text.Encoding.GetEncoding(&utf-8&));(&utf-8&) && sw.WriteLine(&Auto number, name, age&);&& foreach(DataRow dr in dt.Rows) && { &&& sw.WriteLine(dr[&ID&]+&,&+dr[&vName&]+&,&+dr[&iAge&]); && } && sw.Close(); && Response.AddHeader(&Content-Disposition&, & filename=& + Server.UrlEncode(name)); && Response.ContentType = &application/ms-excel&;//Set the return string is unavailable reading for client, and must be downloaded&& Response.WriteFile(name); //Send file string to client&& Response.End();public void Out2Excel(string sTableName,string url){Excel.Application oExcel=new Excel.Application();Workbooks oBWorkbook oBSheets oSWorksheet oSRange oCstring sFile=&&,sTemplate=&&;//System.Data.DataTable dt=TableOut(sTableName).Tables[0];sFile=url+&myExcel.xls&;sTemplate=url+&MyTemplate.xls&;//oExcel.Visible=oExcel.DisplayAlerts=//define a new workbookoBooks=oExcel.WoBooks.Open(sTemplate,Type.Missing,Type.Missing,Type.Missing,Type.Missing.Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing, Type.Missing, Type.Missing);oBook=oBooks.get_Item(1);oSheets=oBook.WoSheet=(Worksheet)oSheets.get_Item(1);//Give the sheet a nameoSheet.Name=&Sheet1&;oCells=oSheet.C//Call dumpdata process and export to ExcelDumpData(dt,oCells);//StoreoSheet.SaveAs(sFile,Excel.XlFileFormat.xlTemplate,Type.Missing,Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing);oBook.Close(false, Type.Missing,Type.Missing);//Exit Excel and free invoking COM resourceoExcel.Quit();GC.Collect();KillProcess(&Excel&);}private void KillProcess(string processName){System.Diagnostics.Process myproc= new System.Diagnostics.Process();//get all opened progressestry{foreach (Process thisproc in Process.GetProcessesByName(processName)){if(!thisproc.CloseMainWindow()){thisproc.Kill();}}}catch(Exception Exc){throw new Exception(&&,Exc);}}方案7:protected void ExportExcel()& {&& gridbind(); && if(ds1==null) & && string saveFileName=&&;//&& bool fileSaved=&& SaveFileDialog saveDialog=new SaveFileDialog();&& saveDialog.DefaultExt =&xls&;&& saveDialog.Filter=&Excel File|*.xls&;&& saveDialog.FileName =&Sheet1&;&& saveDialog.ShowDialog();&& saveFileName=saveDialog.FileN&& if(saveFileName.IndexOf(&:&)&0) // Cancelled//excelapp.Workbooks.Open&& (App.path & Progress table.xls) && Excel.Application xlApp=new Excel.Application();&& object missing=System.Reflection.Missing.V & &&& if(xlApp==null)&& {&&& MessageBox.Show(&Create Excel object failed, maybe you dont install Excel &);&&&&& }&& Excel.Workbooks workbooks=xlApp.W&& Excel.Workbook workbook=workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);&& Excel.Worksheet worksheet=(Excel.Worksheet)workbook.Worksheets[1];// Get sheet1&& Excel.R& && string oldCaption=Title_label .Text.Trim ();&& long totalCount=ds1.Tables[0].Rows.C&& long rowRead=0;&& float percent=0; & && worksheet.Cells[1,1]=Title_label .Text.Trim ();&& //Write text&& for(int i=0;i&ds1.tables[0].columns.i++) &&& worksheet.cells[2,i+1]=&ds1.Tables[0].Columns.ColumnN& &&& range.interior.colorindex=&15;& range.font.bold=&& &&& .visible=&& r=&0;r&ds1.Tables[0].Rows.Cr++)& &&& i=&0;i&ds1.Tables[0].Columns.Ci++)& &&& worksheet.cells[r+3,i+1]=&ds1.Tables[0].Rows[r];& &&& percent=&((float)(100*rowRead))/totalC& this.caption.visible=&& &&& this.caption.text=& Exporting Data [& range=&(Excel.Range)worksheet.Cells&&& [2,i+1];& range.borders[excel.xlbordersindex.xlinsidehorizontal].colorindex=&&& &Excel.XlColorIndex.xlColorIndexA& &&& range.borders[excel.xlbordersindex.xlinsidehorizontal].linestyle=&&& &Excel.XlLineStyle.xlC& &&& range.borders[excel.xlbordersindex.xlinsidehorizontal].weight=&&& &Excel.XlBorderWeight.xlT&&1)&& {&&& range.Borders[Excel.XlBordersIndex.xlInsideVertical].ColorIndex=Excel.XlColorIndex.xlColorIndexA&&& }&& workbook.Close(missing,missing,missing);&& xlApp.Quit();}方案8 (from Cipherlad):使用DataSet 的GetXml方法,并且使用XSLT将XML转化为标准的Excel格式,你可以使用不同样式模版对应不容版本的Excel,甚至可以用于导出其它文档。方案9 (from Sergelp):使用 OOXML 格式的开源库:/这是一个非常便捷的库,它包含多种格式、字体、颜色订制,你也不需要安装Excel软件,你可以在服务端创建Excel,然后实现下载,如下代码所示:Dim&ms&As&MemoryStream&=&ArticleDAL.GetStreamFromDataSet()
Response.Clear()
Response.AddHeader(&content-disposition&,&String.Format(&filename={0}&,&strFile))
Response.ContentType&=&&application/vnd.openxmlformats-officedocument.spreadsheetml.sheet&
ms.WriteTo(Response.OutputStream)
Response.End()
在日常办公中经常会需要用到表格软件,一般我们常见的表格软件就是了,不过只有正版系统中才有,而很多国人使用的都是盗版的系统是没有软件的。这里西西给大家提供了一些比较好用的表格软件下载,包括等软件,如果你的电脑中没有,需要找一些好用的软件可以来西西下载。...
11-04 / 52.3M
推荐理由:WPS2013深度兼容Microsoft Office,你可以直接保存和打开 Microsoft Word、Excel 和 PowerPoint 文件;即使
05-03 / 21.9M
推荐理由:金山软件的WPSOffice终于出现在Android平台上,并更名为KingsoftOffice。在手机上打开和编辑word,tst,wps文
02-05 / 52.3M
推荐理由:WPS Office是金山公司的老牌办公软件套装,可以实现办公软件最常用的文字、表格、演示等多种功能。WPS Offi
05-26 / 52.3M
推荐理由:WPS Office 2014个人版(SP1)新增功能1 WPS表格新引擎 多线程计算技术,最大限度发挥计算机性能,效率更高 。
11-17 / 72.1M
推荐理由:本次提供的是Excel 2007工作薄查看,打印、浏览工具,不能对excel工作薄创建、编辑、修改工作。那是Office
11-10 / 36.9M
推荐理由:采用 Microsoft Office Word、Excel 和 PowerPoint 2007 新增的文件格式打开、编辑和保存文档、工作簿和演示
这款办公软件大家平时都用吧,小编相信也不用做多介绍了,西西主要为大家带来官方原版及一些电子书快捷键等下载,有需要的就拿走吧官方下载说明这个版本是官方正式版,是官方许可免费发布的软件,可以在您的设备上安装和使用本软件的任意数量的副本。小编平时也经常用它,所以整理了一些格式的电子书分享给大家,新手可以认真看看。官方介绍是一款老牌的办公软件套装,可以实现办公软件最常用的文字表格演示等多种功能。内存占用低...
11-17 / 72.1M
推荐理由:本次提供的是Excel 2007工作薄查看,打印、浏览工具,不能对excel工作薄创建、编辑、修改工作。那是Office
11-10 / 36.9M
推荐理由:采用 Microsoft Office Word、Excel 和 PowerPoint 2007 新增的文件格式打开、编辑和保存文档、工作簿和演示
04-06 / 64.6M
推荐理由:该版本采用Office 2007 SP1 中文、英文双语版本制作而成,功能上进行了一定的精减,但保留了VBA、绘图笔及构
03-21 / 56.2M
推荐理由:Microsoft Office 2007精简版包括: •Microsoft Office Excel 2007 •Microsoft Office PowerPo
04-14 / 20.6M
推荐理由:最新版本:v1.2.0403,升级日期:本次主要升级:1.完善了升级功能,直接覆盖安装即可自动升级。2
11-12 / 234KB
推荐理由:我们在工作或者学习中会经常需要运用excel或者word,所以熟练掌握excel的制表技巧是非常重要的,我们在exce
12-1110-2609-3009-2309-1509-0908-2408-2108-1007-20
阅读本文后您有什么感想? 已有23人给出评价!
名称大小下载asp网页中导出数据到Excel身份证号码显示科学计数法以及Excel中数字前面的单引号如何变成绿色三角符号的解决办法
我的图书馆
asp网页中导出数据到Excel身份证号码显示科学计数法以及Excel中数字前面的单引号如何变成绿色三角符号的解决办法
帮同事做一个非师范生教师资格证报名系统。学生注册了信息后,管理员要把数据导出到excel中。结果问题出现了:身份证号和手机号码导出后变成科学计数法,如果设置单元格格式为文本,身份证号码后的几位数都会变成0.在网上找了很久,没有很方便的解决办法。灵机一动,我想起来一个最简单的办法,和大家分享:
大家知道excel中输入一串数字,想要作为文本,前面可以加个英文的单引号。那我在将学生的身份证号和手机号码存入数据表之前,在这两个字段前手动加个单引号:
rs.addnew()
rs("身份证号码")=“‘”&request("sfzh")&&& '&前面其实就是双引号引了一个单引号
rs("手机号码")="'"&request("tel")&&
哈哈,我是不是很聪明?
不过问题又出来了。导出数据后,excel中这两列每个数字前面都能看到单引号,而且打印的时候会把单引号打印处理。
&&&&&&&&&&&&&&&&&&&
&怎么办?在网上搜索了一圈,找到解决办法:
第一个方法是首先是将数字一列选中,选择数据——分列,单击“下一步”,文本分割符号选择单引号’。继续单击下一步,在“列数据格式”选项中选择“文本”。哈哈,所有数字前面都能看到那个养眼的绿色三角洲了。
发表评论:
TA的最新馆藏

我要回帖

更多关于 安卓模拟器哪个最流畅 的文章

 

随机推荐