扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
1.将excel上传到服务器
武都网站建设公司成都创新互联,武都网站设计制作,有大型网站制作公司丰富经验。已为武都成百上千家提供企业网站建设服务。企业网站搭建\成都外贸网站建设公司要多少钱,请找那个售后服务好的武都做网站的公司定做!
/// summary
/// 上传文件到指定服务器文件
/// /summary
/// param name="fileUpload".Net_FileUpload控件/param
/// param name="mag"out 返回上传是否成功/param
/// param name="fileName"out 返回上传到服务器上的文件名/param
/// returns返回布尔类型。 上传成功返回true 失败false/returns
public static bool UpLoad(FileUpload fileUpload, out string mag, out string fileName)
{
mag = null;
fileName = null;
bool flag = false;
//是否允许上载
bool fileAllow = false;
//设定允许上载的扩展文件名类型
string[] allowExtensions = { ".xls", ".xlsx" };
//检查是否有(是否包含)文件案
if (fileUpload.HasFile)
{
//取得上传文件之扩展文件名,并转换成小写字母
string fileExtension = System.IO.Path.GetExtension(fileUpload.FileName).ToLower();
//检查扩展文件名是否符合限定类型
for (int i = 0; i allowExtensions.Length; i++)
{
if (fileExtension == allowExtensions[i])
{
fileAllow = true;
}
}
//符合上传文件类型
if (fileAllow)
{
try
{
//重命名文件名
fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + fileUpload.FileName;
//存储文件到文件夹
fileUpload.SaveAs(GetServerPath(fileName));
fileUpload.Dispose();
mag = "文件导入成功";
flag = true;
}
catch (Exception ex)
{
mag += ex.Message;
flag = false;
}
}
else
{
mag = "不允许上载:" + fileUpload.PostedFile.FileName + ",只能上传xls和xlsx的文件,请检查!";
flag = false;
}
}
else
{
mag = "请选择要导入的Excel文件!";
flag = false;
}
return flag;
}
调用 bool ft = ExcelImport.UpLoad(FileUpload1, out mag, out filePath);
FileUpload1为。net的上传控件
二,查询出Excel里面的所有工作薄名,根据OUT出来的存放excel的路径
/// summary
/// 获取EXCEL文件中的所有表名(模板类型)(SheetName)
/// /summary
/// param name="filepath"文件绝对路径/param
/// returnsArrayList集合/returns
public static ArrayList ExcelSheetName(string filepath)
{
ArrayList al = new ArrayList();
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
try
{
conn.Open();
DataTable sheetNames = conn.GetOleDbSchemaTable
(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
conn.Close();
foreach (DataRow dr in sheetNames.Rows)
{
al.Add(dr[2]);
}
}
catch (Exception e)
{
Logger.Error("ExcelImport.cs 页面 ExcelSheetName", e);
}
finally
{
conn.Close();
}
return al;
}
调用 //获取导入模板所有的模板表名
ArrayList al = ExcelImport.ExcelSheetName(UpPath);
3.进行工作薄名称的对比
string sheet = null;
//进行判断是否取到想要的sheet1
bool isExists = false;
for (int i = 0; i al.Count; i++)
{
//获取模板表名
sheet = al[i].ToString();
if (sheet.Equals("sheet1"))
{
//EXCELsheet名是sheet1
isExists = true;
}
}
搜一下:VB.NET操作SQLCE数据库,如何获取SQLCE数据库中所有表的表名
?
呵呵,刚刚做这个,就借花献佛了
/// summary
/// 获得当前Access数据库的表
/// /summary
/// param name="Source"/param
/// returns/returns
public ArrayList DataScoreTableName(string Source)
{
ArrayList TableName = new ArrayList();
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Source;
OleDbConnection conn = new OleDbConnection(ConnectionString);
conn.Open();
DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] { null, null, null, "TABLE"});
foreach (DataRow dr in schemaTable.Rows)
{
TableName.Add(dr["TABLE_NAME"]);
}
conn.Close();
return TableName;
}
Public conn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Public db As String
Private sSQL As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
db = "C:\Documents and Settings\ws01\デスクトップ\新しいフォルダ\WindowsApplication1\db1.mdb"
db = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" db
conn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
conn.Open(db)
Rs = conn.OpenSchema()
End Sub
access数据库中所有的表名都存在一个叫做MSysObjects的表中了,所以在这个表中查询就可以了。以下是代码:
Dim L_dadap As New OleDb.OleDbDataAdapter("select * from MSysObjects ", L_conn)
Dim L_dtable As New DataTable
L_dadap.Fill(L_dtable)
Dim TabName(L_dtable.Rows.Count - 1)
For i = 0 To L_dtable.Rows.Count - 1
TabName(i) = L_dtable.Rows(i).Item("name")
Next
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流