Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4538938
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:52:40+00:00 2026-05-21T14:52:40+00:00

I am sure this is quite simple but I cannot seem to get this

  • 0

I am sure this is quite simple but I cannot seem to get this right.
I have a built up a ICollection of Users. This collection could have 1 or many.
I now want to loop through this collection and assign a variable to each user that I can then use to fill in a spread sheet.

At present I have this code :

    string username = null;

        foreach (var user in dailyReport)
        {
             username = user.UserName;
        }

        Cell cell= worksheet.Cells["B5"];
        cell.PutValue(username);

Now obviously this just puts the last user of the collection into cell B5!
How do I collect all user.UserNames so I can place them in B5, B6, B7 and so on????

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:52:41+00:00Added an answer on May 21, 2026 at 2:52 pm

    You need to put the value inside the foreach loop. The specific thing you are asking for–getting a different variable for every value in the collection–is not possible, and isn’t what you want anyway.

    string column = "B"; // or whatever your column is
    int row = 1; // or whatever your starting value is
    
    foreach (var user in dailyReport)
    {
        string username = user.UserName;
        string cellAddress = String.Format("{0}{1}", column, row);
        Cell cell = worksheet.Cells[cellAddress];
    
        cell.PutValue(username);
    
        row++; // make sure to increment the row, or every username goes in the same cell
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im sure this will be a simple one but have a project that started
I'm sure this is simple but I can't quite find out how to do
I'm sure this is quite simple but I can't find the answer. I'm passing
I'm not quite sure how this happened, but somehow a completely empty hierarchy of
I'm sure this is easy but I can't figure it out: I have an
I'm not quite sure how to phrase this, so bear with me. I have
I'm not quite sure if this is possible, or falls into the category of
I'm not quite sure if this is specific to Sun Java Systems Application Server
Not quite sure how to troubleshoot this. I'm maintaining an ASP site, its mostly
Pretty sure this question counts as blasphemy to most web 2.0 proponents, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.