当前位置:才华咖 > 互联网计算机 > 设计制作 > 网页设计 > asp.net动态获取Excel表名的代码
手机版

asp.net动态获取Excel表名的代码

来源:才华咖 阅读:2.67W 次

复制代码 代码如下:

asp.net动态获取Excel表名的代码

public string GetExcelFirstTableName(string excelFileName)

{

string tableName = null;

if (ts(excelFileName))

{

using (OleDbConnection conn = new OleDbConnection("Provider=." +

"OLEDB.4.0;Extended Properties="Excel 8.0";Data Source=" + excelFileName))

{

();

DataTable dt = leDbSchemaTable(es, null);

for (int i = 0; i < t; i++)

{

tableName += [i][2]ring()();

view sourceprint?1 }

}

}

return tableName;

}

读取excel动态获取表名

复制代码 代码如下:

string a=ring();

string excelFilePath=a;

ication myExcel=new icationClass( ) ;

object oMissing = e ;

(excelFilePath,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing) ;

book myBook = books[1] ;

sheet mySheet = (sheet)sheets[1] ;

e();

string Name=;

Table dt=new Table("mytable");

("F1", ype("ng"));

("F2", ype("ng"));

("F3", ype("ng"));

("F4", ype("ng"));

("F5", ype("ng"));

DataSet myDs = new DataSet();

(dt);

DataRow myRow;

r();

for( int i = 2 ; i <= 4 ; i ++ ) //第一行为标题,不读取

{

myRow = es["mytable"]ow();

for( int j = 1 ; j <= 5 ; j ++ )

{

e r=(e)s[i,j];

string strValue=ring();

string aa=strValue;

string columnname="F"+ring();

myRow[columnname]=strValue;

}

es["mytable"](myRow);

// }

();

Source=es["mytable"]ultView;

Bind();

本文链接:https://www.caihuaka.com/sjzz/sjzz/yejvlv.html

Copyright © 2024. 才华咖 All right reserved. 浙ICP备20120231号-3

文字美图素材,版权属于原作者。部分文章内容由网友提供推送时因种种原因未能与原作者联系上,若涉及版权问题,敬请原作者联系我们,立即处理。