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 6970673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:44:24+00:00 2026-05-27T16:44:24+00:00

I am programatically building an Excel spreadsheet in C# (joy!) and I am seeing

  • 0

I am programatically building an Excel spreadsheet in C# (joy!) and I am seeing bizarre behaviour in the Range.Top property.

I am building a network diagram (please don’t ask why I’m using Excel, but know that it wasn’t my decision and it cannot change) so many of the cells (nodes) are connected by lines (arcs) which are being drawn using Worksheet.Shapes.addLine(...). Unfortunately many of my arcs do not join up very well with my nodes.

Each time I add a node to the diagram (by filling a cell’s value with the node ID) I query its position so that I can calculate its center and use that as a line anchor point.

In one example I have seen when debugging I add two nodes, 1 at cell C3 and 2 at E3. For each cell the Range.Top property gives a different number!

Range cell = ws.Cells[3, 3];    // y (rows) before x (cols)
node.renderSmallerX = Convert.ToDouble(cell.Left);  // e.g. 100
node.renderSmallerY = Convert.ToDouble(cell.Top);   // e.g. 100
node.renderLargerX = node.renderSmallerX + Convert.ToDouble(cell.Width);    // e.g. 130
node.renderLargerY = node.renderSmallerY + Convert.ToDouble(cell.Height);   // e.g. 115

// ... (next loop)

Range cell = ws.Cells[3, 5];
node.renderSmallerX = Convert.ToDouble(cell.Left);  // e.g. 100
node.renderSmallerY = Convert.ToDouble(cell.Top);   // e.g. 114.25
node.renderLargerX = node.renderSmallerX + Convert.ToDouble(cell.Width);    // e.g. 130
node.renderLargerY = node.renderSmallerY + Convert.ToDouble(cell.Height);   // e.g. 129.25

I have read the manual and the measurement is to the top of the row, and in no way related to its content, so I see NO REASON why the property should change here.

I am so annoyed with this issue that I am now going to iterate over all required columns and rows first to create dictionaries of coordinates, rather than querying the position of cells as they are used, so that at least if they’re wrong they’re all wrong in the same way.

Can any Excel gurus explain this very odd outcome, or show me where I’m causing the problem? Many thanks.

EDIT: Should have mentioned – .NET v4, Microsoft.Office.Interop.Excel v11

  • 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-27T16:44:25+00:00Added an answer on May 27, 2026 at 4:44 pm

    I tried to simulate your problem in Excel 2003 by running the following code on a key press at various cells

    Sub GetCoord()
    Dim R1 As Range, R2 As Range
    
        Set R1 = Selection
        Set R2 = Selection.Cells(1, 1)
    
        MsgBox "T/L/W/H:" & vbCrLf & _
               R1.Top & "/" & R1.Left & "/" & R1.Width & "/" & R1.Height & vbCrLf & _
               R2.Top & "/" & R2.Left & "/" & R2.Width & "/" & R2.Height
    
    End Sub
    

    I didn’t find .Top to be different for cells in the same row, allthough I experimented with .VerticalAlignment and boxes around the ranges with various line thicknesses.

    With various line thicknesses on at least one of the cells the .Top changes – but in sync for both cells. With different line thickness for both cells both .Top go with the thicker line.

    One more difference between R1 and R2 in my MsgBox can be seen for merged cells: R1.Height reports total height whereas R2.Height reports the height of the first cell only.

    Not an answer, but maybe an inspiration for you where to look next.

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

Sidebar

Related Questions

How does one go about programatically building a TemplateColumn object and adding it to
See the chart below. I'm building the chart programatically, so no asp.net control syntax
I'm building a program, and I'm quite confident using Objective-C, but I don't know
I have a large spreadsheet in Excel 2007 OpenXML format that I want to
I am building an app that needs to dynamically/programatically know of and use different
I am building an XML string programatically using the XmlWriter ... sb = New
I'm building an application that accepts credit card orders, but does not programatically authorize
I have a map of a building and I'd like to programmatically highlight specific
I programatically create an NSToolbar in my application. I just added a new button
I want to programatically create an NSTextView. How can I determine the correct frame

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.