LearningScripts
New member
- Joined
- Apr 30, 2022
- Messages
- 2
- Programming Experience
- 1-3
Hi,
Seeking for help please because I tried to import my excel file to my dataGrid but it is not properly getting the value of the excel cell value. Can you help me enlighten please on how can I get the cell value regardless of the cell format of the excel. Please see screenshots image below as well as my code. THank you.
if (ofd.ShowDialog() == DialogResult.OK)
{
txt_Locate.Text = ofd.FileName;
//Load Data to Data Grid
Microsoft.Office.Interop.Excel.Application xlapp;
Microsoft.Office.Interop.Excel.Workbook xlworkbook;
Microsoft.Office.Interop.Excel.Worksheet xlworksheet;
Microsoft.Office.Interop.Excel.Range xlrange;
xlapp = new Microsoft.Office.Interop.Excel.Application();
xlworkbook = xlapp.Workbooks.Open(txt_Locate.Text);
xlworksheet = xlworkbook.Sheets[1];
xlrange = xlworksheet.UsedRange;
for (int xlRow = 1; xlRow <= xlrange.Rows.Count; xlRow++)
{
data_GRD.Rows.Add(
xlrange.Cells[xlRow, 1].Text,
xlrange.Cells[xlRow, 2].Text,
xlrange.Cells[xlRow, 3].Text);
}
xlworkbook.Close();
xlapp.Quit();
}
Seeking for help please because I tried to import my excel file to my dataGrid but it is not properly getting the value of the excel cell value. Can you help me enlighten please on how can I get the cell value regardless of the cell format of the excel. Please see screenshots image below as well as my code. THank you.
if (ofd.ShowDialog() == DialogResult.OK)
{
txt_Locate.Text = ofd.FileName;
//Load Data to Data Grid
Microsoft.Office.Interop.Excel.Application xlapp;
Microsoft.Office.Interop.Excel.Workbook xlworkbook;
Microsoft.Office.Interop.Excel.Worksheet xlworksheet;
Microsoft.Office.Interop.Excel.Range xlrange;
xlapp = new Microsoft.Office.Interop.Excel.Application();
xlworkbook = xlapp.Workbooks.Open(txt_Locate.Text);
xlworksheet = xlworkbook.Sheets[1];
xlrange = xlworksheet.UsedRange;
for (int xlRow = 1; xlRow <= xlrange.Rows.Count; xlRow++)
{
data_GRD.Rows.Add(
xlrange.Cells[xlRow, 1].Text,
xlrange.Cells[xlRow, 2].Text,
xlrange.Cells[xlRow, 3].Text);
}
xlworkbook.Close();
xlapp.Quit();
}