请帮助我,并在下面的C#代码中解释我在哪里出错。我的要求将输出作为相关的column(E7)单元格值。但是当我使用下面的代码时,输出是该单元格的计数,请告诉我,我该如何纠正呢?
private void btn_Attach_Click(object sender, EventArgs e)
{
string datetime = DateTime.Now.ToString("yyyyMMddHHmmss");
string LogFolder = @"C:\Log\";
try
{
string CellToRead = "A2";
string CellName = "";
Int32 CellNumber;
string fileFullPath = @"C:\Users\Pavan\Desktop\IT";
string CellValue = "";
var alphanumericstring = new System.Text.RegularExpressions.Regex("(?<Alpha>[a-zA-Z]*)(?<Numeric>[0-9]*)");
var match = alphanumericstring.Match(CellToRead);
CellName = match.Groups["Alpha"].Value;
int.TryParse(match.Groups["Numeric"].Value, out CellNumber);
string ConStr;
ConStr = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileFullPath + ";Extended Properties=dBASE IV; User ID=;Password=;");
OleDbConnection cnn = new OleDbConnection(ConStr);
cnn.Open();
System.Data.DataTable dtSheet = cnn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
OleDbCommand oconn = new OleDbCommand("select * from CSHMIMP0.dbf ["+CellName +(CellNumber - 1).ToString()+ ":" + CellToRead + "]", cnn);
OleDbDataAdapter adp = new OleDbDataAdapter(oconn);
System.Data.DataTable dt = new System.Data.DataTable();
adp.Fill(dt);
cnn.Close();
foreach (DataRow row in dt.Rows)
{
object[] array = row.ItemArray;
CellValue = array[0].ToString();
}
Console.WriteLine("CelltoRead :" + CellToRead + " Cell Value:" + CellValue);
Console.ReadLine();
}
catch (Exception exception)
{
using (StreamWriter sw = File.CreateText(LogFolder + "\\" + "ErrorLog_" + datetime + ".log"))
{
sw.WriteLine(exception.ToString());
}
}
}
E7单元格值为“ MCROYALE”