日期:2014-05-20  浏览次数:20785 次

疑难问题~~,请各位高手指点~~!可追加分!
首先不考虑采用b/s或c/s那种架构,我想集中处理一批excel表(大概几百个,结构不同),这些表在内容上有相关/相同字段,我主要是想把重复信息去掉,把几张表的信息整合到一起,最终是要导到sqlserver中的,我不知道:
1、是先把众多excel表现整合为一张表处理好呢,还是先都导入到sqlserver中,然后再处理成一张表好呢
2、怎么样批量将不同结构的excel表导入到sqlserver的一张表中?
3、我发现dtc很不错,功能比较全,但是只能导入单个excel文件,我的问题还和批量有关,能不能在后台程序上c#使用dtc的功能,处理多个excel表?
4、这个问题离上面的问题比较远:如果我想通过c#将一批excel表的字段列出,应该怎么做?

我的思路可能不太清晰,问得也比较愚钝,还烦请各位多多指点,不胜感激,可以加分!

------解决方案--------------------
根据我的经验还是先导入数据库,在从数据库中处理要好点
------解决方案--------------------
应该是先导入后处理好些吧

写个从excel导入到sql的小程序不就行了
根据列数创建表 然后按行导入

至于几百个文件 用Files取呗
------解决方案--------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace ExcelToSql
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void btnConvert_Click(object sender, EventArgs e)
{
string strExcelFullNamePath = System.Configuration.ConfigurationManager.AppSettings[ "excelFileFullNamePath "].ToString();
string strExcelSheetName = System.Configuration.ConfigurationManager.AppSettings[ "sheetName "].ToString();
string strSqlCon = System.Configuration.ConfigurationManager.AppSettings[ "connectionstring "].ToString();
int column = 3;//the start of the valid value;
if (strExcelFullNamePath == string.Empty)
{
Response.Write( " <script> alert( 'Sorry! ExcelFullNamePath is empty! Please setup Web.config! '); </script> ");
return;
}

if (strExcelSheetName == string.Empty)
{
Response.Write( " <script> alert( 'Sorry! ExcelSheetName is empty! Please setup Web.config! '); </script> ");
return;
}

if (strSqlCon == string.Empty)
{
Response.Write( " <script> alert( 'Sorry! SqlConnectionString is empty! Please setup Web.config! '); </script> ");
return;
}

string strExcelCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + @strExcelFullNamePath + ";Extended Properties= 'Excel 8.0;HDR=NO;IMEX=1; ' ";
string strExcelSelect = "select * from [ " + strExcelSheetName + "$] ";
DataSet ds = new DataSet();
try
{
OleDbConnection oledbExcelCon = new OleDbConnection(strExcelCon);
OleDbDataAdapter oledbExcelDA = new OleDbDataAdapter(strExcelSelect, oledbExcelCon);
oledbExcelDA.Fill(ds);
//this.gv1.DataSource = ds;
//this.gv1.DataBind();
}
catch (Exception ex)
{
Response.Write( " <font color = 'red '> " + ex.Message.ToString() + " </font> ");
return;
}

string strSqlInsert = " ";