473,734 Members | 2,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open-Office ; Python & Win (plain/text)


Open-Office 2.0 bêta-2 français pour Windows (en fait, la 1.9.125 ) est
sortie.
Vous la trouverez là :

http://oootranslation.services.openo...install_fr.zip

Je cite ce lien, car j'ai réussi à piloter Open-Office, depuis Python, avec
PyWin32.
Vous trouverez ci dessous le script expérimental (code "brut" et méchant ;
mais c'est la faisabilité qui importe ici).

Ce script fonctionne avec le fichier Open-office C:\\ootest.odt qui
contient :
---------------------------------------------------------------------
AAAAAAAAAAAA
BBBBBBBBBBB
CCCCCCCCCCC
111%TXT1%111
22222222222222
%CADRE1%
333333333333333
444444444444444 4
Aaz aze ABC djhevgd fude uftyf
ofh efzehiufre hiufre
zefoz hfzr hruifh
ABC ABC gyuguyg ufg eruzyfgerABCABC
efeorzehfzrehiu freh
ABC
---------------------------------------------------------------------


Recréez ce fichier, puis lancez le script ci-dessous.
Ensuite, ben... lisez le code-source, et débrouillez-vous...
---
Michel Claveau
PS : je poste ce message en HTML, puis en plain/text, pour faciliter les
choses.

---------------------------------------------------------------------
# -*- coding: cp1252 -*-

import win32com.client
import time
def insertIntoCell( strCellName, strText, objTable):
objCellText = objTable.getCel lByName( strCellName)
objCellCursor = objCellText.cre ateTextCursor()
objCellCursor.s etPropertyValue ("CharColor",16 777215)
objCellText.ins ertString(objCe llCursor, strText, False)
objServiceManag er = win32com.client .Dispatch("com. sun.star.Servic eManager")
objDesktop = objServiceManag er.CreateInstan ce("com.sun.sta r.frame.Desktop ")

args = []

#si nouveau document, ligne suivante
#objDocument = objDesktop.load ComponentFromUR L("private:fact ory/swriter",
"_blank", 0, args)
"""
//swriter pour le traitement de texte.
//scalc pour le tableur
//sdraw pour l'éditeur de dessin
//simpress pour l'éditeur de présentation (équivalent de PowerPoint)
//smath pour l'éditeur de formule mathématique
//swriter/Global Document document maitre
//swriter/web Pour l'éditeur HTML
"""
#si document existant
objDocument = objDesktop.load ComponentFromUR L("file:///C:/ootest.odt",
"_blank", 0, args)
objText = objDocument.Get Text()
objCursor = objText.createT extCursor()
objText.insertS tring(objCursor , "Vous avez les salutations de PONX.\nCeci
est la deuxième ligne.\n", 0)
objText.insertS tring(objCursor , "Troisième ligne.\n", 0)
objText.insertS tring(objCursor , "4è ligne éèë?@ç.\n\n\n", 0)

# Tableau

#Crée un tableau de 4 colonnes x 4 lignes
objTable= objDocument.cre ateInstance( "com.sun.star.t ext.TextTable")
objTable.IsWidt hRelative = True
objTable.Relati veWidth = 80 # largeur de 80 %
objTable.BackCo lor = 255*256*256+255 *256+204 # fond en jaune clair
objTable.HoriOr ient = 2 # 0 LEFT 1 RIGHT 2 CENTER
objTable.initia lize(8, 4) # lignes / colonnes

#Insère la table
objText.insertT extContent(objC ursor, objTable, 0)

#1ère ligne
objRows = objTable.getRow s()
objRow0 = objRows.getByIn dex(0)

#Couleur de fond
objTable.setPro pertyValue("Bac kTransparent", 0)
objTable.setPro pertyValue("Bac kColor", 255*256*256+255 *256+204)

#Autre couleur de fond, pour la première ligne
objRow0.setProp ertyValue("Back Transparent", 0)
objRow0.setProp ertyValue("Back Color", 6710932)
objRow0.setProp ertyValue("IsAu toHeight", False)
objRow0.setProp ertyValue("Heig ht", 3000) #30 mm

#Remplissage 1ère ligne
insertIntoCell( "A1","FirstColu mn",objTable)
insertIntoCell( "B1","SecondCol umn",objTable)
insertIntoCell( "C1","ThirdColu mn",objTable)
insertIntoCell( "D1","SUM",objT able)

#Remplissage suite
objTable.getCel lByName("A2").s etValue(22.5)
objTable.getCel lByName("B2").s etValue(5615.3)
objTable.getCel lByName("C2").s etValue(-2315.7)
objTable.getCel lByName("D2").s etFormula("sum( <A2>|<B2>|<C2>) ")

objTable.getCel lByName("A3").s etValue(21.5)
objTable.getCel lByName("B3").s etValue(615.3)
objTable.getCel lByName("C3").s etValue(-315.7)
objTable.getCel lByName("D3").s etFormula("sum( <A3:C3>)")

objTable.getCel lByName("A4").s etValue(121.5)
objTable.getCel lByName("B4").s etValue(-615.3)
objTable.getCel lByName("C4").s etValue(415.7)
objTable.getCel lByName("D4").s etFormula("sum ")
#on sélectionne la colonne C
sCell = objTable.create CursorByCellNam e("C1")
sCell.goDown(4, True)
sCell.BackColor = 255*256*256+200 *256+200 #rouge clair

""" ça ne marche pas (spécif OO-2.0 ?)
cols = objTable.getCol umns()
col = cols.getByIndex (2)
"""
#Couleur des caractères et ombre
objCursor.setPr opertyValue("Ch arColor", 255)
objCursor.setPr opertyValue("Ch arShadowed", True)

#Saut de paragraphe
#The second argument is a
com::sun::star: :text::ControlC haracter::PARAG RAPH_BREAK constant
objText.insertC ontrolCharacter (objCursor, 0 , False)

#Insertion texte
objText.insertS tring(objCursor , " Texte coloré - bleu avec ombre\n", False)
#Saut de paragraphe (caractère spécial PARAGRAPH_BREAK = 0).
objText.insertC ontrolCharacter (objCursor, 0, False)
#on repasse en noir, sans ombre
objCursor.setPr opertyValue("Ch arColor", 0)
objCursor.setPr opertyValue("Ch arShadowed", False)
# Attention : ces 4 lignes fonctionnent en invisible.
objText.insertS tring(objCursor , "RRRRRRRRRR R", False)
objCursor.goLef t(3, False)
objCursor.goLef t(5, True)
objCursor.Strin g="+++"
objCursor.gotoE ndOfParagraph(F alse)

#Saut de paragraphe
objText.insertC ontrolCharacter (objCursor, 0, False)

#Création d'un cadre (TextFrame)
objTextFrame= objDocument.cre ateInstance("co m.sun.star.text .TextFrame")
objTextFrame.Wi dth = 10400 # 104 mm largeur
#objTextFrame.H eight =2000 # 20 mm de haut # ne sert à rien, le cadre
d'agrandit tout seul

#Affectation type de cadre (AnchorType.AS_ CHARACTER = 1)
objTextFrame.se tPropertyValue( "AnchorType ", 1)

#insertion du cadre
objText.insertT extContent(objC ursor, objTextFrame, False)

#Lecture du texte du cadre
objFrameText= objTextFrame.ge tText()

#Positionnement curseur interne
objFrameTextCur sor= objFrameText.cr eateTextCursor( )

#Insertion texte
objFrameText.in sertString(objF rameTextCursor, "Encore du
texte\naaaaaaaa aaaa\nbbbbbbb\n ccccc\n", False)
objFrameText.in sertString(objF rameTextCursor, "\net une autre ligne.",
False)
objFrameText.in sertString(objF rameTextCursor, "AAAAAAAA1\ n", False)
objFrameText.in sertString(objF rameTextCursor, "AAAAAAAA2\ n", False)
objFrameText.in sertString(objF rameTextCursor, "AAAAAAAA3\ n", False)
objFrameText.in sertString(objF rameTextCursor, "AAAAAAAA4\ n", False)
objFrameText.in sertString(objF rameTextCursor, "AAAAAAAA5" , False)



#Création d'un cadre (TextFrame)
objTextFrame= objDocument.cre ateInstance("co m.sun.star.text .TextFrame")
objTextFrame.Wi dth = 8000 # 80 mm largeur

objTextFrame.se tPropertyValue( "AnchorType ", 1)

# on va mettre la cadre à la place d'autre chose (remplacement)
och=objDocument .createSearchDe scriptor()
och.SearchStrin g="%CADRE1%"
och.SearchWords = False #mots entiers seulement ?
position=objDoc ument.findFirst (och)
position.String =""
# on remplit le cadre
objText.insertT extContent(posi tion, objTextFrame, False)
objFrameText= objTextFrame.ge tText()
objFrameTextCur sor= objFrameText.cr eateTextCursor( )
objFrameText.in sertString(objF rameTextCursor, "1111111\n" , False)
objFrameText.in sertString(objF rameTextCursor, "2222222222 \n", False)
objFrameText.in sertString(objF rameTextCursor, "333333333" , False)

#couleur texte et sans ombre
objCursor.setPr opertyValue("Ch arColor", 255*256*256+0*2 56+0)
objCursor.setPr opertyValue("Ch arShadowed", False)

#Insertion texte
objText.insertS tring(objCursor , "\n\n\nThat 's all for now !!", False)
#recherche et remplacement
orempl=objDocum ent.createRepla ceDescriptor()
orempl.SearchSt ring="ABC"
orempl.ReplaceS tring="XXXYYYZZ Z"
orempl.SearchWo rds = False #mots entiers seulement ?
orempl.SearchCa seSensitive = True #sensible à la casse ?
nb = objDocument.rep laceAll(orempl)

print "Nb remplacements :",nb
#recherche, effacement et insertion
och=objDocument .createSearchDe scriptor()
och.SearchStrin g="%TXT1%"
och.SearchWords = False #mots entiers seulement ?
position=objDoc ument.findFirst (och)

position.String ="" #remplacement
position.setPro pertyValue("Cha rColor", 255*256*256) #rouge Rouge*256*256 +
Vert*256 + Bleu
#position.goRig ht(1, False)
objText.insertS tring(position, "Texte de remplacement", 0)
objText.insertS tring(position, "Texte ajouté", 0)
#impression, sauvergarde, sortie
objDocument.Pri nt(args)
objDocument.sto reAsURL("file:///C:/ootest2.odt", args)
objDesktop.Term inate()
Sep 1 '05 #1
0 2303

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
11235
by: Marshall Dudley | last post by:
When I do the following line in Netscape, the popup loads as it should, but the parent window usually, but not always, reloads as well. <a href="#" onClick="window.open('/cgi-bin/displayimage.cgi?/store/demo/image.jpg&YOUR+PRODUCT%27<b>S+NAME+GOES', 'fullimage', 'WIDTH=420,HEIGHT=405,status=0')"> The original window should not reload, but is, and I have tested it with both version 4.72 and 7.02, and they both do it. IE does not do it....
10
6756
by: David McCulloch | last post by:
The following code opens a new window, but the "resizeTo" doesn't resize it. Why not? (Don't ask why I simply did not open the window with the new size....my original problem was how to open a new window with maximized dimensions!) FYI, I uploaded the same code to: http://tosasoft.com/test/open.htm ========================================
5
10598
by: Ryan Hubbard | last post by:
Is it possible to get the recordset from an open query window? So you run the query. The window is open. Can vba retrieve this data?
1
2566
by: C Sharp beginner | last post by:
I'm sorry about this verbose posting. This is a follow-up to my yesterday's posting. Thanks William for your reply. I understand it is a good practice to open connections as late as possible and close them as early as possible. My requirement is as follows: I'm developing a class library that will be instantiated by a COM component. My class library contains functions that perform lot of mathematical calculations and read a lot of data...
6
3632
by: Brad | last post by:
I have a win2003 server workstation with multiple webs, each web has it's own ip address. In VS2005, if I select to open an existing web site, select Local IIS, the dialog correctly displays a list of all of my webs, however if I attempt to open a site under and web other than localhost I receive the message: "Unable to open the Web 'http://localhost/anywebappname'. The Web 'http://localhost/anywebappname' does not exist" Obviously...
6
10034
by: qysbc | last post by:
I have a web page and there is a link to open a TIFF file. The way I do it is to have the server code open a binary stream, set the content type to "image/tiff" and call Response.BinaryWrite. On the client machine, the file type TIFF is associated with Kodak Imaging Preview. This app works on most client machines. When you click on the link, Kodak Imaging Preview will open the TIFF file on the client machine. However, on some machines, the...
0
12066
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in '/CinemaBookingSystem' Application. -------------------------------------------------------------------------------- ERROR General error Unable to open registry key 'Temporary (volatile) Jet DSN for process
7
3672
by: anthony.turcotte | last post by:
Hi, I've looked for a solution to this problem on google, read posts in this newsgroup and I still haven't found anything that could help me. Here's the scenario. 1. User accesses pageA.html 2. User clicks on menu link to open popup.html 3. pageA.html checks if popup.html is already open. It is not, open
19
19041
by: =?Utf-8?B?R3JlZw==?= | last post by:
How can I tell via code if a Form is already open. Each time my forms load I have some initialization code that runs, but if the form is already open and hidden I don't want that initialization code to run. Thus, I just want to unhide the form. My thought is eveyrtime I go to load a form I could scan through all the open forms in my project and determine whether the one I'm getting ready to load is open or not.
0
4967
by: Salad | last post by:
A97. Split database. Frontend DB1.MDB. Backend DB1BE.MDB. Tables are linked between DB1 and DB2. From my testing, if I open DB1 exclusively using /excl the backend DB1BE is not opened exclusively. If I open DB1 but have no tables open and then open up DB1BE exclusively, DB1BE will open exclusive. But if I then attempt to open a linked table in the frontend DB1 I'm informed I can't use the table because the file is in use.
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.