如何通过 COM Interop 获取 Excel 中的特定范围?
我必须通过 COM 互操作读取 Excel 文件。我使用以下方法搜索特定字符串:
this.sheet = (Excel.Worksheet)this.excelApp.Workbook.Sheets.Item[this.sheetname];
this.sheet.Activate();
Excel.Range firstRow = this.sheet.Range["A1", "XFD1"];
Excel.Range foundRange = firstRow.Find(
this.StringISearch,
Type.Missing,
Type.Missing,
Excel.XlLookAt.xlWhole,
Excel.XlSearchOrder.xlByColumns,
Excel.XlSearchDirection.xlNext,
false,
false,
Type.Missing);
现在我想使用foundRange 作为起点来获取另一个范围。
像这样的事情
Excel.Range MyRange = this.sheet.Range[foundRange + 2 rows, + 1 column & lastRow];
我看不出有办法做到这一点。有吗?
I have to read an excel file through a COM interop. I search for a specific string using this:
this.sheet = (Excel.Worksheet)this.excelApp.Workbook.Sheets.Item[this.sheetname];
this.sheet.Activate();
Excel.Range firstRow = this.sheet.Range["A1", "XFD1"];
Excel.Range foundRange = firstRow.Find(
this.StringISearch,
Type.Missing,
Type.Missing,
Excel.XlLookAt.xlWhole,
Excel.XlSearchOrder.xlByColumns,
Excel.XlSearchDirection.xlNext,
false,
false,
Type.Missing);
Now I want to use the foundRange as a starting point to get another range.
Something like this
Excel.Range MyRange = this.sheet.Range[foundRange + 2 rows, + 1 column & lastRow];
I don't see a way to do this. Is there one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,睡了一觉后我找到了答案。
Okay, after some sleep i have found the answer.