Worksheet.get_Range Method

本文介绍如何使用 Worksheet.get_Range 方法获取 Microsoft Office Interop Excel 中的单元格或单元格范围。此方法已被 Range 属性替代,但了解其用法对于理解早期代码或特定需求仍有帮助。

[转自:http://technet.microsoft.com/zh-cn/library/microsoft.office.tools.excel.worksheet.get_range(de-de).aspx]

Worksheet.get_Range Method

Gets a Microsoft.Office.Interop.Excel.Range object that represents a cell or a range of cells. Use the Range property instead of this method.

 

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

 

Syntax

C#:

Range get_Range(
	Object Cell1,
	Object Cell2
)
Parameters
Cell1
Type: System.Object
The name of the range in A1-style notation in the language of the application.It can include the range operator (a colon), the intersection operator (a space), or the union operator (a comma).It can also include dollar signs, but they are ignored.You can use a local defined name in any part of the range.If you use a name, the name is assumed to be in the language of the application.This parameter is required.
Cell2
Type: System.Object
The cell in the lower-right corner of the range.Can be a Microsoft.Office.Interop.Excel.Range that contains a single cell, an entire column, an entire row, or it can be a string that names a single cell in the language of the application.This parameter is optional.
Return Value
Type: Microsoft.Office.Interop.Excel.Range
A Microsoft.Office.Interop.Excel.Range that represents a cell or a range of cells.
.NET Framework Security

.Net Framework Security

转载于:https://www.cnblogs.com/anchenjie007/archive/2013/03/15/2961446.html

METHOD set_title. DATA: lo_worksheets_iterator TYPE REF TO zcl_excel_collection_iterator, lo_worksheet TYPE REF TO zcl_excel_worksheet, lv_rangesheetname_old TYPE string, lv_rangesheetname_new TYPE string, lo_ranges_iterator TYPE REF TO zcl_excel_collection_iterator, lo_range TYPE REF TO zcl_excel_range, lv_range_value TYPE zexcel_range_value, lv_errormessage TYPE string. " Can't pass '...'(abc) to exception-class *--------------------------------------------------------------------* * Check whether title consists only of allowed characters * Illegal characters are: / \ [ ] * ? : --> http://msdn.microsoft.com/en-us/library/ff837411.aspx * Illegal characters not in documentation: ' as first character *--------------------------------------------------------------------* IF ip_title CA '/\[]*?:'. lv_errormessage = 'Found illegal character in sheetname. List of forbidden characters: /\[]*?:'(402). zcx_excel=>raise_text( lv_errormessage ). ENDIF. IF ip_title IS NOT INITIAL AND ip_title(1) = `'`. lv_errormessage = 'Sheetname may not start with &'(403). " & used instead of ' to allow fallbacklanguage REPLACE '&' IN lv_errormessage WITH `'`. zcx_excel=>raise_text( lv_errormessage ). ENDIF. *--------------------------------------------------------------------* * Check whether title is unique in workbook *--------------------------------------------------------------------* lo_worksheets_iterator = me->excel->get_worksheets_iterator( ). WHILE lo_worksheets_iterator->has_next( ) = abap_true. lo_worksheet ?= lo_worksheets_iterator->get_next( ). CHECK me->guid <> lo_worksheet->get_guid( ). " Don't check against itself IF ip_title = lo_worksheet->get_title( ). " Not unique --> raise exception lv_errormessage = 'Duplicate sheetname &'. REPLACE '&' IN lv_errormessage WITH ip_title. zcx_excel=>raise_text( lv_errormessage ). ENDIF. ENDWHILE. *--------------------------------------------------------------------* * Remember old sheetname and rename sheet to desired name *--------------------------------------------------------------------* lv_rangesheetname_old = zcl_excel_common=>escape_string( me->title ) && '!'. me->title = ip_title. *--------------------------------------------------------------------* * After changing this worksheet's title we have to adjust * all ranges that are referring to this worksheet. *--------------------------------------------------------------------* lv_rangesheetname_new = zcl_excel_common=>escape_string( me->title ) && '!'. lo_ranges_iterator = me->excel->get_ranges_iterator( ). "workbookglobal ranges WHILE lo_ranges_iterator->has_next( ) = abap_true. lo_range ?= lo_ranges_iterator->get_next( ). lv_range_value = lo_range->get_value( ). REPLACE ALL OCCURRENCES OF lv_rangesheetname_old IN lv_range_value WITH lv_rangesheetname_new. IF sy-subrc = 0. lo_range->set_range_value( lv_range_value ). ENDIF. ENDWHILE. IF me->ranges IS BOUND. "not yet bound if called from worksheet's constructor lo_ranges_iterator = me->get_ranges_iterator( ). "sheetlocal ranges, repeat rows and columns WHILE lo_ranges_iterator->has_next( ) = abap_true. lo_range ?= lo_ranges_iterator->get_next( ). lv_range_value = lo_range->get_value( ). REPLACE ALL OCCURRENCES OF lv_rangesheetname_old IN lv_range_value WITH lv_rangesheetname_new. IF sy-subrc = 0. lo_range->set_range_value( lv_range_value ). ENDIF. ENDWHILE. ENDIF. ENDMETHOD.
最新发布
08-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值