try { //Excel objektumok létrehozása Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkBook = xlApp.Workbooks.Add(); Excel.Worksheet xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); xlApp.DisplayAlerts = false; //Fejléc feltöltése for (int i = 0; i < dataGridView2.Columns.Count; i++) { xlWorkSheet.Cells[1, i + 1] = dataGridView2.Columns[i].HeaderText; } //Cellák feltöltése for (int i = 0; i < dataGridView2.Rows.Count; i++) { for (int j = 0; j < dataGridView2.Columns.Count; j++) { xlWorkSheet.Cells[i + 2, j + 1] = dataGridView2.Rows[i].Cells[j].Value; } } //Formázás, pénznem formátumra for (int i = 0; i < dataGridView2.Rows.Count; i++) { ((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[i + 2, 8]).NumberFormat = ## 000 Ft; } //Mentés elvégzése, a létezés ellenÅ‘rzésével Directory.CreateDirectory(c:nev); DateTime ma = DateTime.Now; String filenev = c:nevnev_ + ma.Year + _ + ma.Month + _ + ma.Day + _ + comboBox1.Text + _ + (int)numericUpDown1.Value + _ + (int)numericUpDown2.Value + .csv; if (!File.Exists(filenev)) { xlWorkBook.SaveAs(filenev); } else { if (MessageBox.Show(Van már ilyen fájl felülÃrjam?, , MessageBoxButtons.YesNo) == DialogResult.Yes) { xlWorkBook.SaveCopyAs(filenev); } } xlWorkBook.Close(); xlApp.Quit(); MessageBox.Show(Ezen az elérési úton találod meg: + Environment.NewLine + c:tanarok); } catch (Exception ex) { MessageBox.Show(Hiba az exportálás során! + ex); } INSERT INTO javitasok ( szerelo_id , autos_id , datum , javido , iranyar ) VALUES ((select szerelo_id from autojavitas.szerelok where nev=` + comboBox1.Text + `),(select autos_id from autojavitas.autosok where nev =` + comboBox2.Text + `),` + sanyi + `, ` + numericUpDown2.Value + `, ` + numericUpDown1.Value + `);
©