0
到目前爲止,我可以從電子表格中輕鬆獲取數據,只是獲取參考號碼行,但我目前不知道如何在獲取正確的數據之前將該行與數據部分進行匹配。如何將日期與行匹配,然後使用EPPlus獲取最終列值?
我現在有提取從下面的Excel電子表格例如一些數據:
Start date Ref number
29/07/2015 2342326
01/07/2016 5697455
02/08/2016 3453787
02/08/2016 5345355
02/08/2015 8364456
03/08/2016 1479789
04/07/2015 9334578
主要的問題是有可能從一組最新的數據讀取,從該行並得到裁判數字形成設定的日期,例如開始日期。
例如,如果我只是想從設置的日期的數據到上個月和第一個月以上。
這將如何最好地實施。用來獲得柱,使用基本的OleDb當前代碼
例子:
using System;
using System.Data.OleDb;
using System.Text.RegularExpressions;
namespace Number_Cleaner
{
public class NumberCleanerReport
{
public void runExcel_Report()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("[*][START OF: NumberExt.xls, Number Extraction]");
Console.ResetColor();
string con =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NumberExt.xls;" +
@"Extended Properties='Excel 8.0;HDR=Yes;'";
string connectionString = ExcelWriter.GetConnectionString();
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
using (OleDbConnection connection = new OleDbConnection(con))
{
connection.Open();
OleDbCommand command = new OleDbCommand("select * from [Sheet1$]", connection);
System.IO.StreamWriter files = new System.IO.StreamWriter(Controller.fpath + "NumberExtOutput.txt");
using (OleDbDataReader dr = command.ExecuteReader())
{
while (dr.Read())
{
var row1Col0 = dr[0];
string ExcelData = row1Col0.ToString();
string subStr = "null";
try
{
subStr = ExcelData.Substring(0, 6);
}
catch
{
//Console.WriteLine("Found Nulls.");
}
if (subStr == "00")
{
string result = Regex.Replace(ExcelData, "^00", "0");
Console.WriteLine(result);
files.WriteLine(result);
cmd.CommandText = "INSERT INTO [table1]('MainNmbers') VALUES(" + result + ");";
cmd.ExecuteNonQuery();
}
}
files.Close();
conn.Close();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("[*][END OF: NumberExt.xls, RefNumber Extraction]");
Console.ResetColor();
}
}
}
}
}
}