如何滚动到SpreadsheetGear WorkBookView控件中的列? [英] How to scroll to column in SpreadsheetGear WorkBookView control?

查看:211
本文介绍了如何滚动到SpreadsheetGear WorkBookView控件中的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每周必须校对30-35个电子表格.

I have to proofread about 30-35 spreadsheets every week.

我需要查看W列和W列右侧的列.当我最初显示电子表格时,我会看到A-P列.我手动滚动到W列,然后开始校对数据.

I need to look at column W and the columns to the right of column W. When I initially display the spreadsheet I see columns A-P. I manually scroll over to column W and begin proofreading the data.

我单击下一步按钮,该按钮将转到下一个文件.我的代码加载了下一个电子表格:

I click on a next button which steps to the next file. My code loads the next spreadsheet:

WorkbookView1.ActiveWorkSheet = Workbook_Obj.ActiveWorksheet.
WorkbookView1.Update()

有时候水平滚动位置保持不变,我可以看到W列和W列右侧的一些列.

Sometimes the horizontal scroll position remains the same and I can see column W and some of the columns to the right of column W.

但是有时水平滚动位置会更改为W列的左侧,而我看不到W列了.

But sometimes the horizontal scroll position changes to the left of column W and I can't see column W anymore.

我会做这样的事情:

' 23 = Column W
Col_Obj = WorkbookView1.Cells(0, 23)
' Or - find column by header text in row = 0.
Col_Obj - WorkbookView1.FindByText("Name")
Col_Obj.HorizontalScroll = Col_Obj.Location

谢谢埃德

推荐答案

您可以设置IWorksheetWindowInfo. ScrollRow属性,以及是否需要设置行滚动位置.

You can set IWorksheetWindowInfo.ScrollColumn (note this property uses a zero-based index, i.e., where Column A is index 0, B is 1, and so on), which will set the leftmost column displayed in the window. Note there is a ScrollRow property as well if you need to set the row scroll position.

当涉及到WorkbookView时(例如您的情况),可能会影响许多其他因素,例如ScrollColumn之类的设置属性是否实际上会在WorkbookView上生效(这与以下事实有关:可以将同一工作表附加到多个WorkbookView控件,并且每个WorkbookView可以保留这些窗口信息"属性的副本.此外,在这方面,SpreadsheetGear 2012和2017的工作方式也存在一些行为差异.下面的代码在大多数情况下应该可以使用,但也希望在您的情况下也可以使用,尽管在某些情况下可能无法使用...例如,如果您使用的是SpreadsheetGear 2017,并且将此工作表附加到多个WorkbookViews上(我猜您不是);但是,如果是这样,我可以更新此答案以更好地适应您的特定情况.

When a WorkbookView is involved, such as in your case, a number of additional factors can come into play as far as whether setting properties such as ScrollColumn will actually take effect on the WorkbookView (this has to do with the fact that you can attach the same worksheet to multiple WorkbookView controls and each WorkbookView can keep its own copy of these "window info" properties). Also, there are some behavioral differences in the way SpreadsheetGear 2012 and 2017 work in this regard. The below code should work in most cases and hopefully yours as well, though it may not in certain circumstances...for instance, if you are using SpreadsheetGear 2017 and attaching this worksheet to multiple WorkbookViews which I'm guessing you're not; but if so, I can update this answer to better accommodate your particular situation.

' Make local variable to the desired worksheet
Dim activeWorksheet = Workbook_Obj.ActiveWorksheet

' Reference cell to select and scroll to
Dim cellW1 = activeWorksheet.Cells("W1")

' Select the cell (this call alone can sometimes also automatically
' trigger the cell to be scrolled to as well, though it may not depending
' on the circumstances; and it may not make this cell the leftmost in the
' window...
cellW1.Select()

' ...to avoid any problems like mentioned above, explicitly set ScrollColumn 
' to the selected cell.  Set ScrollRow as well if desired.
activeWorksheet.WindowInfo.ScrollColumn = cellW1.Column

' Attach workbook *AFTER* doing the above.  For a variety of reasons I
' won't go into, attaching the worksheet before setting the above "window
' info" options may not have any effect.
WorkbookView1.ActiveWorksheet = Workbook_Obj.ActiveWorksheet

这篇关于如何滚动到SpreadsheetGear WorkBookView控件中的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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