1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| # coding: utf-8
from __future__ import unicode_literals
import uno
import os
from com.sun.star.beans import PropertyValue
from com.sun.star.awt.MessageBoxType import MESSAGEBOX, INFOBOX, ERRORBOX, WARNINGBOX, QUERYBOX
from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK
try:
CTX = uno.getComponentContext()
SM = CTX.getServiceManager()
desktop = XSCRIPTCONTEXT.getDesktop()
ODOC = desktop.getCurrentComponent()
parentwin = ODOC.CurrentController.Frame.ContainerWindow
dispatcher = SM.createInstanceWithContext("com.sun.star.frame.DispatchHelper", CTX)
model = desktop.getCurrentComponent()
except:
print("ModulePython init Error")
def extraireTout(*args):
dossierSrc = r"D:\temp\dossier_a"
dossierDest = r"D:\temp\dossier_b"
for name in os.listdir(dossierSrc):
ficSrc = os.path.join(dossierSrc,name )
ficDest = os.path.join(dossierDest, name.replace('fichier','extract') )
print(ficSrc,ficDest)
extraction(ficSrc,ficDest)
MsgBox("fin d'extraction")
def extraction(ficSrc,ficDest):
ongletSrc = "Feuille1"
ongletDest = "Feuille1"
urlSrc = uno.systemPathToFileUrl(ficSrc)
urlDest = uno.systemPathToFileUrl(ficDest)
args = (PropertyValue(Name='Hidden', Value=True),)
docSrc = desktop.loadComponentFromURL(urlSrc, '_default', 0, args)
oFeuilleSrc = docSrc.getSheets().getByName(ongletSrc)
scc = oFeuilleSrc.createCursor()
scc.gotoStartOfUsedArea(False)
scc.gotoEndOfUsedArea(True)
oAddr = scc.getRangeAddress()
oDataSrc = oFeuilleSrc.getCellRangeByPosition(oAddr.StartColumn,oAddr.StartRow,
oAddr.EndColumn,oAddr.EndRow).getDataArray()
docSrc.close(0)
oFeuilleDest = ODOC.getSheets().getByName(ongletDest)
rngUtil = oFeuilleDest.getCellRangeByPosition(oAddr.StartColumn,oAddr.StartRow,
oAddr.EndColumn,oAddr.EndRow)
rngUtil.setDataArray(oDataSrc)
ODOC.calculateAll()
args = (PropertyValue(Name='FilterName', Value='Calc MS Excel 2007 XML'),)
ODOC.storeToURL(urlDest, args)
rngUtil.clearContents(7)
def MsgBox(message, titre="Message", boxtype='message', boutons=BUTTONS_OK):
types = {'message': MESSAGEBOX, 'info': INFOBOX, 'error': ERRORBOX,
'warn': WARNINGBOX, 'query': QUERYBOX}
tk = SM.createInstanceWithContext("com.sun.star.awt.Toolkit", CTX)
box = tk.createMessageBox(parentwin, types[boxtype], boutons, titre, message)
return box.execute()
g_exportedScripts = extraireTout, |
Partager