Reputation: 109
I have this code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TabeleExcel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void cboSheet_SelectedIndexChanged(object sender, EventArgs e)
{
DataTable dt = tableCollection[cboSheet.SelectedItem.ToString()];
dataGridView1.DataSource = dt;
}
DataTableCollection tableCollection;
private void btnBrowse_Click(object sender, EventArgs e)
{
using(OpenFileDialog openFileDialog=new OpenFileDialog() { Filter="Excel|*.xls|Excel|*.xlsx" })
{
if(openFileDialog.ShowDialog()==DialogResult.OK)
{
txtFilename.Text = openFileDialog.FileName;
using(var stream=File.Open(openFileDialog.FileName, FileMode.Open, FileAccess.Read))
{
using (IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream))
{
DataSet result = reader.AsDataSet(new ExcelDataSetConfiguration()
{
ConfigureDataTable=(_)=>new ExcelDataTableConfiguration() { UseHeaderRow=true }
});
tableCollection = result.Tables;
cboSheet.Items.Clear();
foreach (DataTable table in tableCollection)
cboSheet.Items.Add(table.TableName);
}
}
}
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
The code makes a GUI in .NET framework and it lets you upload an .xls or .xlsx, the Excel file will be shown as a DataGrid view. I implemented a new textbox ( the textBox1_TextChanged(object sender, EventArgs e) method), and based on the user's input, I want to it to display only the rows that correspond with the input. How am I supposed to do that? Thanks in advance!
Upvotes: 1
Views: 139
Reputation: 9804
You have 3 options for working with office formats:
My standing advice is to use the OpenXML way and learn to live without the old formats altogether. They are way more trouble to support then it is worth.
Upvotes: 1