I'm developing an MVC .Net web application, and I want to read data from both .xlsx and .xls file. Currently, my application have no problem reading .xls file. I read about all the connection string but I have been having problem figuring out how should I go about implementing them as this is my first experience handling C#. Anyway here are some snippets of my code.Thanks alot in advance. Appreciate your great help.
private void button_OpenFile_Click(object sender, EventArgs e)
{
if(fileType.Equals("csv")){
openFileDialog_ExcelFile.Filter = "CSV Files (.csv)|*.csv";
}
else if (fileType.Equals("xls"))
{
openFileDialog_ExcelFile.Filter = "Excel Worksheets 1997 -2003(.xls)|*.xls";
}
else if (fileType.Equals("xlsx"))
{
openFileDialog_ExcelFile.Filter = "Excel Worksheets 2007 (.xlsx)|*.xlsx";
}
DialogResult result = openFileDialog_ExcelFile.ShowDialog(); // Show the dialog.
if (result == DialogResult.OK) // Test result.
{
OpenNewFile();
fileOpened = true;
}
if (includeAllAttributesByDefault)
SelectAndIncludeAll();
nonNumberChkBx.Checked = includeNumericValuesByDefault;
//Debug.WriteLine(result); // <-- For debugging use only.
}
private void OpenNewFile()
{
// Initializing new data object.
try
{
data = new MyData(openFileDialog_ExcelFile.FileName);
UpdateCheckListBox();
UpdateGridView();
UpdateCurrentFileInfo();
}