7
I would like to know how to get all the content that was passed to a Datagridview and save it in an Excel file. So far I have it:
private void btnDiretorio_Click(object sender, EventArgs e)
{
folderBrowserDialog.RootFolder = Environment.SpecialFolder.DesktopDirectory;
folderBrowserDialog.SelectedPath = openFileDialog.InitialDirectory;
folderBrowserDialog.ShowNewFolderButton = true;
DialogResult result = folderBrowserDialog.ShowDialog();
if (result == DialogResult.OK)
{
List<string> selectedPath = listaArquivos(folderBrowserDialog.SelectedPath);
foreach (string s in selectedPath)
{
grvShowFile.Rows.Add(Path.GetFileName(s), s);
}
}
}
This code is from a button that selects all files in a directory and its subfolders. Note that Datagridview is being filled normally.
private void btnPesquisar_Click(object sender, EventArgs e)
{
if (this.cboParametro.Text == "" || this.cboParametro.Text == "Ola"){
MessageBox.Show("Parametro inválido, por favor tente novamente.");
}
string[] arrayParam = { "FROM", "SELECT", "WHERE", "UPDATE", "" };
//Dictionary<string, string> getParam = new Dictionary<string, string>();
//getParam.Add("FROM", "WHERE");
//getParam.Add("SELECT", "Private");
StreamReader DirectorySR = new StreamReader(folderBrowserDialog.SelectedPath);
while (!DirectorySR.EndOfStream)
{
string read = DirectorySR.ReadToEnd();
DirectorySR.Close();
}
}
This is where I am losing myself, this button needs to receive a parameter that will be passed by the user ( OK! ) and then load the files that were passed in Datagridview ( That’s where I’m not being able to continue ) and read file by file passing that array that was created with the specific words.
I’m a beginner in C# and I can’t continue this part.
your question is a little confused, can not understand exactly what you need, you speak of saving the content of
DataGridView
in an Excel file and then in the code, implies that you want to do a search in the files that are in theDataGridView
using thearrayParam
, take a look at [Ask] and adjust your question– mateusalxd
Rodolfo, also not understood if you want to export the contents of the grid to excel or want to open a file.
– Alexandre Soares Machado