Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand you correctly then when you use say <code>cells[1][2]</code> then it means <code>A2</code> In such a case, Column comes first and then the row. If you write it as <code>cells[1,2]</code> then you will get <code>B2</code>. In this case, Row comes first and then the Column.</p> <p>It's the same in Excel-VBA. <code>?Cells(1)(2).address</code> in immediate window gives <code>$A$2</code> and <code>?Cells(1,2).address</code> gives <code>$B$1</code> If you feel that I have not understood your query then please re-phrase it for me...</p> <p>Here is the complete code to test it.</p> <p><strong>NOTE</strong>: Tested using VS 2010 Ultimate + Excel 2010</p> <pre><code>using System; using System.Windows.Forms; using System.IO; using Excel = Microsoft.Office.Interop.Excel; using System.Reflection; Namespace WindowsFormsApplication1 { public partial class Form1 : Form { Public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Excel.Application xlexcel; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; object misValue = Missing.Value; xlexcel = new Excel.Application(); xlexcel.Visible = true; //~~&gt; Open a File (Change filename as applicable) xlWorkBook = xlexcel.Workbooks.Open("C:\\SomeFile.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); //~~&gt; Set Sheet 1 as the sheet you want to work with xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Excel.Range cells = xlWorkSheet.Cells; Excel.Range topleftCell = cells[1][2]; MessageBox.Show(topleftCell.Address); topleftCell = cells[1,2]; MessageBox.Show(topleftCell.Address); //~~&gt; Once done close and quit Excel xlWorkBook.Close(false, misValue, misValue); xlexcel.Quit(); //~~&gt; CleanUp releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlexcel); } private void releaseObject(object obj) { try { System.Runtime.InteropServices.Marshal.ReleaseComObject(obj); obj = null; } catch (Exception ex) { obj = null; MessageBox.Show("Unable to release the Object " + ex.ToString()); } finally { GC.Collect(); } } } } </code></pre> <p><strong>ScreenShot</strong></p> <p><img src="https://i.stack.imgur.com/Ncajn.png" alt="enter image description here"></p> <p><img src="https://i.stack.imgur.com/xXUx5.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload