简体   繁体   English

如何获取使用 Interop.Excel 的范围的第一个单元格坐标?

[英]How do I get the first Cell coordinates for a range for using Interop.Excel?

I am working on a small addin for excel for where I work and I need to find the starting position (x and y) for a selected cell range.我正在为我工作的地方为 excel 开发一个小插件,我需要为选定的单元格范围找到起始 position(x 和 y)。

Here is some code:这是一些代码:

using Excel = Microsoft.Office.Interop.Excel;
Excel.Range thisRange = thisSheet.Cells.Application.Selection.SpecialCells(
                             Excel.XlCellType.xlCellTypeVisible,
                             Type.Missing);

where thisSheet is an Excel.Worksheet .其中 thisSheet 是Excel.Worksheet

I can find the number of rows and columns using:我可以使用以下方法找到行数和列数:

int r = thisRange.Rows.Count;
int c = thisRange.Columns.Count;

but I am trying to find the X and Y position of the first cell in the selected range.但我试图找到所选范围内第一个单元格的 X 和 Y position。 Can anyone please help?有人可以帮忙吗? Thanks谢谢

I was able to achieve this by using Range.Row and Range.Column我能够通过使用Range.RowRange.Column来实现这一点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 C# 中使用 interop.excel 检测空白 Excel 单元格 - Detect blank Excel cell using interop.excel in C# 如何使用带有 Interop.Excel 库的 C# 从现有 Excel 文件中获取特定元素? - How to get specific elements from an existing Excel file using C# with the Interop.Excel library? 如何使用Excel Interop获取已过滤行的范围? - How can I get the Range of filtered rows using Excel Interop? C# interop.excel get_range 调用因空引用异常而失败 - C# interop.excel get_range call failing with Null Reference exception 如何检查哪些单元格属于合并单元格并使用 c# Excel Interop 获取合并单元格的值? - How do I check which cells belong to a merged cell and get the merged cell's value using c# Excel Interop? Interop.Excel本地化和Range.Formula与Formulalocal - Interop.Excel localization and Range.Formula vs Formulalocal C#Interop.Excel'#N / A'单元格值转换为-2146826246 - C# Interop.Excel '#N/A' Cell Value converted to -2146826246 c#Interop.excel Range.formula 错误与 VLOOKUP - c# Interop.excel Range.formula error with VLOOKUP 如何使用 C# 中的 interop.excel 从 excel 文件中删除只读模式 - How to remove read-only mode from excel file using interop.excel in C# 如何使用Interop.Excel库从所有Excel工作表中返回单个数据表 - How to return a Single DataTable From All Excel Sheets Using Interop.Excel Library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM