简体   繁体   English

使用 OLE,从 OpenOffice/LibreOffice Calc 文档中删除除第一个以外的所有工作表,而不使用工作表名称

[英]Using OLE, remove all sheets except first one from a OpenOffice/LibreOffice Calc document, without using sheet names

From a OpenOffice/LibreOffice Calc document created on code, the idea is to add a sheet as the first one and them remove all others (normally the document comes with 3 sheets).从基于代码创建的 OpenOffice/LibreOffice Calc 文档中,想法是添加一个工作表作为第一个工作表,然后删除所有其他工作表(通常该文档带有 3 个工作表)。

It is using OLE on Windows from a xHarbour language program, but any language is ok if someone knows to do it on whatever language, translation is not a problem.它在 xHarbour 语言程序的 Windows 上使用 OLE,但是如果有人知道使用任何语言,任何语言都可以,翻译不是问题。

I got it working using the Sheet names.我使用工作表名称让它工作。 I think that this should be better using the indexes directly to remove them, but I was unable to do it with indexes only.我认为这应该更好地直接使用索引来删除它们,但是我无法仅使用索引来做到这一点。

The code I got working is:我得到的代码是:

oPlan := oSheetDoc:GetSheets()
oPlan:insertNewByName("My New Sheet", 0)
DO WHILE oPlan:GetCount() > 1
    oPlan:removeByName(oPlan:GetByIndex(oPlan:GetCount()-1):getName())
ENDDO

I think that should be a "remove by index" that I can't find on the online docs from OpenOffice.我认为这应该是我在 OpenOffice 的在线文档中找不到的“按索引删除”。

Anybody knows if is there a way to do it only with indexes, or any way just better than I am doing?任何人都知道是否有办法只使用索引,或者比我做得更好?

According to https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=94494 , sheets can only be removed by name.根据https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=94494 ,只能按名称删除工作表。

oSheets = oDoc.Sheets
aSheetNames() = oSheets.getElementNames()
for iSheet = 1 to ubound(aSheetNames)
    oSheets.removeByName(aSheetNames(iSheet))
next iSheet

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM