3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
6 import javax
.swing
.JOptionPane
;
11 import org
.jdesktop
.swingworker
.SwingWorker
;
13 import ag
.ion
.bion
.officelayer
.application
.OfficeApplicationException
;
14 import ag
.ion
.bion
.officelayer
.desktop
.IFrame
;
15 import ag
.ion
.bion
.officelayer
.document
.DocumentDescriptor
;
16 import ag
.ion
.bion
.officelayer
.document
.IDocument
;
17 import ag
.ion
.bion
.officelayer
.document
.IDocumentDescriptor
;
18 import ag
.ion
.bion
.officelayer
.document
.IDocumentService
;
19 import ag
.ion
.bion
.officelayer
.filter
.RTFFilter
;
20 import ag
.ion
.bion
.officelayer
.presentation
.IPresentationDocument
;
21 import ag
.ion
.bion
.officelayer
.spreadsheet
.ISpreadsheetDocument
;
22 import ag
.ion
.bion
.officelayer
.text
.IText
;
23 import ag
.ion
.bion
.officelayer
.text
.ITextCursor
;
24 import ag
.ion
.bion
.officelayer
.text
.ITextDocument
;
25 import ag
.ion
.bion
.officelayer
.text
.ITextField
;
26 import ag
.ion
.bion
.officelayer
.text
.ITextRange
;
27 import ag
.ion
.bion
.officelayer
.text
.IViewCursor
;
28 import ag
.ion
.noa
.NOAException
;
29 import ag
.ion
.noa
.printing
.IPrinter
;
30 import ag
.ion
.noa
.search
.ISearchResult
;
31 import ag
.ion
.noa
.search
.SearchDescriptor
;
33 import com
.sun
.star
.awt
.XTopWindow
;
34 import com
.sun
.star
.beans
.PropertyVetoException
;
35 import com
.sun
.star
.beans
.UnknownPropertyException
;
36 import com
.sun
.star
.beans
.XPropertySet
;
37 import com
.sun
.star
.comp
.helper
.BootstrapException
;
38 import com
.sun
.star
.container
.NoSuchElementException
;
39 import com
.sun
.star
.container
.XNameContainer
;
40 import com
.sun
.star
.datatransfer
.DataFlavor
;
41 import com
.sun
.star
.datatransfer
.UnsupportedFlavorException
;
42 import com
.sun
.star
.datatransfer
.XTransferable
;
43 import com
.sun
.star
.datatransfer
.clipboard
.XClipboard
;
44 import com
.sun
.star
.frame
.XController
;
45 import com
.sun
.star
.frame
.XFrame
;
46 import com
.sun
.star
.lang
.IllegalArgumentException
;
47 import com
.sun
.star
.lang
.IndexOutOfBoundsException
;
48 import com
.sun
.star
.lang
.WrappedTargetException
;
49 import com
.sun
.star
.lang
.XMultiComponentFactory
;
50 import com
.sun
.star
.sheet
.XSheetCellCursor
;
51 import com
.sun
.star
.sheet
.XSpreadsheet
;
52 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
53 import com
.sun
.star
.sheet
.XSpreadsheets
;
54 import com
.sun
.star
.style
.XStyle
;
55 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
56 import com
.sun
.star
.table
.XCell
;
57 import com
.sun
.star
.table
.XCellRange
;
58 import com
.sun
.star
.text
.XText
;
59 import com
.sun
.star
.text
.XTextDocument
;
60 import com
.sun
.star
.text
.XTextViewCursor
;
61 import com
.sun
.star
.text
.XTextViewCursorSupplier
;
62 import com
.sun
.star
.uno
.Exception
;
63 import com
.sun
.star
.uno
.UnoRuntime
;
64 import com
.sun
.star
.uno
.XComponentContext
;
65 import com
.sun
.star
.view
.XLineCursor
;
71 public static void sucheLeerenPlatzhalter(ITextDocument textDocument
, ITextField placeholders
){
74 public static void loescheLeerenPlatzhalter(ITextDocument textDocument
, ITextField placeholders
){
75 IViewCursor viewCursor
= textDocument
.getViewCursorService().getViewCursor();
76 viewCursor
.goToRange(placeholders
.getTextRange(), false);
77 XController xController
= textDocument
.getXTextDocument().getCurrentController();
78 XTextViewCursorSupplier xTextViewCursorSupplier
= (XTextViewCursorSupplier
) UnoRuntime
.queryInterface(XTextViewCursorSupplier
.class,
80 XLineCursor xLineCursor
= (XLineCursor
) UnoRuntime
.queryInterface(XLineCursor
.class,
81 xTextViewCursorSupplier
.getViewCursor());
82 xLineCursor
.gotoStartOfLine(false);
83 xLineCursor
.gotoEndOfLine(true);
84 ITextCursor textCursor
= viewCursor
.getTextCursorFromStart();
85 textCursor
.goLeft((short) 1, false);
86 textCursor
.gotoRange(viewCursor
.getTextCursorFromEnd().getEnd(), true);
87 textCursor
.setString("");
91 private static boolean sucheNachPlatzhalter(ITextDocument document
){
92 IText text
= document
.getTextService().getText();
93 String stext
= text
.getText();
99 boolean noendfound
= false;
100 while ((start
= stext
.indexOf("^")) >= 0){
102 for(int i
= 1;i
< 150;i
++){
103 if(stext
.substring(start
+i
,start
+(i
+1)).equals("^")){
104 dummy
= stext
.substring(start
,start
+(i
+1));
105 String sanweisung
= dummy
.toString().replace("^", "");
106 Object ret
= JOptionPane
.showInputDialog(null,"<html>Bitte Wert eingeben für: --\u003E<b> "+sanweisung
+" </b> </html>","Platzhalter gefunden", 1);
109 //sucheErsetze(dummy,"");
111 sucheErsetze(document
,dummy
,((String
)ret
).trim(),false);
112 stext
= text
.getText();
120 JOptionPane
.showMessageDialog(null,"Der Baustein ist fehlerhaft, eine Übernahme deshalb nicht möglich"+
121 "\n\nVermutete Ursache des Fehlers: es wurde ein Start-/Endezeichen '^' für Variable vergessen\n");
127 private static void sucheErsetze(ITextDocument document
,String suchenach
,String ersetzemit
,boolean alle
){
128 SearchDescriptor searchDescriptor
= new SearchDescriptor(suchenach
);
129 searchDescriptor
.setIsCaseSensitive(true);
130 ISearchResult searchResult
= null;
132 searchResult
= document
.getSearchService().findAll(searchDescriptor
);
134 searchResult
= document
.getSearchService().findFirst(searchDescriptor
);
137 if(!searchResult
.isEmpty()) {
138 ITextRange
[] textRanges
= searchResult
.getTextRanges();
139 for (int resultIndex
=0; resultIndex
<textRanges
.length
; resultIndex
++) {
140 textRanges
[resultIndex
].setText(ersetzemit
);
146 /*******************************************************************************************/
147 @SuppressWarnings("unchecked")
148 /*******************************************************************************************/
149 /*******************************************************************************************/
151 public ITextDocument
starteWriterMitDatei(String url
){
153 if(!OpRgaf
.officeapplication
.isActive()){
154 OpRgaf
.starteOfficeApplication();
156 IDocumentService documentService
= OpRgaf
.officeapplication
.getDocumentService();
157 DocumentDescriptor docdescript
= new DocumentDescriptor();
158 docdescript
.setURL(url
);
159 docdescript
.setHidden(false);
160 //IDocument document = documentService.constructNewDocument(IDocument.WRITER,docdescript );
161 IDocument document
= documentService
.loadDocument(url
,DocumentDescriptor
.DEFAULT
);
162 ITextDocument textDocument
= (ITextDocument
) document
;
163 /*********************/
164 XController xController
= textDocument
.getXTextDocument().getCurrentController();
165 XTextViewCursorSupplier xTextViewCursorSupplier
= (XTextViewCursorSupplier
) UnoRuntime
.queryInterface(XTextViewCursorSupplier
.class,
167 XTextViewCursor xtvc
= xTextViewCursorSupplier
.getViewCursor();
168 xtvc
.gotoStart(false);
169 textDocument
.getFrame().setFocus();
171 return (ITextDocument
) textDocument
;
173 }catch (OfficeApplicationException exception
) {
174 exception
.printStackTrace();
175 }catch (NOAException exception
) {
176 exception
.printStackTrace();
181 public static ITextDocument
starteWriterMitStream(InputStream is
, String titel
){
183 if(!OpRgaf
.officeapplication
.isActive()){
184 OpRgaf
.starteOfficeApplication();
186 DocumentDescriptor d
= new DocumentDescriptor();
188 d
.setFilterDefinition(RTFFilter
.FILTER
.getFilterDefinition(IDocument
.WRITER
));
189 IDocumentService documentService
= OpRgaf
.officeapplication
.getDocumentService();
190 IDocument document
= documentService
.constructNewDocument(IDocument
.WRITER
, DocumentDescriptor
.DEFAULT
);
191 ITextDocument textDocument
= (ITextDocument
)document
;
192 textDocument
.getViewCursorService().getViewCursor().getTextCursorFromStart().insertDocument(is
, new RTFFilter());
193 XController xController
= textDocument
.getXTextDocument().getCurrentController();
194 XTextViewCursorSupplier xTextViewCursorSupplier
= (XTextViewCursorSupplier
) UnoRuntime
.queryInterface(XTextViewCursorSupplier
.class,
196 XTextViewCursor xtvc
= xTextViewCursorSupplier
.getViewCursor();
197 xtvc
.gotoStart(false);
198 textDocument
.getFrame().setFocus();
200 return (ITextDocument
) textDocument
;
202 }catch (OfficeApplicationException exception
) {
203 exception
.printStackTrace();
204 }catch (NOAException exception
) {
205 exception
.printStackTrace();
206 } catch (IOException e
) {
207 // TODO Auto-generated catch block
214 public ISpreadsheetDocument
starteCalcMitDatei(String url
){
216 if(!OpRgaf
.officeapplication
.isActive()){
217 OpRgaf
.starteOfficeApplication();
219 IDocumentService documentService
= OpRgaf
.officeapplication
.getDocumentService();
220 DocumentDescriptor docdescript
= new DocumentDescriptor();
221 docdescript
.setURL(url
);
222 docdescript
.setHidden(false);
223 IDocument document
= documentService
.loadDocument(url
,DocumentDescriptor
.DEFAULT
);
224 //IDocument document = documentService.constructNewDocument(IDocument.CALC, DocumentDescriptor.DEFAULT);
225 ISpreadsheetDocument spreadsheetDocument
= (ISpreadsheetDocument
) document
;
226 /********************/
227 spreadsheetDocument
.getFrame().setFocus();
228 return (ISpreadsheetDocument
) spreadsheetDocument
;
231 catch (Throwable exception
) {
232 exception
.printStackTrace();
237 public static void starteLeerenCalc(){
239 IDocumentService documentService
= OpRgaf
.officeapplication
.getDocumentService();
240 IDocument document
= documentService
.constructNewDocument(IDocument
.CALC
, DocumentDescriptor
.DEFAULT
);
241 ISpreadsheetDocument spreadsheetDocument
= (ISpreadsheetDocument
) document
;
242 spreadsheetDocument
.getFrame().setFocus();
244 catch (Throwable exception
) {
245 exception
.printStackTrace();
249 public static void starteLeerenImpress(){
251 IDocumentService documentService
= OpRgaf
.officeapplication
.getDocumentService();
252 IDocument document
= documentService
.constructNewDocument(IDocument
.IMPRESS
, DocumentDescriptor
.DEFAULT
);
253 IPresentationDocument presentationDocument
= (IPresentationDocument
) document
;
254 presentationDocument
.getFrame().setFocus();
256 catch(Throwable throwable
) {
257 throwable
.printStackTrace();
262 public static void setzePapierFormat(ITextDocument textDocument
,int hoch
,int breit
) throws NoSuchElementException
, WrappedTargetException
, UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
{
263 XTextDocument xTextDocument
= textDocument
.getXTextDocument();
264 XStyleFamiliesSupplier xSupplier
= (XStyleFamiliesSupplier
) UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class,
266 XNameContainer family
= (XNameContainer
) UnoRuntime
.queryInterface(XNameContainer
.class,
267 xSupplier
.getStyleFamilies().getByName("PageStyles"));
268 XStyle xStyle
= (XStyle
) UnoRuntime
.queryInterface(XStyle
.class, family
.getByName("Standard"));
269 XPropertySet xStyleProps
= (XPropertySet
) UnoRuntime
.queryInterface(XPropertySet
.class,
272 com.sun.star.beans.Property[] props = xStyleProps.getPropertySetInfo().getProperties();
273 for (int i = 0; i < props.length; i++) {
274 //System.out.println(props[i] .Name + " = "
275 + xStyleProps.getPropertyValue(props[i].Name));
280 xStyleProps
.setPropertyValue("Height", hoch
);
281 xStyleProps
.setPropertyValue("Width", breit
);
283 public static void setzePapierFormatCalc(ISpreadsheetDocument document
,int hoch
,int breit
) throws NoSuchElementException
, WrappedTargetException
, UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
{
284 XSpreadsheetDocument xSpreadSheetDocument
= document
.getSpreadsheetDocument();
285 XStyleFamiliesSupplier xSupplier
= (XStyleFamiliesSupplier
) UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class,
286 xSpreadSheetDocument
);
287 XNameContainer family
= (XNameContainer
) UnoRuntime
.queryInterface(XNameContainer
.class,
288 xSupplier
.getStyleFamilies().getByName("PageStyles"));
289 XStyle xStyle
= (XStyle
) UnoRuntime
.queryInterface(XStyle
.class, family
.getByName("Standard"));
290 XPropertySet xStyleProps
= (XPropertySet
) UnoRuntime
.queryInterface(XPropertySet
.class,
292 xStyleProps
.setPropertyValue("Height", hoch
);
293 xStyleProps
.setPropertyValue("Width", breit
);
295 public static void setzeRaenderCalc(ISpreadsheetDocument document
,int oben
,int unten
,int links
,int rechts
) throws NoSuchElementException
, WrappedTargetException
, UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
{
296 XSpreadsheetDocument xSpreadSheetDocument
= document
.getSpreadsheetDocument();
297 XStyleFamiliesSupplier xSupplier
= (XStyleFamiliesSupplier
) UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class,
298 xSpreadSheetDocument
);
299 XNameContainer family
= (XNameContainer
) UnoRuntime
.queryInterface(XNameContainer
.class,
300 xSupplier
.getStyleFamilies().getByName("PageStyles"));
301 XStyle xStyle
= (XStyle
) UnoRuntime
.queryInterface(XStyle
.class, family
.getByName("Standard") );
302 XPropertySet xStyleProps
= (XPropertySet
) UnoRuntime
.queryInterface(XPropertySet
.class,
304 xStyleProps
.setPropertyValue("TopMargin",oben
);
305 xStyleProps
.setPropertyValue("BottomMargin",unten
);
306 xStyleProps
.setPropertyValue("LeftMargin",links
);
307 xStyleProps
.setPropertyValue("RightMargin",rechts
);
311 public static void setzeRaender(ITextDocument textDocument
,int oben
,int unten
,int links
,int rechts
) throws NoSuchElementException
, WrappedTargetException
, UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
{
312 XTextDocument xTextDocument
= textDocument
.getXTextDocument();
313 XStyleFamiliesSupplier xSupplier
= (XStyleFamiliesSupplier
) UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class,
315 XNameContainer family
= (XNameContainer
) UnoRuntime
.queryInterface(XNameContainer
.class,
316 xSupplier
.getStyleFamilies().getByName("PageStyles"));
317 XStyle xStyle
= (XStyle
) UnoRuntime
.queryInterface(XStyle
.class, family
.getByName("Standard") );
318 XPropertySet xStyleProps
= (XPropertySet
) UnoRuntime
.queryInterface(XPropertySet
.class,
320 xStyleProps
.setPropertyValue("TopMargin",oben
);
321 xStyleProps
.setPropertyValue("BottomMargin",unten
);
322 xStyleProps
.setPropertyValue("LeftMargin",links
);
323 xStyleProps
.setPropertyValue("RightMargin",rechts
);
328 public static void inDenVordergrund(ITextDocument textDocumentx
){
329 ITextDocument textDocument
= (ITextDocument
) textDocumentx
;
330 IFrame officeFrame
= textDocument
.getFrame();
331 XFrame xFrame
= officeFrame
.getXFrame();
332 XTopWindow topWindow
= (XTopWindow
)
333 UnoRuntime
.queryInterface(XTopWindow
.class,
334 xFrame
. getContainerWindow());
335 //hier beide methoden, beide sind nötig
341 public static void ooOrgAnmelden(){
342 new SwingWorker
<Void
,Void
>(){
344 protected Void
doInBackground() throws java
.lang
.Exception
{
345 IDocumentDescriptor docdescript
= new DocumentDescriptor();
346 docdescript
.setHidden(true);
347 IDocument document
= null;
348 ITextDocument textDocument
= null;
349 OpRgaf
.thisFrame
.setCursor(OpRgaf
.thisClass
.wartenCursor
);
351 if(!OpRgaf
.officeapplication
.isActive()){
352 OpRgaf
.starteOfficeApplication();
355 IDocumentService documentService
= OpRgaf
.officeapplication
.getDocumentService();
356 document
= documentService
.constructNewDocument(IDocument
.WRITER
, docdescript
);
357 textDocument
= (ITextDocument
)document
;
358 textDocument
.close();
360 catch (OfficeApplicationException exception
) {
361 exception
.printStackTrace();
363 catch (NOAException exception
) {
364 exception
.printStackTrace();
372 public static void druckerSetzen(ITextDocument textDocument
,String drucker
){
374 /**********************/
376 String druckerName
= null;
378 druckerName
= textDocument
.getPrintService().getActivePrinter().getName();
379 } catch (NOAException e
) {
382 //Wenn nicht gleich wie im Übergebenen Parameter angegeben -> Drucker wechseln
383 IPrinter iprint
= null;
384 if(! druckerName
.equals(drucker
)){
386 iprint
= (IPrinter
) textDocument
.getPrintService().createPrinter(drucker
);
387 } catch (NOAException e
) {
391 textDocument
.getPrintService().setActivePrinter(iprint
);
392 } catch (NOAException e
) {
398 /***********************OO-Calc Funktionen*******************************/
399 public static void doColWidth(ISpreadsheetDocument spreadsheetDocument
,String sheetName
, int col_first
,int col_last
,int width
) throws NoSuchElementException
, WrappedTargetException
, IndexOutOfBoundsException
, UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
{
400 XSpreadsheets spreadsheets
= spreadsheetDocument
.getSpreadsheetDocument().getSheets();
401 XSpreadsheet spreadsheet1
= (XSpreadsheet
)UnoRuntime
.queryInterface(XSpreadsheet
.class,spreadsheets
.getByName(sheetName
));
402 XCellRange xCellRange
= spreadsheet1
.getCellRangeByPosition( 0, 0, col_last
, 0 );
403 com
.sun
.star
.table
.XColumnRowRange xColRowRange
= ( com
.sun
.star
.table
.XColumnRowRange
)
404 UnoRuntime
.queryInterface( com
.sun
.star
.table
.XColumnRowRange
.class, xCellRange
);
405 com
.sun
.star
.beans
.XPropertySet xPropSet
= null;
406 com
.sun
.star
.table
.XTableColumns xColumns
= xColRowRange
.getColumns();
407 for(int i
= col_first
; i
<= col_last
;i
++){
408 Object aColumnObj
= xColumns
.getByIndex(i
);
409 xPropSet
= (com
.sun
.star
.beans
.XPropertySet
)
410 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, aColumnObj
);
411 xPropSet
.setPropertyValue("Width", width
);
414 public static void doColTextAlign(ISpreadsheetDocument spreadsheetDocument
,String sheetName
, int col_first
,int col_last
,int col_textalign
) throws NoSuchElementException
, WrappedTargetException
, IndexOutOfBoundsException
, UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
{
415 XSpreadsheets spreadsheets
= spreadsheetDocument
.getSpreadsheetDocument().getSheets();
416 XSpreadsheet spreadsheet1
= (XSpreadsheet
)UnoRuntime
.queryInterface(XSpreadsheet
.class,spreadsheets
.getByName(sheetName
));
417 XCellRange xCellRange
= spreadsheet1
.getCellRangeByPosition( 0, 0, col_last
, 0 );
418 com
.sun
.star
.table
.XColumnRowRange xColRowRange
= ( com
.sun
.star
.table
.XColumnRowRange
)
419 UnoRuntime
.queryInterface( com
.sun
.star
.table
.XColumnRowRange
.class, xCellRange
);
420 com
.sun
.star
.beans
.XPropertySet xPropSet
= null;
421 com
.sun
.star
.table
.XTableColumns xColumns
= xColRowRange
.getColumns();
422 for(int i
= col_first
; i
<= col_last
;i
++){
423 Object aColumnObj
= xColumns
.getByIndex(i
);
424 xPropSet
= (com
.sun
.star
.beans
.XPropertySet
)
425 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, aColumnObj
);
426 xPropSet
.setPropertyValue("HoriJustify", col_textalign
);
429 public static void doColNumberFormat(ISpreadsheetDocument spreadsheetDocument
,String sheetName
, int col_first
,int col_last
,int col_numberformat
) throws NoSuchElementException
, WrappedTargetException
, IndexOutOfBoundsException
, UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
{
430 XSpreadsheets spreadsheets
= spreadsheetDocument
.getSpreadsheetDocument().getSheets();
431 XSpreadsheet spreadsheet1
= (XSpreadsheet
)UnoRuntime
.queryInterface(XSpreadsheet
.class,spreadsheets
.getByName(sheetName
));
432 XCellRange xCellRange
= spreadsheet1
.getCellRangeByPosition( 0, 0, col_last
, 0 );
433 com
.sun
.star
.table
.XColumnRowRange xColRowRange
= ( com
.sun
.star
.table
.XColumnRowRange
)
434 UnoRuntime
.queryInterface( com
.sun
.star
.table
.XColumnRowRange
.class, xCellRange
);
435 com
.sun
.star
.beans
.XPropertySet xPropSet
= null;
436 com
.sun
.star
.table
.XTableColumns xColumns
= xColRowRange
.getColumns();
437 for(int i
= col_first
; i
<= col_last
;i
++){
438 Object aColumnObj
= xColumns
.getByIndex(i
);
439 xPropSet
= (com
.sun
.star
.beans
.XPropertySet
)
440 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, aColumnObj
);
441 xPropSet
.setPropertyValue("NumberFormat", col_numberformat
);
444 public static void doCellNumberFormat(XSheetCellCursor cellCursor
,int col
,int row
,int cell_numberformat
) throws NoSuchElementException
, WrappedTargetException
, IndexOutOfBoundsException
, UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
{
445 XCell cell
= cellCursor
.getCellByPosition(col
,row
);
446 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, cell
);
447 com
.sun
.star
.beans
.XPropertySet xPropSet
= null;
448 xPropSet
= (com
.sun
.star
.beans
.XPropertySet
)
449 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, cell
);
450 xPropSet
.setPropertyValue( "NumberFormat", cell_numberformat
);
453 public static void doCellValue(XSheetCellCursor cellCursor
,int col
,int row
,Object value
) throws IndexOutOfBoundsException
{
454 XCell cell
= cellCursor
.getCellByPosition(col
,row
);
456 if(value
instanceof Double
){
457 cell
.setValue((Double
)value
);
458 }else if(value
instanceof String
){
459 cellText
= (XText
)UnoRuntime
.queryInterface(XText
.class, cell
);
460 cellText
.setString((String
)value
);
465 public static void doCellFormula(XSheetCellCursor cellCursor
,int col
,int row
,String formula
) throws IndexOutOfBoundsException
{
466 XCell cell
= cellCursor
.getCellByPosition(col
,row
);
467 cell
.setFormula(formula
);
469 public static void doCellColor(XSheetCellCursor cellCursor
,int col
,int row
,int color
) throws IndexOutOfBoundsException
, UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
{
470 XCell cell
= cellCursor
.getCellByPosition(col
,row
);
471 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, cell
);
472 com
.sun
.star
.beans
.XPropertySet xPropSet
= null;
473 xPropSet
= (com
.sun
.star
.beans
.XPropertySet
)
474 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, cell
);
475 xPropSet
.setPropertyValue( "CharColor", color
);
477 public static void doCellFontBold(XSheetCellCursor cellCursor
,int col
,int row
) throws IndexOutOfBoundsException
, UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
{
478 XCell cell
= cellCursor
.getCellByPosition(col
,row
);
479 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, cell
);
480 com
.sun
.star
.beans
.XPropertySet xPropSet
= null;
481 xPropSet
= (com
.sun
.star
.beans
.XPropertySet
)
482 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, cell
);
483 xPropSet
.setPropertyValue( "CharWeight",com
.sun
.star
.awt
.FontWeight
.BOLD
);
484 /* Beispiele für Fonthandling
485 xPropSet.setPropertyValue("CharFontStyleName", new String("Times New Roman"));
486 xPropSet.setPropertyValue("CharWeight", new Float(com.sun.star.awt.FontWeight.NORMAL));
487 xPropSet.setPropertyValue("CharHeight", new Float(12));
491 public static void doCellFontItalic(XSheetCellCursor cellCursor
,int col
,int row
) throws IndexOutOfBoundsException
, UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
{
492 XCell cell
= cellCursor
.getCellByPosition(col
,row
);
493 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, cell
);
494 com
.sun
.star
.beans
.XPropertySet xPropSet
= null;
495 xPropSet
= (com
.sun
.star
.beans
.XPropertySet
)
496 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, cell
);
497 xPropSet
.setPropertyValue( "CharPosture", com
.sun
.star
.awt
.FontSlant
.ITALIC
);
500 public static void doCellFontSize(XSheetCellCursor cellCursor
,int col
,int row
,Float size
) throws IndexOutOfBoundsException
, UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
{
501 XCell cell
= cellCursor
.getCellByPosition(col
,row
);
502 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, cell
);
503 com
.sun
.star
.beans
.XPropertySet xPropSet
= null;
504 xPropSet
= (com
.sun
.star
.beans
.XPropertySet
)
505 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, cell
);
506 xPropSet
.setPropertyValue("CharHeight", size
);
507 xPropSet
.setPropertyValue( "CharWeight",com
.sun
.star
.awt
.FontWeight
.NORMAL
);
508 /* Beispiele für Fonthandling
509 xPropSet.setPropertyValue("CharFontStyleName", new String("Times New Roman"));
510 xPropSet.setPropertyValue("CharWeight", new Float(com.sun.star.awt.FontWeight.NORMAL));
511 xPropSet.setPropertyValue("CharHeight", new Float(12));
514 public static void doCellFontName(XSheetCellCursor cellCursor
,int col
,int row
,String fontname
) throws IndexOutOfBoundsException
, UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
{
515 XCell cell
= cellCursor
.getCellByPosition(col
,row
);
516 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, cell
);
517 com
.sun
.star
.beans
.XPropertySet xPropSet
= null;
518 xPropSet
= (com
.sun
.star
.beans
.XPropertySet
)
519 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, cell
);
520 xPropSet
.setPropertyValue("CharFontName", fontname
);
521 //PropSet.setPropertyValue( "CharWeight",com.sun.star.awt.FontWeight.NORMAL );
522 /* Beispiele für Fonthandling
523 xPropSet.setPropertyValue("CharFontStyleName", new String("Times New Roman"));
524 xPropSet.setPropertyValue("CharWeight", new Float(com.sun.star.awt.FontWeight.NORMAL));
525 xPropSet.setPropertyValue("CharHeight", new Float(12));
528 public static void getCellPropertiesName(XSheetCellCursor cellCursor
,int col
,int row
,String fontname
) throws IndexOutOfBoundsException
, UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
{
529 XCell cell
= cellCursor
.getCellByPosition(col
,row
);
530 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, cell
);
531 com
.sun
.star
.beans
.XPropertySet xPropSet
= null;
532 xPropSet
= (com
.sun
.star
.beans
.XPropertySet
)
533 UnoRuntime
.queryInterface(com
.sun
.star
.beans
.XPropertySet
.class, cell
);
539 /*******************************************************/
540 public static void holeClipBoard() {
542 XComponentContext xComponentContext
;
544 xComponentContext
= (XComponentContext
) com
.sun
.star
.comp
.helper
.Bootstrap
.bootstrap();
545 XMultiComponentFactory xMultiComponentFactory
;
546 xMultiComponentFactory
= (XMultiComponentFactory
) OpRgaf
.officeapplication
.getDocumentService();
549 xMultiComponentFactory
.createInstanceWithContext(
550 "com.sun.star.datatransfer.clipboard.SystemClipboard",
552 XClipboard xClipboard
= (XClipboard
)
553 UnoRuntime
.queryInterface(XClipboard
.class, oClipboard
);
555 //---------------------------------------------------
556 // get a list of formats currently on the clipboard
557 //---------------------------------------------------
559 XTransferable xTransferable
= xClipboard
.getContents();
561 DataFlavor
[] aDflvArr
= xTransferable
.getTransferDataFlavors();
563 // print all available formats
565 //System.out.println("Reading the clipboard...");
566 //System.out.println("Available clipboard formats:");
568 DataFlavor aUniFlv
= null;
570 for (int i
=0;i
<aDflvArr
.length
;i
++) {
571 //System.out.println( "MimeType: " +
572 // aDflvArr[i].MimeType +
573 // " HumanPresentableName: " +
574 // aDflvArr[i].HumanPresentableName );
576 // if there is the format unicode text on the clipboard save the
577 // corresponding DataFlavor so that we can later output the string
579 if (aDflvArr
[i
].MimeType
.equals("text/plain;charset=utf-16"))
581 aUniFlv
= aDflvArr
[i
];
585 if (aUniFlv
!= null){
586 //System.out.println("Unicode text on the clipboard...");
587 Object aData
= xTransferable
.getTransferData(aUniFlv
);
589 }catch(UnsupportedFlavorException ex
){
590 System
.err
.println( "Requested format is not available" );
592 } catch (OfficeApplicationException e
) {
594 } catch (Exception e
) {
596 } catch (BootstrapException e
) {