Sry.Solution.Components/DataTableExcel.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Data.OleDb;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Sry.Solution.Components
{
public class DataTableExcel
{
/// <summary>
/// 根据excel文件路径和文件名得到数据
/// </summary>
/// <param name="filenameurl">文件路径</param>
/// <param name="table">文件名</param>
/// <returns></returns>
public static DataSet ExecleDs(string filenameurl, string table)
{
DataSet ds = new DataSet();
string strConn = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + filenameurl + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1;'";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string tableName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0][2].ToString().Trim();
OleDbDataAdapter odda = new OleDbDataAdapter("select * from [" + tableName + "]", conn);
odda.Fill(ds, table);
conn.Close();
odda.Dispose();
System.IO.File.Delete(filenameurl);
return ds;
}
/// <summary>
/// Datatable to Excel带自定文件名的导出
/// </summary>
/// <param name="dt"></param>
/// <param name="FileName"></param>
//public static void DataTableExcel(System.Data.DataTable dt, string FileName)
//{
//System.IO.StringWriter stringWriter = new System.IO.StringWriter();
//HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
//DataGrid excel = new DataGrid();
//System.Web.UI.WebControls.TableItemStyle headerStyle = new TableItemStyle();
//System.Web.UI.WebControls.TableItemStyle itemStyle = new TableItemStyle();
//headerStyle.BackColor = System.Drawing.Color.LightGray;
//headerStyle.Font.Bold = true;
//headerStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
//excel.HeaderStyle.MergeWith(headerStyle);
//excel.ItemStyle.MergeWith(itemStyle);
//excel.GridLines = GridLines.Both;
//excel.HeaderStyle.Font.Bold = true;
//excel.DataSource = dt.DefaultView;
后面还有 20 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。