How to read irregular cells in Excel after merged?

Posted by Hitu under C# on 4/9/2015 | Points: 10 | Views : 419 | Status : [Member] | Replies : 1
How to read a cell if it has been merged? For example A1 A2 B1 B2 merged as one, how could I read it's data? Thanks.
DataTable dtGBPatient = new DataTable();

string strConn;

string excelName;

string excelPath;

OpenFileDialog fileDlg = new OpenFileDialog();

fileDlg.Multiselect = false;

fileDlg.Filter = "????(*.*)|*.*";//"excel 2003 ??(*.xls)|*.xls|excel 2007 ?? (*.xlsx)|*.xlsx";
if (fileDlg.ShowDialog() == DialogResult.OK)
{
excelPath = fileDlg.FileName;

// excelPath.inde

strConn = @"Provider = Microsoft.Jet.OLEDB.4.0;Data Source = '{0}'; Extended Properties = 'Excel 8.0; HDR = YES; IMEX = 1';";

string strConnection = string.Format(strConn, excelPath);

OleDbConnection conn = new OleDbConnection(strConnection);

conn.Open();
// excelName= GetFirstSheetNameFromExcelFileName(excelPath,0);

excelName = "The note list of Container";
OleDbDataAdapter oada = new OleDbDataAdapter("select * from [" + excelName + "$]", strConnection);

dtGBPatient.TableName = "gbPatientInfo";

oada.Fill(dtGBPatient);

conn.Close();

Can't read irregular cell,help me plz.




Responses

Posted by: Yesi on: 4/9/2015 [Member] Starter | Points: 25

Up
0
Down
You better don't use ADO to read. You can try this libraryhttp://www.e-iceblue.com/Introduce/excel-for-net-introduce.html ,after add reference add the code:
 Workbook workbook=new Workbook();
workbook.LoadFromFile("test.xlsx");
Worksheet sheet = workbook.Worksheets[0];
sheet.Range["A1:C3"].Merge();
string str = sheet.Range["A1"].Value.ToString();
Console.WriteLine(str);
Console.ReadKey();


Hitu, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response