asp.net動(dòng)態(tài)獲取Excel表名的函數(shù)代碼
更新時(shí)間:2011年02月14日 22:51:13 作者:
asp.net動(dòng)態(tài)獲取Excel表名的函數(shù)代碼,需要的朋友可以參考下。
復(fù)制代碼 代碼如下:
public string GetExcelFirstTableName(string excelFileName)
{
string tableName = null;
if (File.Exists(excelFileName))
{
using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet." +
"OLEDB.4.0;Extended Properties=\"Excel 8.0\";Data Source=" + excelFileName))
{
conn.Open();
DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
for (int i = 0; i < dt.Rows.Count; i++)
{
tableName += dt.Rows[i][2].ToString().Trim();
view sourceprint?1 }
}
}
return tableName;
}
asp.net讀取excel動(dòng)態(tài)獲取表名
復(fù)制代碼 代碼如下:
string a=File1.PostedFile.FileName.ToString();
string excelFilePath=a;
Excel.Application myExcel=new Excel.ApplicationClass( ) ;
object oMissing = System.Reflection.Missing.Value ;
myExcel.Application.Workbooks.Open(excelFilePath,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing) ;
Excel.Workbook myBook = myExcel.Workbooks[1] ;
Excel.Worksheet mySheet = (Excel.Worksheet)myBook.Worksheets[1] ;
Response.Write(mySheet.Name);
string Name=mySheet.Name;
System.Data.DataTable dt=new System.Data.DataTable("mytable");
dt.Columns.Add("F1", System.Type.GetType("System.String"));
dt.Columns.Add("F2", System.Type.GetType("System.String"));
dt.Columns.Add("F3", System.Type.GetType("System.String"));
dt.Columns.Add("F4", System.Type.GetType("System.String"));
dt.Columns.Add("F5", System.Type.GetType("System.String"));
DataSet myDs = new DataSet();
myDs.Tables.Add(dt);
DataRow myRow;
myDs.Clear();
for( int i = 2 ; i <= 4 ; i ++ ) //第一行為標(biāo)題,不讀取
{
myRow = myDs.Tables["mytable"].NewRow();
for( int j = 1 ; j <= 5 ; j ++ )
{
Excel.Range r=(Excel.Range)mySheet.Cells[i,j];
string strValue=r.Text.ToString();
string aa=strValue;
string columnname="F"+j.ToString();
myRow[columnname]=strValue;
}
myDs.Tables["mytable"].Rows.Add(myRow);
// }
myExcel.Quit();
DataGrid1.DataSource=myDs.Tables["mytable"].DefaultView;
DataGrid1.DataBind();
您可能感興趣的文章:
- 收集學(xué)習(xí)asp.net比較完整的面向?qū)ο箝_(kāi)發(fā)流程
- ASP.NET編程中經(jīng)常用到的27個(gè)函數(shù)集
- asp.net Repeater綁定時(shí)使用函數(shù)
- asp.net簡(jiǎn)化接收參數(shù)值的函數(shù)
- 介紹幾個(gè)ASP.NET中容易忽略但卻很重要的方法函數(shù)
- ASP.NET常用函數(shù)(推薦)
- asp.net字符串分割函數(shù)使用方法分享
- asp.net 驗(yàn)證字符串是否為純數(shù)字檢測(cè)函數(shù)
- asp.net(C#)函數(shù)對(duì)象參數(shù)傳遞的問(wèn)題
- ASP.NET私有構(gòu)造函數(shù)用法分析
相關(guān)文章
ASP.NET Core中快速構(gòu)建PDF文檔的步驟分享
這篇文章主要給大家介紹了關(guān)于ASP.NET Core中快速構(gòu)建PDF文檔的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用ASP.NET Core具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12asp.net如何在圖片上加水印文字具體實(shí)現(xiàn)
這篇文章主要介紹了asp.net如何在圖片上加水印文字具體實(shí)現(xiàn),有需要的朋友可以參考一下2013-12-12值得收藏的asp.net基礎(chǔ)學(xué)習(xí)筆記
這篇文章主要分享了一份值得大家收藏的asp.net基礎(chǔ)學(xué)習(xí)筆記,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09ASP.Net Core3.0中使用JWT認(rèn)證的實(shí)現(xiàn)
這篇文章主要介紹了ASP.Net Core3.0中使用JWT認(rèn)證的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01asp.net session的使用與過(guò)期實(shí)例代碼
本文章來(lái)簡(jiǎn)單的介紹asp.net中session常見(jiàn)兩種用法,一種是session使用如何創(chuàng)建,另一種是告訴你如何判斷session過(guò)期了,有需要了解的朋友可以參考一下2013-08-08.NET Core利用動(dòng)態(tài)代理實(shí)現(xiàn)AOP(面向切面編程)
用動(dòng)態(tài)代理可以做AOP(面向切面編程),進(jìn)行無(wú)入侵式實(shí)現(xiàn)自己的擴(kuò)展業(yè)務(wù),調(diào)用者和被調(diào)用者之間的解耦,提高代碼的靈活性和可擴(kuò)展性。本文將為大家詳細(xì)介紹實(shí)現(xiàn)的方法,感興趣的可以學(xué)習(xí)一下2022-01-01