none
Linq to Excel.... RRS feed

  • Question

  •  I'm interested in VSTO & LINQ. I'm studying LINQ to excel.

    To cut the length of the source, I posted up a simple source about LINQ to excel.

     private void button1_Click_1(object sender, EventArgs e)
    
      {
    
       List<Excel.Range> str = new List<Excel.Range>();
    
       int x = this.UsedRange.Rows.Count;
    
       int y = this.UsedRange.Columns.Count;
    
    
    
       for (int i = 1; i <= x; i++)
    
       {
    
        str.Add(this.Range["a" + i, "a" + y]);     
    
       }
    
       
    
       var q = from c in str
    
         //where c[missing, 1].Value2 == "test" 
    
         where c[missing,1].Text == "test"
    
         select c;
    
    
    
    
    
       Excel.Range rng = this.Range["a10", missing];
    
    
    
       int rowX = 1;
    
       foreach (Excel.Range r in q)
    
       {
    
        rng.get_End(Excel.XlDirection.xlToLeft).get_Resize(rowX, y).Value2 = r.get_Resize(1, y).Value2;
    
        rowX++;
    
       }
    
      }
    
    
    It’s very difficult to get help in Korea since Korean developers are not much interested in VSTO, till now.

    So I posted up what I’ve been thinking. And please give me advice whether the source I posted is right or not.

    If you have the time, please visit to the category of VSTO on my blog and advise about the source posted.

    http://vsto.tistory.com/entry/VSTO-Tip-Linq-to-Excel


    http://vsto.tistory.com



    Monday, April 11, 2011 10:29 AM

Answers

  • Hi VSTO_Beginner,

    I tested your code and it works well. This code snippet can copy values from A10 based on the UsedRanged data's each column.If the column contains a cell with text "test", it will add this row to q, and output q from A10.

    Thank you for sharing us your code and website.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by VSTO_Beginner Thursday, April 14, 2011 12:42 PM
    Thursday, April 14, 2011 7:42 AM

All replies

  • Hi VSTO_Beginner,

    I tested your code and it works well. This code snippet can copy values from A10 based on the UsedRanged data's each column.If the column contains a cell with text "test", it will add this row to q, and output q from A10.

    Thank you for sharing us your code and website.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by VSTO_Beginner Thursday, April 14, 2011 12:42 PM
    Thursday, April 14, 2011 7:42 AM
  • Thank you for your reply. I've been studying this part constantly and I'll try to build better source.
    Thank you.


    http://vsto.tistory.com
    Thursday, April 14, 2011 12:41 PM