<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
Calc documents implement the following service:<br>
<br>
com.sun.star.sheet.SpreadsheetDocument<br>
<br>
Using that with the examples below based on a write document:<br>
<br>
<br>
'******************************************************************************************<br>
'// Count the total number of open componets.<br>
'// This includes all document types as well<br>
'// as things such as the Basic IDE and help windows.<br>
'******************************************************************************************<br>
Function numberOfOpenComponents As Integer<br>
Dim i As Integer<br>
Dim oDocs<br>
Dim oDoc<br>
i = 0<br>
<br>
oDocs = StarDesktop.getComponents().createEnumeration()<br>
Do While oDocs.hasMoreElements()<br>
oDoc = oDocs.nextElement()<br>
i = i + 1<br>
Loop<br>
numberOfOpenComponents = i<br>
End Function<br>
<br>
'******************************************************************************************<br>
'// Count number of open Write documents. <br>
'******************************************************************************************<br>
Function countOpenWriteDocs() As Integer<br>
countOpenWriteDocs =
countTypedComponents("com.sun.star.text.TextDocument")<br>
End Function<br>
<br>
'******************************************************************************************<br>
'// Count number of documents that are open with the specified
service type.<br>
'******************************************************************************************<br>
Function countTypedComponents(serviceName$) As Integer<br>
Dim i As Integer<br>
Dim oDocs<br>
Dim oDoc<br>
i = 0<br>
<br>
oDocs = StarDesktop.getComponents().createEnumeration()<br>
Do While oDocs.hasMoreElements()<br>
oDoc = oDocs.nextElement()<br>
If oDoc.supportsService(serviceName) Then<br>
i = i + 1<br>
End If<br>
Loop<br>
countTypedComponents = i<br>
End Function<br>
<br>
'******************************************************************************************<br>
'// Return true if the specified document is a Write document.<br>
'******************************************************************************************<br>
Function isWriteDocument(oDoc) As Boolean<br>
If IsNull(oDoc) Then<br>
isWriteDocument = False<br>
ElseIf IsEmpty(oDoc) Then<br>
isWriteDocument = False<br>
ElseIf oDoc.supportsService("com.sun.star.text.TextDocument")
Then<br>
isWriteDocument = True<br>
Else<br>
isWriteDocument = False<br>
End If<br>
End Function<br>
<br>
<br>
<br>
<br>
<div class="moz-cite-prefix">On 06/07/2015 09:21 PM, Zhang, William
wrote:<br>
</div>
<blockquote
cite="mid:BY2PR05MB19279A75C691291FBD18FA83B4BF0@BY2PR05MB1927.namprd05.prod.outlook.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"\@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
{mso-style-priority:99;
mso-style-link:"Plain Text Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:10.5pt;
font-family:"Calibri","sans-serif";}
span.PlainTextChar
{mso-style-name:"Plain Text Char";
mso-style-priority:99;
mso-style-link:"Plain Text";
font-family:"Calibri","sans-serif";}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
/* Page Definitions */
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoPlainText"><span lang="EN-US">Hi Andrew,<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">Thanks a lot for your
reply.<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">Q1: In your case do
you only care about documents that have been saved...
Ignoring new never saved to disk docs?<o:p></o:p></span></p>
<p class="MsoPlainText"><span style="font-family:Wingdings"
lang="EN-US">à</span><span lang="EN-US">What I want to get
is all calc documents as long as the doc is opened, no
matter it have been saved or not.<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"> So firstly, I want
to know if it</span><span style="font-family:"Courier
New"" lang="EN-US">’</span><span lang="EN-US">s
possible to do it in this case. If no, maybe I can only care
the doc which have been saved and ignore which is not saved.<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">Q2: You enumerate the
open components from the desktop object and check of the
component is a calc document.<o:p></o:p></span></p>
<p class="MsoPlainText"><span style="font-family:Wingdings"
lang="EN-US">à</span><span lang="EN-US">Sorry, I know how to
get the desktop object, but I am not clear how to get the
open component and check them as you mentioned.<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"> This is my gap,
would you please give example code based on my comment for
Q1?<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">Thanks in advanced!<br>
<br>
<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">Best Regards<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">William<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">-----Original
Message-----<br>
From: Andrew Pitonyak [<a class="moz-txt-link-freetext" href="mailto:andrew@pitonyak.org">mailto:andrew@pitonyak.org</a>] <br>
Sent: 2015</span><span style="font-family:宋体">年</span><span
lang="EN-US">6</span><span style="font-family:宋体">月</span><span
lang="EN-US">5</span><span style="font-family:宋体">日</span><span
lang="EN-US"> 19:15<br>
To: Zhang, William<br>
Cc: <a class="moz-txt-link-abbreviated" href="mailto:libreoffice@lists.freedesktop.org">libreoffice@lists.freedesktop.org</a><br>
Subject: Re: Q: How to get the path of all opened
spreadsheet documents</span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">No time to find the
solution now.... But I have done this sort of thing in
basic.<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">You enumerate the
open components from the desktop object and check of the
component is a calc document.<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">In your case do you
only care about documents that have been saved... Ignoring
new never saved to disk docs?<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">Think I can find a
basic example of it helps<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">On Jun 4, 2015 10:35
PM, "Zhang, William" <<a moz-do-not-send="true"
href="mailto:william.zhang@ptn.advantest.com"><span
style="color:windowtext;text-decoration:none">william.zhang@ptn.advantest.com</span></a>>
wrote:<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> Hi,<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> </span><span
style="font-family:"Courier New"" lang="EN-US"> </span><span
lang="EN-US"><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> Request:<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> In RedHat7, I
want to get the path of all opened spreadsheet documents
with Java.<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> </span><span
style="font-family:"Courier New"" lang="EN-US"> </span><span
lang="EN-US"><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> What I</span><span
style="font-family:"Courier New"" lang="EN-US">’</span><span
lang="EN-US">ve done:<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> 1.</span><span
style="font-family:"Courier New"" lang="EN-US"> </span><span
lang="EN-US"> I used Runtime.exec(cmd</span><span
style="font-family:"Courier New"" lang="EN-US">…</span><span
lang="EN-US">) with Java code, the </span><span
style="font-family:"Courier New"" lang="EN-US">‘</span><span
lang="EN-US">cmd</span><span
style="font-family:"Courier New"" lang="EN-US">’</span><span
lang="EN-US"> was defined with
</span><span style="font-family:"Courier New""
lang="EN-US">“</span><span lang="EN-US">ps
</span><span style="font-family:"Courier New""
lang="EN-US">–</span><span lang="EN-US">ef | grep xxx</span><span
style="font-family:"Courier New"" lang="EN-US">”</span><span
lang="EN-US"><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> ->if only one
spreadsheet document opened, the returned info list the
correct document, I can parse it and get the file path<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> ->but if
multi spreadsheet documents opened, the returned process
still only list the first document, I cannot get other
documents.<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> </span><span
style="font-family:"Courier New"" lang="EN-US"> </span><span
lang="EN-US">2.</span><span style="font-family:"Courier
New"" lang="EN-US"> </span><span lang="EN-US"> I also
test in bash, it seems
</span><span style="font-family:"Courier New""
lang="EN-US">“</span><span lang="EN-US">ps -ef</span><span
style="font-family:"Courier New"" lang="EN-US">”</span><span
lang="EN-US"> cannot list all files.<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> </span><span
style="font-family:"Courier New"" lang="EN-US"> </span><span
lang="EN-US"><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> So , I want to
know is there any other way to do it. such as using UNO
service with libreoffice API to get it.<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> Anyone who knows
it is much appreciate.<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> </span><span
style="font-family:"Courier New"" lang="EN-US"> </span><span
lang="EN-US"><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> Best Regards<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> William<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">> </span><span
style="font-family:"Courier New"" lang="EN-US"> </span><span
lang="EN-US"><o:p></o:p></span></p>
</div>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Andrew Pitonyak
My Macro Document: <a class="moz-txt-link-freetext" href="http://www.pitonyak.org/AndrewMacro.odt">http://www.pitonyak.org/AndrewMacro.odt</a>
Info: <a class="moz-txt-link-freetext" href="http://www.pitonyak.org/oo.php">http://www.pitonyak.org/oo.php</a>
</pre>
</body>
</html>