Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

how to excport one excel column from datagridview in C#

$
0
0

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);



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>