Posts

How to add excel with header to DataGridView C# Visual Studio

private void button1_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); string file = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); ofd.FileName = ""; ofd.Title = "Choose a Document..."; ofd.AddExtension = true; ofd.FilterIndex = 0; ofd.Multiselect = false; ofd.ValidateNames = true; ofd.InitialDirectory = file; ofd.RestoreDirectory = true; if (ofd.ShowDialog() == DialogResult.OK) { BindingSource bs = new BindingSource(); //add columns to the dgv dgv_data_baru.Columns.Add("column_one", "column one"); dgv_data_baru.Columns.Add("column_two", "column_two"); Microsoft.Office.Interop.Excel.Application application = new Microsoft.Offi...

How to export data from DataGridView to Excel including header as column C# Visual Studio

//you can change dgv_data_baru to your own DataGridView name //put these using above the class but first you have to import the referrence, there are many easy guides about it on google using Microsoft.Office.Interop.Excel; using _Excel1 = Microsoft.Office.Interop.Excel; using System.IO; private void ImportDataGridViewDataToExcelSheet() { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Excel Documents (*.xls)|*.xls"; sfd.FileName = "Inventory_Adjustment_Export.xls"; if (sfd.ShowDialog() == DialogResult.OK) { _Excel1.Application xlexcel = new _Excel1.Application(); _Excel1.Application xlApp; _Excel1.Workbook xlWorkBook; _Excel1.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlApp = new _Excel1.Application(); xlWorkBook = xlApp.Workbooks.Add(misValue...