如何复制由 AutoFilter() 方法过滤的行
到目前为止,我一直在使用 AutoFilter() 方法,没有任何问题。但我无法标记或获取过滤行的范围,以计算/复制/删除它们。
我看过很多关于 VBA 问题的帖子,但没有看到关于 C# 的帖子。
过滤后,我尝试通过以下任何一行来获取范围:
range = ws.UsedRange.CurrentRegion.SpecialCells(Excel.XlCellType.xlCellTypeVisible, missing);
range = ws.AutoFilter.Range.SpecialCells(Excel.XlCellType.xlCellTypeVisible, missing);
range = ws.Cells.SpecialCells(Excel.XlCellType.xlCellTypeVisible, missing);
我什至尝试了其他我什至不记得的方法。
标记范围后,我尝试通过执行以下操作来计算行数:
range.Rows.Count
在每种情况下,我都得到了工作表的总行数,有时我得到 65536 (office 2003),有时只有 1,但肯定不是我想要的行数过滤。
我必须将它与带有对象库 11 的 Office 2003 一起使用。
I've been using the AutoFilter() method with no problem so far. but I wasn't able to mark or get the range of the filtered rows, to count/copy/delete them.
I've seen many posts on this issue with VBA, but none for C#.
After filtering, I tried to get the range by any of these lines:
range = ws.UsedRange.CurrentRegion.SpecialCells(Excel.XlCellType.xlCellTypeVisible, missing);
range = ws.AutoFilter.Range.SpecialCells(Excel.XlCellType.xlCellTypeVisible, missing);
range = ws.Cells.SpecialCells(Excel.XlCellType.xlCellTypeVisible, missing);
And I have even tried other ways that I dont even remember.
After marking the range I tried to count the rows by doing:
range.Rows.Count
and in each case, I got the total number of lines of the sheet, sometimes I got 65536 (office 2003) and sometimes just 1 but surely not the number of rows that I filtered.
I must use it with office 2003 with Object Library 11.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的。经过长时间的睡眠。我有一些力量尝试更多的方向,这一次没有从其他论坛和谷歌获得方向。
试试这个:
(这将根据第 1 列以 criteriaString 作为条件过滤行)
filteredRange.Rows.Count
整数来计算行数,并做一些有趣的事情。就是这样!它必须比我想象的简单。
谢谢
Ok. after a long sleep. i got some power to try more directions, this time without getting directions from other forums and google.
Try this:
(this will filter the rows according to column 1 with criteriaString as the criteria)
filteredRange.Rows.Count
integer to count the rows, and do fun stuff.THATS IT! it had to be simple then i ever thought it would.
Thanks
对于删除行,只需
range.Delete(Microsoft.Office.Interop.Excel.XlDeleteShiftDirection.xlShiftUp);
For deleting the rows , it is just
range.Delete(Microsoft.Office.Interop.Excel.XlDeleteShiftDirection.xlShiftUp);
自动过滤后,我想仅在过滤行的“N”范围内命名术语“COGI”。如何编写以仅选取该范围“N”并插入术语“COGI”
after autofilter, i would like to name a term "COGI" only in range "N" in the filtered rows.how to write to just pick up that range "N" and insert a term "COGI"