I am working to this part and this is my process so far, please help me.
private void copyAlltoClipboard()
{
G2.SelectAll();
DataObject dataObj = G2.GetClipboardContent();
if (dataObj != null)
Clipboard.SetDataObject(dataObj);
}
private void btn_export_Click(object sender, EventArgs e)
{
copyAlltoClipboard();
Microsoft.Office.Interop.Excel.Application xlexcel;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlexcel = new Excel.Application();
xlexcel.Visible = true;
xlWorkBook = xlexcel.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
Excel.Range CR = (Excel.Range)xlWorkSheet.Cells[1, 1];
CR.Select();
xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true);
}
So this is the code, It will export the datagridview to excel ( but without Header text, and I need to export with header text also). And for all the textboxes above, I also want them to export to the Excel, How can I do it?
I forgot to mention, these textboxes and readonly and is called from another form from data table, not for input.