C# - как читать файл excel из пути к файлу INI.
Hi, I am doing some calculation based on my excel input. This Excel user can select from the particular path and then select the file. But, now client wants, they don't want to select excel file from the path. Instead of that, they will mention the file path in the INI file. While loading the form, first it should read the INI File and then read and convert into datatable. I am new to use INI File. Can anyone suggest how to write code to read the file from INI and convert those file into datatable See my current code below..
Что я уже пробовал:
private void btnbrowse_Click(object sender, EventArgs e) { this.openFileDialog1.Filter = "Excel file (*.xls;)|*.xlsx"; this.openFileDialog1.Multiselect = true; this.openFileDialog1.Title = "Select Excel"; DialogResult dr = this.openFileDialog1.ShowDialog(); DataTable dataTable1 = new DataTable(); if (dr == System.Windows.Forms.DialogResult.OK) { foreach (String file in openFileDialog1.FileNames) { Excelname = file; txtXLfile.Text = Excelname; } } dtproject = getXLDatatable(Excelname, dataTable1); DataRow dr1; dr1 = dtproject.NewRow(); dr1.ItemArray = new object[] { 0, "Select Project" }; dtproject.Rows.InsertAt(dr1, 0); cmbProject.ValueMember = "EmployeeName"; cmbProject.DisplayMember = "EmployeeName"; cmbProject.DataSource = dtproject; } private static DataTable getXLDatatable(string XLbroname, DataTable dataTable1) { FileStream fstream1 = new FileStream(XLbroname, FileMode.Open); Workbook workbook1 = new Workbook(fstream1); Worksheet worksheet1 = workbook1.Worksheets[0]; dataTable1.AcceptChanges(); DataSet ds1 = new DataSet(); DataTable dt2 = new DataTable(); ds1.Tables.Add(dataTable1); dataTable1 = worksheet1.Cells.ExportDataTable(1, 0, worksheet1.Cells.MaxRow + 1, worksheet1.Cells.MaxColumn + 1); dataTable1.TableName = "tableXL"; dataTable1.Columns[0].ColumnName = "Id"; dataTable1.Columns[1].ColumnName = "EmployeeName"; dataTable1.Columns[2].ColumnName = "Dept"; dataTable1.Columns[3].ColumnName = "Section"; dt2 = dataTable1; return dt2; }