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

  • Home
  • SEARCH
  • 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 6659507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:02:34+00:00 2026-05-26T02:02:34+00:00

I am a little confounded with Microsoft’s interop Library. It doesn’t seem all that

  • 0

I am a little confounded with Microsoft’s interop Library. It doesn’t seem all that intuitive, and I think if they had just stuck with multidimensional arrays this would have been a much better library. That being said though, I am a little confused about how to write to columns using C#. How would I iterate through a single column and place data into each individual column. Better question, how do I loop through an individual excel column in excel. I am basically attempting to loop through columns and add data to other columns based on the value in the first column. Would I pull all of the data out and put it into some kind of data structure (most likely an array) and then recast it as a Range or something like that? Kind of confused. Here is the code that I use to create new columns that I need to populate with data that I get from other columns in that same row…

    public static void setUpSheet(Worksheet wkSheet)
    {
        Range rng = (Range)wkSheet.get_Range("A1", Type.Missing);
        rng.EntireColumn.Insert(XlInsertShiftDirection.xlShiftToRight,
                                XlInsertFormatOrigin.xlFormatFromRightOrBelow);
        wkSheet.Range["A1", Type.Missing].Value2 = "R_EMPIID";

        Range rng2 = (Range)wkSheet.get_Range("A1", Type.Missing);
        rng2.EntireColumn.Insert(XlInsertShiftDirection.xlShiftToRight,
                                XlInsertFormatOrigin.xlFormatFromRightOrBelow);
        wkSheet.Range["A1", Type.Missing].Value2 = "PopulationID";

        Range rng3 = (Range)wkSheet.get_Range("A1", Type.Missing);
        rng3.EntireColumn.Insert(XlInsertShiftDirection.xlShiftToRight,
                                XlInsertFormatOrigin.xlFormatFromRightOrBelow);
        wkSheet.Range["A1", Type.Missing].Value2 = "PopPatID";

        wkSheet.SaveAs("C:\\CorrectDirectory\\App_Data\\test", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);            
    }

So I can add a new column and name the column, Now I just need to figure out how to get the right data out of other columns and place them in another column in that row (those columns would be the new columns I just created here). Any ideas?

UPDATE: trying to be more specific
I know you can get a range of values in an excel column. But there is no way of knowing how large the dataset is. For example

    (Excel.Range)excelWorksheet.get_Range("A5:A35", Type.Missing);

That would get you a range of columns with data in them. But, lets say you haven’t seen the excel file before hand. How would you loop through ALL of the rows in that column if you don’t know how many rows are in it? Or should you just do a catch all and just do .get_Range(A2:A10000,Type.Missing). And then after that, how would you change the exact same rows but in a different column?

  • 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-26T02:02:35+00:00Added an answer on May 26, 2026 at 2:02 am

    I think the easiest way to deal with the mappings is to create a function to map 0 based integer column to Excel column names: eg. 0, 1, 2, … 26, 27, 28 => A, B, C … AA, AB, AC. (You may or may not need the reverse mapping).

    It’s then pretty easy to create a mapping function between Cell addresses and row/column indexes since you know for any cell address <alpha><numeric> becomes <column><row>.

    It’s a bit of extra work up front that they didn’t provide index based ranges, but if you start doing advanced formulas you’d be doing this mapping anyways.

    —-edited based on updated question—–

    I believe Worksheet.Cells.Width and Worksheet.Cells.Height might be of some use here. It’s possible for a worksheet to contain a lot of empty cells, but it should at least be a starting point.

    Note: I’m looking at version 12 of the type lib, not sure what version you’re on…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Little help needed if possible. I think I'm close just can't quite figure it
Little to say ill just paste my code hoping that someone will see what
My little brother is just getting into programming, and for his Science Fair project,
A little setup: Our shop has a mixture of different platforms. Almost all of
Little new to powershell. I am trying to locate a get-childitem like command that
A little background on the application that I am gonna talk about in the
A little help from you all... I was trying to convert a simple java
little background: currently putting together a website that is selling products, many of which
Little bit of a 2 parter. First of all im trying to do this
After looking around for weeks and being totally confounded by the tutorials that were

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.