Last active
September 7, 2023 06:51
-
-
Save ebubekirbastama/313c3e9c841c50d8c9575e7a4defa8ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void excellaktar() | |
{ | |
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application | |
{ | |
Visible = true | |
}; | |
object Missing = Type.Missing; | |
Workbook workbook = excel.Workbooks.Add(Missing); | |
Worksheet sheet1 = (Worksheet)workbook.Sheets[1]; | |
int StartCol = 1; | |
int StartRow = 1; | |
for (int j = 0; j < dataGridView1.Columns.Count; j++) | |
{ | |
Range myRange = (Range)sheet1.Cells[StartRow, StartCol + j]; | |
myRange.Value2 = dataGridView1.Columns[j].HeaderText; | |
} | |
StartRow++; | |
for (int i = 0; i < dataGridView1.Rows.Count; i++) | |
{ | |
for (int j = 0; j < dataGridView1.Columns.Count; j++) | |
{ | |
Range myRange = (Range)sheet1.Cells[StartRow + i, StartCol + j]; | |
myRange.Value2 = dataGridView1[j, i].Value == null ? "" : dataGridView1[j, i].Value; | |
myRange.Select(); | |
} | |
} | |
// Dosyayı belirli bir konuma kaydet | |
string dosyaYolu = System.Windows.Forms.Application.StartupPath + "\\EBSCikti.xlsx"; | |
workbook.SaveAs(dosyaYolu); | |
workbook.Close(); | |
excel.Quit(); | |
Marshal.ReleaseComObject(sheet1); | |
Marshal.ReleaseComObject(workbook); | |
Marshal.ReleaseComObject(excel); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment