首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenOffice pyuno“全选”

OpenOffice pyuno“全选”
EN

Stack Overflow用户
提问于 2011-02-12 06:35:39
回答 2查看 1.3K关注 0票数 5

有人知道如何使用OO uno bridge api在Calc工作表中“全选”吗?

或者,找到使用的最大行数和列数也是可行的。

我想要做的是将格式应用于电子表格中的所有单元格。

(原因是我将工作表另存为csv,因此除非格式提供足够的小数位,否则不会准确地保存数字。)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-04-06 22:23:25

假设您已经连接到OpenOffice,并且document是一个已经打开或创建的电子表格。

代码语言:javascript
复制
#get the sheet you want to work with, I'm just going to grab the first sheet
sheets = document.getSheets().createEnumeration()
sheet = sheets.nextElement()

#start with a range on the first cell
range = sheet.getCellRangeByPosition( 0, 0, 0, 0 )

#expand to full extend of the used area
range.gotoEndOfUsedArea( True ) #true for expand selection

#no do whatever formatting things you want to do
票数 2
EN

Stack Overflow用户

发布于 2014-08-19 22:47:20

我确实收到以下代码行的错误(属性错误):

range.gotoEndOfUsedArea(真)

通过在1:http://nab.pcug.org.au/transferdemo_oocalc.py和2:https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/Cells_and_Ranges上组合这两个信息

我想出了以下解决方案:

代码语言:javascript
复制
def getLastActiveCell(sheet):
    """returns the last used column and row of the provided sheet 
    (ie the last cell in the range containing something other than '')"""
    #create a cursor for the whole sheet using OO interface XSheetCellRange 
    cursor = sheet.createCursor()
    #goto the last used cell
    cursor.gotoEndOfUsedArea(True)
    #grab that positions "coordinates"
    address = cursor.RangeAddress
    endcol = address.EndColumn
    endrow = address.EndRow
    #and pass them back
    return endcol,endrow

然后您可以在代码中访问这些值,如下所示:

代码语言:javascript
复制
lastCell = getLastActiveCell(sheetObject)
print lastCell[0] #Column
print lastCell[1] #Row

并创建一个范围

代码语言:javascript
复制
 range = sheetObject.getCellRangeByPosition( 0, 0, lastCell[0], lastCell[1] )

或者做进一步的工作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4974763

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档