Launch libreoffice-calc:
soffice --calc --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"
Launch python shell to write data into the calc:
import uno
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)
context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
svcmgr = context.ServiceManager
desktop = svcmgr.createInstanceWithContext("com.sun.star.frame.Desktop", context)
oDoc = desktop.loadComponentFromURL( "private:factory/scalc","_blank", 0, () )
oSheet = oDoc.getSheets().getByIndex(0)
oRange = oSheet.getCellRangeByName("A1:C3")
Write data into oRange.
oRange.setDataArray((('a1','a2','a3'),('b1','b2','b3'),('c1','c2','c3'),))
The calc's appearance now:
I want to merge all data in oRange and format it with vertical and horizontal alignment.
My desired effect in the editing calc.
oRange.merge()
oCell = oSheet.getCellByPosition(0, 0)
oCell.HoriJustify = 2
oCell.VertJustify = 2
Merged data with vertical and horizontal alignment ,previous data in many cells b1-c1 and a2-c2 and a3-c3 lost.
The real effect.
How to fix my code to get the desired effect?
import uno
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)
context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
svcmgr = context.ServiceManager
desktop = svcmgr.createInstanceWithContext("com.sun.star.frame.Desktop", context)
oDoc = desktop.loadComponentFromURL( "private:factory/scalc","_blank", 0, () )
oSheet = oDoc.getSheets().getByIndex(0)
oRange = oSheet.getCellRangeByName("A1:C3")
tup = (('a1','a2','a3'),('b1','b2','b3'),('c1','c2','c3'),)
oRange.setDataArray(tup)
target =''
for item in tup:
tmp = ' '.join(item)
target = target + tmp + ' '
target = target.strip()
oRange.merge(True)
oCell = oSheet.getCellByPosition(0, 0)
oCell.String = target
oCell.HoriJustify = 2
oCell.VertJustify = 2
I'm not sure, but I think UNO has no way of knowing that you want to rearrange the data into the merged cell that way. What UNO does is "copy" the data from the "main" cell (the top left one) and "paste" its data into the merged cell. Therefore, what you could do is change the data of the main cell before merging. Check the example below.
# get range
oRange = oSheet.getCellRangeByName("A1:C3")
# build string
flat_list = [str(item) for sublist in oRange.getDataArray() for item in sublist]
string = ' '.join(flat_list)
# put string into main cell
main_cell = oRange.getCellByPosition(0, 0)
main_cell.setString(string)
# merge
oRange.merge()
I've been using the following script to run Agent trace reports on call center agents daily for our primary call center site, which has between 40 and 50 agents at any given time. I'm now expanding this reporting to our other sites, having to run the report for 234 agents at a time. I tried setting the loop for the full list of 234 agents, and after the 63rd agent is completed, I get the OLE error.
I've tried adding 'DoEvents" and 'Application.Wait' throughout the code to slow things down a bit and to ensure that the process completes before the next starts , I've also broken up the code from 1 loop of 234 into 4 loops of 60 (the last loop is only 54 for you math junkies), but I'm still getting the OLE error after agent 63 completes.
How can I determine what is causing this OLE error?
Sub CMSConn()
Dim cvsApp As Object
Dim cvsConn As Object
Dim cvsSrv As Object
Dim Rep As Object
Dim Info As Object, Log As Object, b As Object
Dim Agents(234) As String
Dim I As Integer
Set wk = ThisWorkbook
serverAddress = "xxx.xxx.xxx.xxx"
mydate = InputBox("Dates: ")
UserName = InputBox("User ID: ")
passW = InputBox("Password: ")
Agents(1) = "Abcede, Ronaldo"
Agents(2) = "Abella, Poltaqn"
Agents(3) = "Ablen, Armie"
Agents(4) = "Abon, Sherry Lou"
Agents(5) = "Acbang, MaryJane"
Agents(6) = "Acbang, MaryJane"
Agents(7) = "Alcantara, Luis Jaim"
Agents(8) = "Alfaro, Nio"
Agents(9) = "Aman, Sherwin"
Agents(10) = "Amar, Catherine"
Agents(11) = "Amor, Charlie"
Agents(12) = "Anonuevo, Hubert"
Agents(13) = "Antonio, Brian Antho"
Agents(14) = "Antonio, Diana Grace"
Agents(15) = "Aragon, Ramiro"
Agents(16) = "Araullo, Keith"
Agents(17) = "Arevalo, Jerome"
Agents(18) = "Arnel Decano"
Agents(19) = "Arriola, Paulo"
Agents(20) = "Asturias, Sheena"
Agents(21) = "Baguhin, Kathrin May"
Agents(22) = "Balatbat, Lauro"
Agents(23) = "Balena, Nathan"
Agents(24) = "Ballos, Evelyn"
Agents(25) = "Banaban, Nona"
Agents(26) = "Bansale, Jemma"
Agents(27) = "Bautista, Bernie"
Agents(28) = "Bautista, Domingo J"
Agents(29) = "Belen, Michelle"
Agents(30) = "Bicaldo, Catherine"
Agents(31) = "Bonifacio, Allan"
Agents(32) = "Borbon, Danny"
Agents(33) = "Brian Patrick Roxas"
Agents(34) = "Bundalian, Kristel J"
Agents(35) = "Bundalian, Paul"
Agents(36) = "Cabasa, Aidel Joy"
Agents(37) = "Cabauatan, Jacquelin"
Agents(38) = "Caldina, Joanne Nico"
Agents(39) = "Calumpiano, Jean"
Agents(40) = "Camarao, Maria There"
Agents(41) = "Capucao, Daisy"
Agents(42) = "Carpio, Rusell"
Agents(43) = "Caunca, Michael John"
Agents(44) = "Cequeña, Dianne"
Agents(45) = "Chinen, Jeffrey"
Agents(46) = "Chrisgeena Clemeno"
Agents(47) = "Clarin, Marco Leandr"
Agents(48) = "Clauag, Martin Paul"
Agents(49) = "Corbilla. Marcel"
Agents(50) = "Cruz, Cherrimei"
Agents(51) = "Cruz, Geran Judeth"
Agents(52) = "Cruz, Lorreine"
Agents(53) = "Cuaresma Sheila Mari"
Agents(54) = "Cudiamat, Catherine"
Agents(55) = "Cudiamat, Paul"
Agents(56) = "Cueva, Ruthie"
Agents(57) = "Dalida, Rowell"
Agents(58) = "De Guzman, Jennelyn"
Agents(59) = "De Vera, Chris Evert"
Agents(60) = "DeGuzman, Aubrey"
Agents(61) = "DeGuzman, Noel"
Agents(62) = "Del Monte, Mark"
Agents(63) = "Dela Fuente, Herner"
Agents(64) = "Dela Mesa, Randy"
Agents(65) = "Delape Jr., Evelio"
Agents(66) = "10404"
Agents(67) = "Delos Santos, Ervin"
Agents(68) = "Diaz, Jerosalem"
Agents(69) = "Diaz, Leila Ruth"
Agents(70) = "Dicen, Melanie"
Agents(71) = "Dimailig, Kenneth"
Agents(72) = "Dizon, Marc Anthony"
Agents(73) = "Doblas, Leora"
Agents(74) = "Domingo, Rafael"
Agents(75) = "Dulay, Susana Marie"
Agents(76) = "Dy, Jerwin"
Agents(77) = "Elnas, Bernadette"
Agents(78) = "Elnas, Elsha Marie"
Agents(79) = "Enumerable, Gary"
Agents(80) = "Escobal, Aubrey"
Agents(81) = "Escorpion, Genix"
Agents(82) = "Espaldon, Eveleen"
Agents(83) = "Esquivel, Jean Paul"
Agents(84) = "Estabillo,Reygienald"
Agents(85) = "Esteban, Aaron Paul"
Agents(86) = "Esteban, Richard"
Agents(87) = "Fe Marie Jopia"
Agents(88) = "Fermin, Maricris"
Agents(89) = "Fresado, Marie"
Agents(90) = "Gagarin, Wilson"
Agents(91) = "Galero, Roxanne"
Agents(92) = "Gamboa, Aleli"
Agents(93) = "Garcia, Jayson"
Agents(94) = "Garcia, Rey"
Agents(95) = "Garganta, Angelie"
Agents(96) = "Gepolane, Jacinth Ka"
Agents(97) = "Geroche, Raul"
Agents(98) = "Gilera, Erwin"
Agents(99) = "Go, Mark Dexter"
Agents(100) = "Godillo, Albert"
Agents(101) = "Grospe, Noemi"
Agents(102) = "Gualin, Raymond"
Agents(103) = "Guela, Antonette"
Agents(104) = "Guevarra, Randy"
Agents(105) = "Guiang, Mary Paula"
Agents(106) = "Gumera, Diana Corina"
Agents(107) = "Hernandez, Jules"
Agents(108) = "Hora, Gene Patrick"
Agents(109) = "Hu Kwong Man"
Agents(110) = "Iballar, Maria Chris"
Agents(111) = "Ignacio, Florabel"
Agents(112) = "Ilaga, Eunice"
Agents(113) = "Inovero, Michelle"
Agents(114) = "Ismail, Amir"
Agents(115) = "Jaen, Ritchiedel"
Agents(116) = "Jimeno, Evita"
Agents(117) = "Joanne Marie Sai"
Agents(118) = "John Michael Abellar"
Agents(119) = "Julian, Desiree"
Agents(120) = "Justine Joy Lucban"
Agents(121) = "Justiniano, Eufraime"
Agents(122) = "Karen Cathley Digman"
Agents(123) = "Lamparas, Nenita"
Agents(124) = "Laxa, Catherine"
Agents(125) = "Lecoto, Vener"
Agents(126) = "Leuterio, Ilene"
Agents(127) = "Limbo, Karen"
Agents(128) = "Lingad, Raymond"
Agents(129) = "Liza, Joseph Jay"
Agents(130) = "Lomongo, Wilbert"
Agents(131) = "Loreto, Aguilar"
Agents(132) = "Lugtu , Jude"
Agents(133) = "Luzon, Liza"
Agents(134) = "Ma. Eleonor Tabing"
Agents(135) = "Mabborang, Queenly"
Agents(136) = "Mabini, Eve"
Agents(137) = "Macababda, Marijo"
Agents(138) = "Macutay, Charlotte"
Agents(139) = "Macutay, Mark Anthon"
Agents(140) = "Magtangob, Julius"
Agents(141) = "Manago, Roman Carlo"
Agents(142) = "Manaloto, Marlon"
Agents(143) = "Mangaoang, Carmel Ri"
Agents(144) = "Mapolon, Amie"
Agents(145) = "Martin, Maricar"
Agents(146) = "Martin, Sharon"
Agents(147) = "Mendoza, Dann Kristo"
Agents(148) = "Mendoza, Liezl"
Agents(149) = "Mesias, Hannah"
Agents(150) = "Miranda, Nicola Elan"
Agents(151) = "Miranda, Sheila"
Agents(152) = "Mirandilla, Paulo"
Agents(153) = "Mislang Jr., Roberto"
Agents(154) = "Montances, Raquel"
Agents(155) = "Montefalcon, Erliza"
Agents(156) = "Munar, Rommel"
Agents(157) = "Naluz, Alexis Viktor"
Agents(158) = "Narbuada, Norman"
Agents(159) = "Nirza, Miguel"
Agents(160) = "Orteza, Gian Carlo"
Agents(161) = "Oteyza, Karen Rosell"
Agents(162) = "Panganiban, Karina"
Agents(163) = "Panganiban, Leah"
Agents(164) = "Papina, Roland"
Agents(165) = "Parel, Rose Ann Chri"
Agents(166) = "Parra, Nimfa"
Agents(167) = "Pascua, Ramon"
Agents(168) = "Pasuquin, Mary Grace"
Agents(169) = "Pauig, Sue Laine"
Agents(170) = "Perlas, Joby Jade"
Agents(171) = "Poñado, Rachal"
Agents(172) = "Puli, Ivan"
Agents(173) = "Pumar, Elora Ann"
Agents(174) = "Quintos, Stephen Ed"
Agents(175) = "Ramirez, Requel"
Agents(176) = "Ramos, Eumir"
Agents(177) = "Ramos, Rosemarie."
Agents(178) = "Rarangol, Jane"
Agents(179) = "Rebugio, Mark Joseph"
Agents(180) = "Reotutar, Neil Clark"
Agents(181) = "Resurreccion, Aimee"
Agents(182) = "Reyes, Lymuel"
Agents(183) = "Ricafranca, Nikolai"
Agents(184) = "Rino, Kim Eric"
Agents(185) = "Rioja, Daisy"
Agents(186) = "Robidillo, Fatima"
Agents(187) = "Rolando Lindog"
Agents(188) = "Romero, Darling"
Agents(189) = "Rosas, Bryan Carlo"
Agents(190) = "Rowena Rona"
Agents(191) = "Sacrez, Ma Aurora"
Agents(192) = "Sai, Joanna Marie"
Agents(193) = "Salvacion, Fairodz b"
Agents(194) = "Salvador Jr, Rolando"
Agents(195) = "Santibanez, Norman"
Agents(196) = "Santos, Mayleen Sa"
Agents(197) = "Saribay, Mark"
Agents(198) = "Saulog, Giovannie"
Agents(199) = "Seludo, Loida"
Agents(200) = "Sereno, Marjorie"
Agents(201) = "Serrano, Zacheus"
Agents(202) = "Sheremeil Tan"
Agents(203) = "Silverio II, Carlo"
Agents(204) = "Tambobong , Regina"
Agents(205) = "Tan, Boon Beng"
Agents(206) = "Tapia, Dianne Andrea"
Agents(207) = "Tingzon, Jan Therese"
Agents(208) = "Tolentino, Glennford"
Agents(209) = "Tolentino, Rodney"
Agents(210) = "Tolosa, Joy Maru"
Agents(211) = "Tolosa, Rod Jeffrey"
Agents(212) = "Toong, Rene"
Agents(213) = "Torilla, Nathaniel"
Agents(214) = "Tort, Mary Grace"
Agents(215) = "Trinidad, Francis"
Agents(216) = "Tubice, Janette"
Agents(217) = "Tudlasan, Mary Jo"
Agents(218) = "Tuguib, Rodney"
Agents(219) = "Tulawan, Joedelyn"
Agents(220) = "Uy, Gretchen Mari St"
Agents(221) = "Valebia, Kristine"
Agents(222) = "Valenzuela, Demsey"
Agents(223) = "Valenzuela, Myles"
Agents(224) = "Vargas, Christine"
Agents(225) = "Vargas, Jose"
Agents(226) = "Villanueva, Marcelle"
Agents(227) = "Villanueva, Vigie"
Agents(228) = "Villaver, Conrado"
Agents(229) = "Virtudazo, Joeurbett"
Agents(230) = "Viscante, Emelson"
Agents(231) = "Yap, Paul"
Agents(232) = "Ylagan, Celin"
Agents(233) = "Ylidon, Andrew"
Agents(234) = "Yrrverre, Neil Vince"
Set cvsApp = CreateObject("ACSUP.cvsApplication")
Set cvsConn = CreateObject("ACSCN.cvsConnection")
Set cvsSrv = CreateObject("ACSUPSRV.cvsServer")
Set Rep = CreateObject("ACSREP.cvsReport")
For I = 1 To 234
agentName = Agents(I)
If cvsApp.CreateServer(UserName, "", "", serverAddress, False, "ENU", cvsSrv, cvsConn) Then
If cvsConn.login(UserName, passW, serverAddress, "ENU") Then
On Error Resume Next
cvsSrv.Reports.ACD = 1
DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
Set Info = cvsSrv.Reports.Reports("Historical\Agent\Trace by Location")
If Info Is Nothing Then
If cvsSrv.Interactive Then
MsgBox "The Report " & "Historical\Agent\Trace by Location" & " was not found on ACD 1", vbCritical Or vbOKOnly, "CentreVu Supervisor"
DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
Else
Set Log = CreateObject("ACSERR.cvslog")
Log.AutoLogWrite "The Report " & "Historical\Agent\Trace by Location" & " was not found on ACD 1"
Set Log = Nothing
End If
DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
Else
b = cvsSrv.Reports.CreateReport(Info, Rep)
If b Then
Debug.Print Rep.SetProperty("Agent", Agents(I)) ' agentName)
Debug.Print Rep.SetProperty("Dates", mydate)
Debug.Print Rep.SetProperty("Times", "00:00-23:59")
b = Rep.ExportData("", 9, 0, False, True, True)
DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
wk.Sheets(I).Select
wk.Sheets(I).Cells.ClearContents
wk.Sheets(I).Cells(1, 1).PasteSpecial
DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
If Not cvsSrv.Interactive Then cvsSrv.ActiveTasks.Remove Rep.TaskID
Set Rep = Nothing
Set Log = Nothing
Set Rep = Nothing
Set cvsSrv = Nothing
Set cvsConn = Nothing
Set cvsApp = Nothing
Set Info = Nothing
DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
End If
End If
End If
End If
ActiveWorkbook.Save
DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
Next I
cvsConn.logout
cvsConn.Disconnect
cvsSrv.Connected = False
DoEvents
MsgBox "Completed"
End Sub
I have a function to load sounds, but not one for loading images. This is how my image loading is layed out currently:
if os.path.exists("themes/voltorb"):
vgui = pygame.image.load("themes/voltorb/gui.png")
voptions = pygame.image.load("themes/voltorb/options.png")
vachievements = pygame.image.load("themes/voltorb/achievements.png")
voverlay = pygame.image.load("themes/voltorb/overlay.png")
vconfirm = pygame.image.load("themes/voltorb/confirm.png")
vboom = pygame.mixer.Sound("themes/voltorb/boom.mp3")
vcoin = pygame.mixer.Sound("themes/voltorb/coin.mp3")
vtheme = {"gui":vgui,"options":voptions,"achievements":vachievements,"overlay":voverlay,"confirm":vconfirm,"coin":vcoin,"boom":vboom,"music":vmusic}
themedb.update({"v":vtheme})
if os.path.exists("themes/fluttershy"):
fcoin = pygame.mixer.Sound("themes/fluttershy/coin.mp3")
fgui = pygame.image.load("themes/fluttershy/gui.png")
foptions = pygame.image.load("themes/fluttershy/options.png")
fachievements = pygame.image.load("themes/fluttershy/achievements.png")
foverlay = pygame.image.load("themes/fluttershy/overlay.png")
ftheme = {"gui":fgui,"options":foptions,"achievements":fachievements,"overlay":foverlay,"confirm":fconfirm,"coin":vcoin,"boom":vboom,"music":vmusic}
themedb.update({"f":ftheme})
if os.path.exists("themes/mario"):
mgui = pygame.image.load("themes/mario/gui.png")
moptions = pygame.image.load("themes/mario/options.png")
machievements = pygame.image.load("themes/mario/achievements.png")
moverlay = pygame.image.load("themes/mario/overlay.png")
mtheme = {"gui":mgui,"options":moptions,"achievements":machievements,"overlay":moverlay,"confirm":mconfirm,"coin":vcoin,"boom":vboom,"music":vmusic}
themedb.update({"m":mtheme})
if os.path.exists("%appdata%/KWScripts/Voltorb/themes/secret1"):
s1gui = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret1/gui.png")
s1options = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret1/options.png")
s1achievements = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret1/achievements.png")
s1overlay = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret1/overlay.png")
s1theme = {"gui":s1gui,"options":s1options,"achievements":s1achievements,"overlay":s1overlay,"confirm":s1confirm,"coin":vcoin,"boom":vboom,"music":vmusic}
themedb.update({"s1":s1theme})
if os.path.exists("%appdata%/KWScripts/Voltorb/themes/secret2"):
s2gui = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret2/gui.png")
s2options = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret2/options.png")
s2achievements = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret2/achievements.png")
s2overlay = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret2/overlay.png")
s2theme = {"gui":s2gui,"options":s2options,"achievements":s2achievements,"overlay":s2overlay,"confirm":s2confirm,"coin":s2coin,"boom":s2boom,"music":s2music}
themedb.update({"s2":s2theme})
if os.path.exists("%appdata%/KWScripts/Voltorb/themes/secret3"):
s3gui = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret3/gui.png")
s3options = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret3/options.png")
s3achievements = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret3/achievements.png")
s3overlay = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret3/overlay.png")
s3theme = {"gui":s3gui,"options":s3options,"achievements":s3achievements,"overlay":s3overlay,"confirm":s3confirm,"coin":s3coin,"boom":s3boom,"music":s3music}
themedb.update({"s3":s3theme})
I'm not sure if there's any easy way to do this, but I have the most difficult way typed already. If anyone has an idea of how to shorten this, then thanks!
Take all your images and put them in a dict, where the key is the variable you were using, and the value is the path:
vimages = {'vgui': "themes/voltorb/gui.png", 'voptions': "themes/voltorb/options.png", 'vachievements': "themes/voltorb/achievements.png"} # and so on...
Then, iterate through vimages, checking for the existence of each individual file, then calling pygame.image.load() on it, and store the result in your already-existing dict (vtheme, in this case).
This way, you don't need to keep writing out pygame.image.load() over and over again.