none
Export data from datagridview to excel based on specific values RRS feed

  • Question

  • I wasn't sure exactly how to word this when searching online and in the forums for help, so I apologize if this has been repeated in another thread...

    I need to export specifc values from a datagridview to excel. Now I already know how to export the entire contents of the datagridview into an excel spreadsheet, but this situation (at least for me) is a bit different:

    The datagridview is setup similar to this:

    ITEM ZONE DETAIL METHOD VALUE
    1 A DIA VISUAL 8
    2 A LENGTH VISUAL 36
    3 B RAD VISUAL 2.5
    4 C PERPEND VISUAL 6
    5 C DIA VISUAL 9

     

    I have a spreadsheet setup similar to this:

    Data Descrip Data Val
    DIAMETER X 9
    PERPENDICULAR 6
    RADIUS 2.5
    DIAMETER Y 8
    LENGTH 36

     

    One would assume that I could just use the Item column from the datagridview as a reference to grab the correct value to be inserted into the Data Val column of the spreadsheet. However, we can't always assume that the data given to us from our vendor will be in that same order (this data is already imported into the datagridview).

    As a result, I have found that the ZONE and DETAIL fields form unique identifiers for the specific values needed. Now, the form on the spreadsheet will always be in the same order as it is our own form.

    My question is this: Is there a way to export data from the VALUE column in the datagridview based on values from the ZONE and DETAIL fields?

    Thanks to any and all who respond!!


    Join the darskide. We have cookies!

    Tuesday, January 7, 2014 10:56 PM

Answers

  • I thought about this question some more today before coding and realized that this might be the path I would have to take.

    Thanks for the reply anyway!

    EDIT:

    So I ended up using a series of IF THEN statements and manually assigned values as you said (ie. if colA = X and colB = Y then value = Z). It was a bit tedious, but I have my code in separate sub to handle this.  If I need to make future changes, they're more accessible for me.

    Again thanks for the response...
    P.S. If someone would like to see a sample of the code I used for help, I can post it...


    Join the darskide. We have cookies!


    • Edited by Darth Probius Tuesday, January 14, 2014 2:41 PM Updated information
    • Marked as answer by Darth Probius Wednesday, January 15, 2014 4:15 PM
    Thursday, January 9, 2014 4:31 PM

All replies

  • Hi Darth,

    You need to work with Excel objects and set the values in the code manually. There is no helpers for your task.  

    Thursday, January 9, 2014 12:55 PM
  • I thought about this question some more today before coding and realized that this might be the path I would have to take.

    Thanks for the reply anyway!

    EDIT:

    So I ended up using a series of IF THEN statements and manually assigned values as you said (ie. if colA = X and colB = Y then value = Z). It was a bit tedious, but I have my code in separate sub to handle this.  If I need to make future changes, they're more accessible for me.

    Again thanks for the response...
    P.S. If someone would like to see a sample of the code I used for help, I can post it...


    Join the darskide. We have cookies!


    • Edited by Darth Probius Tuesday, January 14, 2014 2:41 PM Updated information
    • Marked as answer by Darth Probius Wednesday, January 15, 2014 4:15 PM
    Thursday, January 9, 2014 4:31 PM