ASP.NET中如何灵活的操作一个复杂的Excel表,例如读取指定的 单元格C3的内容 或者 C3:F3的内容其实我主要就是想判断 一下C1单元格是否是 是"SUM(A1:B1)" 大虾们能详细点么?我很新手的~~分也不多求教~我有用如下代码把excel中的题目表导入DataGrid中,但是没用....求指教、求教育: protected void Page_Load(object sender, EventArgs e)
{
DataSet ds=ExcelToDS(@"C:\Users\Administrator\Desktop\excel.xls");
DataGrid1.DataSource = ds.Tables["table"].DefaultView;
DataGrid1.DataBind();
} /// <summary>
/// 读取Excel文档
/// </summary>
/// <param name="Path">文件名称</param>
/// <returns>返回一个数据集</returns>
public DataSet ExcelToDS(string Path)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
OleDbDataAdapter myCommand = null;
DataSet ds = null;
strExcel = "select * from [题目$]";
myCommand = new OleDbDataAdapter(strExcel, strConn);
ds = new DataSet();
myCommand.Fill(ds, "table");
return ds;
}
{
DataSet ds=ExcelToDS(@"C:\Users\Administrator\Desktop\excel.xls");
DataGrid1.DataSource = ds.Tables["table"].DefaultView;
DataGrid1.DataBind();
} /// <summary>
/// 读取Excel文档
/// </summary>
/// <param name="Path">文件名称</param>
/// <returns>返回一个数据集</returns>
public DataSet ExcelToDS(string Path)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
OleDbDataAdapter myCommand = null;
DataSet ds = null;
strExcel = "select * from [题目$]";
myCommand = new OleDbDataAdapter(strExcel, strConn);
ds = new DataSet();
myCommand.Fill(ds, "table");
return ds;
}
解决方案 »
- js实现网页全屏(效果和F11一样)
- 为过程或函数##指定了过多的参数?
- 奇怪的问题,传到服务器上就不行了~!?各位帮忙看看
- 求一个文字的分页功能??
- 各位前辈,现在想往ASP.net方向发展,能否推荐一些学ASP.NET的好书??
- ASP.NET页面刷新时,第一次执行的方法是什么?在PageLoad方法之前是什么方法?
- 类似panel自定义控件?允许拖入其他服务器控件问题
- Jpage分页 .net2.0版通用分页
- 怎样将数据导入到word中,并加上页眉
- 怎样判断一个DataReader是否有下一条记录?
- asp.net中的menu控件,如何获取哪一个按钮被点击
- 发不到IIS 之后,外部的 js css 图片都引用不到
///<summary>
///读取单元格
///</summary>
private void a()
{
Excel.Application ObjApp=new Excel.ApplicationClass();//创建一个Excel对象
Excel.Sheets ObjSheets;//定义一个工作表组
Excel._Worksheet ObjSheet;//定义一个工作表 ObjApp.Workbooks.Open(Server.MapPath(@".\excel.xls"), System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);
ObjSheets = ObjApp.Worksheets;//引用工作簿中的工作表
ObjSheet = (Excel._Worksheet)ObjSheets.get_Item(1);//得到工作表组中第一个工作表
Excel.Range rang = (Excel.Range)ObjSheet.Cells[3, 1];
Response.Write(rang.Text);
}求教:怎么去判断单元格是否使用函数呢?使用什么函数呢?
使用 ADO.NET 更新 Excel 中指定单元格的内容 String sql = "Select * from [Sheet1$C3:C3]";