0
I am doing a project and need that when opening an (image) it will take the name of this image, save in a variable and show in one of the excel line.
Note: This will be repeated, there will be several files that I will open..
So I know I need to create a foreach to get a new line inserted for every new image I open. Another way is not to save to an array and any image that opens to clear the variable.
Button that opens the image:
private void openFileDialog_FileOk(object sender, CancelEventArgs e)
{
try
{
string[] caminhoImagens = Directory.GetFiles(@"C:\Users\pedroduca\Pictures", "*.jpg");
Path.GetFileNameWithoutExtension(caminhoImagens[0]);
string nomeArquivo = caminhoImagens[0];
NomeImagem.Text = nomeArquivo;
Bitmap image = new Bitmap(openFileDialog1.FileName);
RFiltro1.Text = empty;
RFiltro2.Text = empty;
RFiltro3.Text = empty;
pictureBox1.Image = image;
}
catch (Exception ex)
{
MessageBox.Show($"Erro: {ex.Message}");
}
}
Here is the button to generate excel:
private void button20_Click(object sender, EventArgs e)
{
Excel.Application AbreExcel = new Microsoft.Office.Interop.Excel.Application();
if (AbreExcel == null)
{
MessageBox.Show("O Excel não está instalado corretamente!");
return;
}
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlWorkBook = AbreExcel.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Cells[1, 1] = "Nome do arquivo";
xlWorkSheet.Cells[1, 2] = "Teste 1";
xlWorkSheet.Cells[1, 3] = "Teste 2";
xlWorkSheet.Cells[1, 4] = "Teste 3";
xlWorkSheet.Cells[2, 2] = Lstr_RFiltro1;
xlWorkSheet.Cells[2, 3] = Lstr_RFiltro2;
xlWorkSheet.Cells[2, 4] = Lstr_RFiltro3;
xlWorkSheet.Cells[2, 1] = "**AQUI VAI O NOME DO ARQUIVO NA ARRAY**";
xlWorkBook.SaveAs("C:\\Users\\pedroduca\\Pictures\\TesteCaptcha.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
AbreExcel.Quit();
Marshal.ReleaseComObject(xlWorkSheet);
Marshal.ReleaseComObject(xlWorkBook);
Marshal.ReleaseComObject(AbreExcel);
MessageBox.Show("Excel criado com sucesso! ");
}
Sorry for the misshaping, I’m new to stackoverflow.
But after all what do you want to do? What’s going on? What’s the problem?
– CypherPotato
I wanted to save the name of the files in an array type and that was displayed in a Label. After all I ended up saving the name of the files, I removed the Label and saved in Excel.
– Pedro Duca