how to excport one excel column from datagridview in C#

  • Thread starter Thread starter sara87
  • Start date Start date
S

sara87

Guest


I have excel data as follow:

Project | person | Time | Date

support | A |50 | 2019-10-10

IT | B |1,20 |2019-10-10

debugg | A |30 |2019-10-11

support | c |20 |2019-10-11

support | A |30 |2019-10-12

IT | B | 1.20 |2019-10-12

In my code I can export all excel data from datagridview, how I do to export one column only. I want to export column Project and do sort for every type of project and sum e.g the exported new excel file should be as follow:

2019-10-10 to 2019-10-12

Project | Sum

support | 1.40

IT | 2.40

debugg | 30

Here is my export code. can you help me please.

Thank you for hand.

private void copyAlltoClipboard()
{
dataGridView1.SelectAll();
DataObject dataObj = dataGridView1.GetClipboardContent();
if (dataObj != null)
Clipboard.SetDataObject(dataObj);
}

private void Button4_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);

Continue reading...
 
Back
Top