Начальная точка:
I am basing this on any number of attributes.
Add a script componenet to dataflow(source)
Add your output columns:
Now enter your script and add this method to read excel into a data table. You already mentioned this so i figured you knew how to do that.
public static DataTable exceldata(string filePath)
{
DataTable dtexcel = new DataTable();
bool hasHeaders = true;
string HDR = hasHeaders ? "Yes" : "No";
string strConn;
if (filePath.Substring(filePath.LastIndexOf('.')).ToLower() == ".xlsx")
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0;HDR=" + HDR + ";IMEX=0\"";
else
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=\"Excel 8.0;HDR=" + HDR + ";IMEX=0\"";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
//Looping Total Sheet of Xl File
/*foreach (DataRow schemaRow in schemaTable.Rows)
{
}*/
//Looping a first Sheet of Xl File
DataRow schemaRow = schemaTable.Rows[0];
string sheet = schemaRow["TABLE_NAME"].ToString();
if (!sheet.EndsWith("_"))
{
string query = "SELECT * FROM [" + sheet + "]";
OleDbDataAdapter daexcel = new OleDbDataAdapter(query, conn);
dtexcel.Locale = System.Globalization.CultureInfo.CurrentCulture;
daexcel.Fill(dtexcel);
}
conn.Close();
return dtexcel;
}
Now this is the script for writing out the rows:
public override void CreateNewOutputRows()
{
string filePath = @"D:\Temp\Test.xlsx";
//string sheetName = "Sheet1" + "_";
DataTable dt = exceldata(filePath);
foreach (DataRow row in dt.Rows)
{
for (int c = 2; c < dt.Columns.Count; c++)
{
if (row[c].ToString() != "")
{
Output0Buffer.AddRow();
Output0Buffer.ID = Convert.ToInt32(row.Field(0));
Output0Buffer.Name = row[1].ToString();
Output0Buffer.Attribute = dt.Columns[c].ColumnName;
Output0Buffer.Value = row[c].ToString();
}
}
}
}
Result:
введите описание изображения здесь