以编程方式使用C#获取最后充满Excel的一行 [英] Programmatically getting the last filled excel row using C#

查看:230
本文介绍了以编程方式使用C#获取最后充满Excel的一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让编程使用Microsoft.interop.Excel库和C#中的Excel工作表的最后一排。我想这样做,因为我被控通过一个Excel US preadsheet的所有记录循环并对其进行某种操作。具体来说,我需要的最后一排的实际数量,因为我将抛出这个数字到一个函数。任何人有任何想法如何做到这一点?

I am trying to get the last row of an excel sheet programatically using the Microsoft.interop.Excel Library and C#. I want to do that, because I am charged with looping through all the records of an excel spreadsheet and performing some kind of operation on them. Specifically, I need the actual number of the last row, as I will throw this number into a function. Anybody have any idea how to do that?

推荐答案

夫妇方式,

using Excel = Microsoft.Office.Interop.Excel;

Excel.ApplicationClass excel = new Excel.ApplicationClass();
Excel.Application app = excel.Application;
Excel.Range all = app.get_Range("A1:H10", Type.Missing);

Excel.Range last = sheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
Excel.Range range = sheet.get_Range("A1", last);

int lastUsedRow = last.Row;
int lastUsedColumn = last.Column;

这篇关于以编程方式使用C#获取最后充满Excel的一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆