Bonjour,
je réalise actuellement une application en java dans laquelle je souhaite visualiser des états déjà enregistré, et réaliser des exports. Ces rapports en question contiennent des requêtes SQL pour une base Access.

L'application est fait pour du client lourd.

Pourriez vous me donner des exemples pour réaliser le rafraichissement des données des .rpt.

Merci.

PS: j'ai trouvé trois classe généré automatiquement, elles fonctionnes pour afficher les rapports avec des données enregistrés:

CRJavaHelper
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
/**
 * This sample code is an example of how to use the Business Objects APIs. 
 * Because the sample code is designed for demonstration only, it is 
 * unsupported.  You are free to modify and distribute the sample code as needed.   
 */
package com.businessobjects.samples;
 
import java.io.InputStream;
import java.util.Collection;
import java.util.Locale;
 
import com.crystaldecisions.sdk.occa.report.application.DataDefController;
import com.crystaldecisions.sdk.occa.report.application.ReportClientDocument;
import com.crystaldecisions.sdk.occa.report.data.FieldDisplayNameType;
import com.crystaldecisions.sdk.occa.report.data.IConnectionInfo;
import com.crystaldecisions.sdk.occa.report.data.ITable;
import com.crystaldecisions.sdk.occa.report.data.ParameterField;
import com.crystaldecisions.sdk.occa.report.data.ParameterFieldDiscreteValue;
import com.crystaldecisions.sdk.occa.report.data.ParameterFieldRangeValue;
import com.crystaldecisions.sdk.occa.report.data.RangeValueBoundType;
import com.crystaldecisions.sdk.occa.report.data.Tables;
import com.crystaldecisions.sdk.occa.report.data.Values;
import com.crystaldecisions.sdk.occa.report.document.PaperSize;
import com.crystaldecisions.sdk.occa.report.document.PaperSource;
import com.crystaldecisions.sdk.occa.report.document.PrintReportOptions;
import com.crystaldecisions.sdk.occa.report.document.PrinterDuplex;
import com.crystaldecisions.sdk.occa.report.exportoptions.CharacterSeparatedValuesExportFormatOptions;
import com.crystaldecisions.sdk.occa.report.exportoptions.DataOnlyExcelExportFormatOptions;
import com.crystaldecisions.sdk.occa.report.exportoptions.EditableRTFExportFormatOptions;
import com.crystaldecisions.sdk.occa.report.exportoptions.ExcelExportFormatOptions;
import com.crystaldecisions.sdk.occa.report.exportoptions.ExportOptions;
import com.crystaldecisions.sdk.occa.report.exportoptions.PDFExportFormatOptions;
import com.crystaldecisions.sdk.occa.report.exportoptions.RTFWordExportFormatOptions;
import com.crystaldecisions.sdk.occa.report.exportoptions.ReportExportFormat;
import com.crystaldecisions.sdk.occa.report.lib.IStrings;
import com.crystaldecisions.sdk.occa.report.lib.PropertyBag;
import com.crystaldecisions.sdk.occa.report.lib.ReportSDKException;
import com.crystaldecisions.sdk.occa.report.lib.ReportSDKPrinterException;
 
/**
 * Crystal Reports Java Helper Sample
 * 
 * @author Business Objects
 */
public class CRJavaHelper {
 
    /**
     * Logs on to an existing datasource
     * 
     * @param clientDoc The reportClientDocument representing the report being used
     * @param username    The DB logon user name
     * @param password    The DB logon password
     * @throws ReportSDKException
     */
    public static void logonDataSource (ReportClientDocument clientDoc, String username, String password)
            throws ReportSDKException
    {
        clientDoc.getDatabaseController ().logon (username, password);
    }
 
    /**
     * Changes the DataSource for each Table
     * @param clientDoc The reportClientDocument representing the report being used
     * @param username  The DB logon user name
     * @param password  The DB logon password
     * @param connectionURL  The connection URL
     * @param driverName    The driver Name
     * @param jndiName        The JNDI name
     * @throws ReportSDKException
     */
    public static void changeDataSource (ReportClientDocument clientDoc, String username, String password,
                                         String connectionURL, String driverName, String jndiName)
            throws ReportSDKException
    {
 
        changeDataSource (clientDoc, null, null, username, password, connectionURL, driverName, jndiName);
    }
 
    /**
     * Changes the DataSource for a specific Table
     * @param clientDoc The reportClientDocument representing the report being used
     * @param subreportName    "" for main report, name of subreport for subreport, null for all reports
     * @param tableName        name of table to change.  null for all tables.
     * @param username  The DB logon user name
     * @param password  The DB logon password
     * @param connectionURL  The connection URL
     * @param driverName    The driver Name
     * @param jndiName        The JNDI name
     * @throws ReportSDKException
     */
    public static void changeDataSource (ReportClientDocument clientDoc, String subreportName, String tableName,
                                         String username, String password, String connectionURL, String driverName,
                                         String jndiName) throws ReportSDKException
    {
 
        PropertyBag propertyBag = null;
        IConnectionInfo connectionInfo = null;
        ITable origTable = null;
        ITable newTable = null;
 
        // Declare variables to hold ConnectionInfo values.
        // Below is the list of values required to switch to use a JDBC/JNDI
        // connection
        String TRUSTED_CONNECTION = "false";
        String SERVER_TYPE = "JDBC (JNDI)";
        String USE_JDBC = "true";
        String DATABASE_DLL = "crdb_jdbc.dll";
        String JNDI_OPTIONAL_NAME = jndiName;
        String CONNECTION_URL = connectionURL;
        String DATABASE_CLASS_NAME = driverName;
 
        // The next few parameters are optional parameters which you may want to
        // uncomment
        // You may wish to adjust the arguments of the method to pass these
        // values in if necessary
        // String TABLE_NAME_QUALIFIER = "new_table_name";
        // String SERVER_NAME = "new_server_name";
        // String CONNECTION_STRING = "new_connection_string";
        // String DATABASE_NAME = "new_database_name";
        // String URI = "new_URI";
 
        // Declare variables to hold database User Name and Password values
        String DB_USER_NAME = username;
        String DB_PASSWORD = password;
 
        // Obtain collection of tables from this database controller
        if (subreportName == null || subreportName.equals (""))
        {
            Tables tables = clientDoc.getDatabaseController ().getDatabase ().getTables ();
            for (int i = 0; i < tables.size (); i++)
            {
                origTable = tables.getTable (i);
                if (tableName == null || origTable.getName ().equals (tableName))
                {
                    newTable = (ITable) origTable.clone (true);
 
                    // We set the Fully qualified name to the Table Alias to keep the
                    // method generic
                    // This workflow may not work in all scenarios and should likely be
                    // customized to work
                    // in the developer's specific situation. The end result of this
                    // statement will be to strip
                    // the existing table of it's db specific identifiers. For example
                    // Xtreme.dbo.Customer becomes just Customer
                    newTable.setQualifiedName (origTable.getAlias ());
 
                    // Change properties that are different from the original datasource
                    // For example, if the table name has changed you will be required
                    // to change it during this routine
                    // table.setQualifiedName(TABLE_NAME_QUALIFIER);
 
                    // Change connection information properties
                    connectionInfo = newTable.getConnectionInfo ();
 
                    // Set new table connection property attributes
                    propertyBag = new PropertyBag ();
 
                    // Overwrite any existing properties with updated values
                    propertyBag.put ("Trusted_Connection", TRUSTED_CONNECTION);
                    propertyBag.put ("Server Type", SERVER_TYPE);
                    propertyBag.put ("Use JDBC", USE_JDBC);
                    propertyBag.put ("Database DLL", DATABASE_DLL);
                    propertyBag.put ("JNDIOptionalName", JNDI_OPTIONAL_NAME);
                    propertyBag.put ("Connection URL", CONNECTION_URL);
                    propertyBag.put ("Database Class Name", DATABASE_CLASS_NAME);
                    // propertyBag.put("Server Name", SERVER_NAME); //Optional property
                    // propertyBag.put("Connection String", CONNECTION_STRING); //Optional property
                    // propertyBag.put("Database Name", DATABASE_NAME); //Optional property
                    // propertyBag.put("URI", URI); //Optional property
                    connectionInfo.setAttributes (propertyBag);
 
                    // Set database username and password
                    // NOTE: Even if the username and password properties do not change
                    // when switching databases, the
                    // database password is *not* saved in the report and must be set at
                    // runtime if the database is secured.
                    connectionInfo.setUserName (DB_USER_NAME);
                    connectionInfo.setPassword (DB_PASSWORD);
 
                    // Update the table information
                    clientDoc.getDatabaseController ().setTableLocation (origTable, newTable);
                }
            }
        }
 
        // Next loop through all the subreports and pass in the same
        // information. You may consider
        // creating a separate method which accepts
        if (subreportName == null || !(subreportName.equals ("")))
        {
            IStrings subNames = clientDoc.getSubreportController ().getSubreportNames ();
            for (int subNum = 0; subNum < subNames.size (); subNum++)
            {
                Tables tables = clientDoc.getSubreportController ().getSubreport (subNames.getString (subNum)).getDatabaseController ().getDatabase ().getTables ();
                for (int i = 0; i < tables.size (); i++)
                {
                    origTable = tables.getTable (i);
                    if (tableName == null || origTable.getName ().equals (tableName))
                    {
                        newTable = (ITable) origTable.clone (true);
 
                        // We set the Fully qualified name to the Table Alias to keep
                        // the method generic
                        // This workflow may not work in all scenarios and should likely
                        // be customized to work
                        // in the developer's specific situation. The end result of this
                        // statement will be to strip
                        // the existing table of it's db specific identifiers. For
                        // example Xtreme.dbo.Customer becomes just Customer
                        newTable.setQualifiedName (origTable.getAlias ());
 
                        // Change properties that are different from the original
                        // datasource
                        // table.setQualifiedName(TABLE_NAME_QUALIFIER);
 
                        // Change connection information properties
                        connectionInfo = newTable.getConnectionInfo ();
 
                        // Set new table connection property attributes
                        propertyBag = new PropertyBag ();
 
                        // Overwrite any existing properties with updated values
                        propertyBag.put ("Trusted_Connection", TRUSTED_CONNECTION);
                        propertyBag.put ("Server Type", SERVER_TYPE);
                        propertyBag.put ("Use JDBC", USE_JDBC);
                        propertyBag.put ("Database DLL", DATABASE_DLL);
                        propertyBag.put ("JNDIOptionalName", JNDI_OPTIONAL_NAME);
                        propertyBag.put ("Connection URL", CONNECTION_URL);
                        propertyBag.put ("Database Class Name", DATABASE_CLASS_NAME);
                        // propertyBag.put("Server Name", SERVER_NAME); //Optional property
                        // propertyBag.put("Connection String", CONNECTION_STRING); //Optionalproperty
                        // propertyBag.put("Database Name", DATABASE_NAME); //Optional property
                        // propertyBag.put("URI", URI); //Optional property
                        connectionInfo.setAttributes (propertyBag);
 
                        // Set database username and password
                        // NOTE: Even if the username and password properties do not
                        // change when switching databases, the
                        // database password is *not* saved in the report and must be
                        // set at runtime if the database is secured.
                        connectionInfo.setUserName (DB_USER_NAME);
                        connectionInfo.setPassword (DB_PASSWORD);
 
                        // Update the table information
                        clientDoc.getSubreportController ().getSubreport (subNames.getString (subNum)).getDatabaseController ().setTableLocation (origTable, newTable);
                    }
                }
            }
        }
    }
 
    /**
     * Passes a populated java.sql.Resultset object to a Table object
     * 
     * @param clientDoc The reportClientDocument representing the report being used
     * @param rs        The java.sql.Resultset used to populate the Table
     * @param tableName    The name of the table
     * @param subreportName    The name of the subreport.  If tables in the main report
     *                         is to be used, "" should be passed
     * @throws ReportSDKException
     */
    public static void passResultSet (ReportClientDocument clientDoc, java.sql.ResultSet rs, String tableName,
                                      String subreportName) throws ReportSDKException
    {
        if (subreportName.equals (""))
        {
            clientDoc.getDatabaseController ().setDataSource (rs, tableName, tableName + "_ResultSet");
        }
        else
        {
            clientDoc.getSubreportController ().getSubreport (subreportName).getDatabaseController ().setDataSource (
                    rs, tableName, tableName + "_ResultSet");
        }
    }
 
    /**
     * Passes a populated collection of a Java class to a Table object
     * 
     * @param clientDoc     The reportClientDocument representing the report being used
     * @param dataSet        The data used to populate the Table
     * @param className        The fully-qualified class name of the POJO objects being passed
     * @param tableName        The name of the table
     * @param subreportName    The name of the subreport.  If tables in the main report
     *                         is to be used, "" should be passed
     * @throws ReportSDKException
     */
    public static void passPOJO (ReportClientDocument clientDoc, Collection<?> dataSet, String className,
                                 String tableName, String subreportName) throws ReportSDKException,
            ClassNotFoundException
    {
        if (subreportName.equals (""))
        {
            clientDoc.getDatabaseController ().setDataSource (dataSet, Class.forName (className), tableName, tableName + "_POJO");
        }
        else
        {
            clientDoc.getSubreportController ().getSubreport (subreportName).getDatabaseController ().setDataSource (
                    dataSet, Class.forName (className), tableName, tableName + "_POJO");
        }
    }
 
    /**
     * Passes a single discrete parameter value to a report parameter
     * 
     * @param clientDoc        The reportClientDocument representing the report being used
     * @param subreportName    The name of the subreport.  If tables in the main report
     *                         is to be used, "" should be passed
     * @param parameterName    The name of the parameter
     * @param newValue        The new value of the parameter 
     * @throws ReportSDKException
     */
    public static void addDiscreteParameterValue (ReportClientDocument clientDoc, String subreportName,
                                                  String parameterName, Object newValue) throws ReportSDKException
    {
        DataDefController dataDefController = null;
        if (subreportName.equals (""))
        {
            dataDefController = clientDoc.getDataDefController ();
        }
        else
        {
            dataDefController = clientDoc.getSubreportController ().getSubreport (subreportName)
                    .getDataDefController ();
        }
 
        ParameterFieldDiscreteValue newDiscValue = new ParameterFieldDiscreteValue ();
        newDiscValue.setValue (newValue);
 
        ParameterField paramField = (ParameterField) dataDefController.getDataDefinition ().getParameterFields ().findField (parameterName, FieldDisplayNameType.fieldName, Locale.getDefault ());
        boolean multiValue = paramField.getAllowMultiValue ();
 
        if (multiValue)
        {
            Values newVals = (Values) paramField.getCurrentValues ().clone (true);
            newVals.add (newDiscValue);
            clientDoc.getDataDefController ().getParameterFieldController ().setCurrentValue (subreportName,
                    parameterName, newVals);
        }
        else
        {
            clientDoc.getDataDefController ().getParameterFieldController ().setCurrentValue (subreportName,
                    parameterName, newValue);
        }
    }
 
    /**
     * Passes multiple discrete parameter values to a report parameter
     * 
     * @param clientDoc        The reportClientDocument representing the report being used
     * @param subreportName    The name of the subreport.  If tables in the main report
     *                         is to be used, "" should be passed
     * @param parameterName    The name of the parameter
     * @param newValues        An array of new values to get set on the parameter
     * @throws ReportSDKException
     */
    public static void addDiscreteParameterValue (ReportClientDocument clientDoc, String subreportName,
                                                  String parameterName, Object[] newValues) throws ReportSDKException
    {
        clientDoc.getDataDefController ().getParameterFieldController ().setCurrentValues (subreportName, parameterName, newValues);
    }
 
    /**
     * Passes a single range parameter value to a report parameter.  The range is assumed to
     * be inclusive on beginning and end.
     * 
     * @param clientDoc        The reportClientDocument representing the report being used
     * @param subreportName    The name of the subreport.  If tables in the main report
     *                         is to be used, "" should be passed
     * @param parameterName    The name of the parameter
     * @param beginValue    The value of the beginning of the range
     * @param endValue        The value of the end of the range
     * @throws ReportSDKException
     */
    public static void addRangeParameterValue (ReportClientDocument clientDoc, String subreportName,
                                               String parameterName, Object beginValue, Object endValue)
            throws ReportSDKException
    {
        addRangeParameterValue (clientDoc, subreportName, parameterName, beginValue, RangeValueBoundType.inclusive, endValue, RangeValueBoundType.inclusive);
    }
 
    /**
     * Passes multiple range parameter values to a report parameter.
     *
     * This overload of the addRangeParameterValue will only work if the
     * parameter is setup to accept multiple values.
     * 
     * If the Parameter does not accept multiple values then it is expected that
     * this version of the method will return an error
     * 
     * @param clientDoc        The reportClientDocument representing the report being used
     * @param subreportName    The name of the subreport.  If tables in the main report
     *                         is to be used, "" should be passed
     * @param parameterName    The name of the parameter
     * @param beginValues    Array of beginning values.  Must be same length as endValues.
     * @param endValues        Array of ending values.  Must be same length as beginValues.
     * @throws ReportSDKException
     */
    public static void addRangeParameterValue (ReportClientDocument clientDoc, String subreportName,
                                               String parameterName, Object[] beginValues, Object[] endValues)
            throws ReportSDKException
    {
        addRangeParameterValue (clientDoc, subreportName, parameterName, beginValues, RangeValueBoundType.inclusive, endValues, RangeValueBoundType.inclusive);
    }
 
    /**
     * Passes a single range parameter value to a report parameter
     * 
     * @param clientDoc        The reportClientDocument representing the report being used
     * @param subreportName    The name of the subreport.  If tables in the main report
     *                         is to be used, "" should be passed
     * @param parameterName    The name of the parameter
     * @param beginValue    The value of the beginning of the range
     * @param lowerBoundType    The inclusion/exclusion range of the start of range.
     * @param endValue        The value of the end of the range
     * @param upperBoundType    The inclusion/exclusion range of the end of range.
     * @throws ReportSDKException
     */
    public static void addRangeParameterValue (ReportClientDocument clientDoc, String subreportName,
                                               String parameterName, Object beginValue,
                                               RangeValueBoundType lowerBoundType, Object endValue,
                                               RangeValueBoundType upperBoundType) throws ReportSDKException
    {
        DataDefController dataDefController = null;
        if (subreportName.equals (""))
        {
            dataDefController = clientDoc.getDataDefController ();
        }
        else
        {
            dataDefController = clientDoc.getSubreportController ().getSubreport (subreportName).getDataDefController ();
        }
 
        ParameterFieldRangeValue newRangeValue = new ParameterFieldRangeValue ();
        newRangeValue.setBeginValue (beginValue);
        newRangeValue.setLowerBoundType (lowerBoundType);
        newRangeValue.setEndValue (endValue);
        newRangeValue.setUpperBoundType (upperBoundType);
 
        ParameterField paramField = (ParameterField) dataDefController.getDataDefinition ().getParameterFields ().findField (parameterName, FieldDisplayNameType.fieldName, Locale.getDefault ());
        boolean multiValue = paramField.getAllowMultiValue ();
 
        if (multiValue)
        {
            Values newVals = (Values) paramField.getCurrentValues ().clone (true);
            newVals.add (newRangeValue);
            clientDoc.getDataDefController ().getParameterFieldController ().setCurrentValue (subreportName, parameterName, newVals);
        }
        else
        {
            clientDoc.getDataDefController ().getParameterFieldController ().setCurrentValue (subreportName, parameterName, newRangeValue);
        }
    }
 
    /**
     * Passes multiple range parameter values to a report parameter.
     *
     * This overload of the addRangeParameterValue will only work if the
     * parameter is setup to accept multiple values.
     * 
     * If the Parameter does not accept multiple values then it is expected that
     * this version of the method will return an error
     * 
     * @param clientDoc        The reportClientDocument representing the report being used
     * @param subreportName    The name of the subreport.  If tables in the main report
     *                         is to be used, "" should be passed
     * @param parameterName    The name of the parameter
     * @param beginValues    Array of beginning values.  Must be same length as endValues.
     * @param lowerBoundType    The inclusion/exclusion range of the start of range.
     * @param endValues        Array of ending values.  Must be same length as beginValues.
     * @param upperBoundType    The inclusion/exclusion range of the end of range.
     * 
     * @throws ReportSDKException
     */
    public static void addRangeParameterValue (ReportClientDocument clientDoc, String subreportName,
                                               String parameterName, Object[] beginValues,
                                               RangeValueBoundType lowerBoundType, Object[] endValues,
                                               RangeValueBoundType upperBoundType) throws ReportSDKException
    {
        // it is expected that the beginValues array is the same size as the endValues array
        ParameterFieldRangeValue[] newRangeValues = new ParameterFieldRangeValue[beginValues.length];
        for (int i = 0; i < beginValues.length; i++)
        {
            newRangeValues[i] = new ParameterFieldRangeValue ();
            newRangeValues[i].setBeginValue (beginValues[i]);
            newRangeValues[i].setLowerBoundType (lowerBoundType);
            newRangeValues[i].setEndValue (endValues[i]);
            newRangeValues[i].setUpperBoundType (upperBoundType);
        }
 
        clientDoc.getDataDefController ().getParameterFieldController ().setCurrentValues (subreportName, parameterName, newRangeValues);
    }
 
    /**
     * Exports a report to PDF
     * 
     * @param clientDoc        The reportClientDocument representing the report being used
     * @return An <code>InputStream</code> object containing the report document exported to the
     *         specified format.
     * @throws ReportSDKException
     */
    public static InputStream exportPDF (ReportClientDocument clientDoc) throws ReportSDKException
    {
        // PDF export allows page range export. The following routine ensures
        // that the requested page range is valid
        PDFExportFormatOptions pdfOptions = new PDFExportFormatOptions ();
        ExportOptions exportOptions = new ExportOptions ();
        exportOptions.setExportFormatType (ReportExportFormat.PDF);
        exportOptions.setFormatOptions (pdfOptions);
 
        // Export the report using the export options.
        return clientDoc.getPrintOutputController ().export (exportOptions);
    }
 
    /**
     * Exports a report to PDF for a range of pages
     * 
     * @param clientDoc        The reportClientDocument representing the report being used
     * @param startPage        Starting page
     * @param endPage        Ending page
     * @return An <code>InputStream</code> object containing the report document exported to the
     *         specified format.
     * @throws ReportSDKException
     */
    public static InputStream exportPDF (ReportClientDocument clientDoc, int startPage, int endPage)
            throws ReportSDKException
    {
        // PDF export allows page range export. The following routine ensures
        // that the requested page range is valid
        PDFExportFormatOptions pdfOptions = new PDFExportFormatOptions ();
        pdfOptions.setStartPageNumber (startPage);
        pdfOptions.setEndPageNumber (endPage);
        ExportOptions exportOptions = new ExportOptions ();
        exportOptions.setExportFormatType (ReportExportFormat.PDF);
        exportOptions.setFormatOptions (pdfOptions);
 
        // Export the report using the export options.
        return clientDoc.getPrintOutputController ().export (exportOptions);
    }
 
    /**
     * Exports a report to RTF
     * 
     * @param clientDoc        The reportClientDocument representing the report being used
     * @return An <code>InputStream</code> object containing the report document exported to the
     *         specified format.
     * @throws ReportSDKException
     */
    public static InputStream exportRTF (ReportClientDocument clientDoc) throws ReportSDKException
    {
        // RTF export allows page range export. The following routine ensures
        // that the requested page range is valid
        RTFWordExportFormatOptions rtfOptions = new RTFWordExportFormatOptions ();
        ExportOptions exportOptions = new ExportOptions ();
        exportOptions.setExportFormatType (ReportExportFormat.RTF);
        exportOptions.setFormatOptions (rtfOptions);
 
        // Export the report using the export options.
        return clientDoc.getPrintOutputController ().export (exportOptions);
    }
 
    /**
     * Exports a report to RTF for a range of pages
     * 
     * @param clientDoc        The reportClientDocument representing the report being used
     * @param startPage        Starting page
     * @param endPage        Ending page.  
     * @return An <code>InputStream</code> object containing the report document exported to the
     *         specified format.
     * @throws ReportSDKException
     */
    public static InputStream exportRTF (ReportClientDocument clientDoc, int startPage, int endPage)
            throws ReportSDKException
    {
        // RTF export allows page range export. The following routine ensures
        // that the requested page range is valid
        RTFWordExportFormatOptions rtfOptions = new RTFWordExportFormatOptions ();
        rtfOptions.setStartPageNumber (startPage);
        rtfOptions.setEndPageNumber (endPage);
        ExportOptions exportOptions = new ExportOptions ();
        exportOptions.setExportFormatType (ReportExportFormat.RTF);
        exportOptions.setFormatOptions (rtfOptions);
 
        // Export the report using the export options.
        return clientDoc.getPrintOutputController ().export (exportOptions);
    }
 
 
    /**
     * Exports a report to RTF (Editable)
     * 
     * @param clientDoc     The reportClientDocument representing the report being used
     * @return An <code>InputStream</code> object containing the report document exported to the
     *         specified format.
     * @throws ReportSDKException
     */
    public static InputStream exportRTFEditable (ReportClientDocument clientDoc) throws ReportSDKException
    {
        // RTF export allows page range export. The following routine ensures
        // that the requested page range is valid
        EditableRTFExportFormatOptions rtfOptions = new EditableRTFExportFormatOptions ();
        ExportOptions exportOptions = new ExportOptions ();
        exportOptions.setExportFormatType (ReportExportFormat.editableRTF);
        exportOptions.setFormatOptions (rtfOptions);
 
        // Export the report using the export options.
        return clientDoc.getPrintOutputController ().export (exportOptions);
    }
 
    /**
     * Exports a report to RTF (Editable) for a range of pages
     * 
     * @param clientDoc     The reportClientDocument representing the report being used
     * @param startPage     Starting page
     * @param endPage       Ending page.  
     * @return An <code>InputStream</code> object containing the report document exported to the
     *         specified format.
     * @throws ReportSDKException
     */
    public static InputStream exportRTFEditable (ReportClientDocument clientDoc, int startPage, int endPage)
            throws ReportSDKException
    {
        // RTF export allows page range export. The following routine ensures
        // that the requested page range is valid
        EditableRTFExportFormatOptions rtfOptions = new EditableRTFExportFormatOptions ();
        rtfOptions.setStartPageNumber (startPage);
        rtfOptions.setEndPageNumber (endPage);
        ExportOptions exportOptions = new ExportOptions ();
        exportOptions.setExportFormatType (ReportExportFormat.editableRTF);
        exportOptions.setFormatOptions (rtfOptions);
 
        // Export the report using the export options.
        return clientDoc.getPrintOutputController ().export (exportOptions);
    }    
 
    /**
     * Exports a report to CSV
     * 
     * @param clientDoc        The reportClientDocument representing the report being used
     * @return An <code>InputStream</code> object containing the report document exported to the
     *         specified format.
     * @throws ReportSDKException
     */
    public static InputStream exportCSV (ReportClientDocument clientDoc) throws ReportSDKException
    {
        CharacterSeparatedValuesExportFormatOptions csvOptions = new CharacterSeparatedValuesExportFormatOptions ();
        csvOptions.setSeparator (",");
        csvOptions.setDelimiter ("\n");
 
        ExportOptions exportOptions = new ExportOptions ();
        exportOptions.setExportFormatType (ReportExportFormat.characterSeparatedValues);
        exportOptions.setFormatOptions (csvOptions);
 
        // Export the report using the export options.
        return clientDoc.getPrintOutputController ().export (exportOptions);
    }
 
    /**
     * Exports a report to Excel (Data Only)
     * 
     * @param clientDoc     The reportClientDocument representing the report being used
     * @return An <code>InputStream</code> object containing the report document exported to the
     *         specified format.
     * @throws ReportSDKException
     */
    public static InputStream exportExcelDataOnly (ReportClientDocument clientDoc) throws ReportSDKException
    {
        ExportOptions exportOptions = new ExportOptions ();
        exportOptions.setExportFormatType (ReportExportFormat.recordToMSExcel);
        exportOptions.setFormatOptions (new DataOnlyExcelExportFormatOptions ());
 
        // Export the report using the export options.
        return clientDoc.getPrintOutputController ().export (exportOptions);
    }
 
    /**
     * Exports a report to Excel 
     * 
     * @param clientDoc     The reportClientDocument representing the report being used
     * @return An <code>InputStream</code> object containing the report document exported to the
     *         specified format.
     * @throws ReportSDKException
     */
    public static InputStream exportExcel (ReportClientDocument clientDoc) throws ReportSDKException
    {
        ExportOptions exportOptions = new ExportOptions ();
        exportOptions.setExportFormatType (ReportExportFormat.MSExcel);
        exportOptions.setFormatOptions (new ExcelExportFormatOptions ());
 
        // Export the report using the export options.
        return clientDoc.getPrintOutputController ().export (exportOptions);
    }    
    /**
     * Prints to the server printer
     * 
     * @param clientDoc        The reportClientDocument representing the report being used
     * @param printerName    Name of printer used to print the report
     * @throws ReportSDKPrinterException
     */
    public static void printToServer (ReportClientDocument clientDoc, String printerName) throws ReportSDKException
    {
        PrintReportOptions printOptions = new PrintReportOptions ();
        // Note: Printer with the <printer name> below must already be
        // configured.
        printOptions.setPrinterName (printerName);
        printOptions.setJobTitle ("Sample Print Job from JRC.");
        printOptions.setPrinterDuplex (PrinterDuplex.useDefault);
        printOptions.setPaperSource (PaperSource.auto);
        printOptions.setPaperSize (PaperSize.paperLetter);
        printOptions.setNumberOfCopies (1);
        printOptions.setCollated (false);
 
        // Print report
        clientDoc.getPrintOutputController ().printReport (printOptions);
    }
 
    /**
     * Prints a range of pages to the server printer
     * 
     * @param clientDoc        The reportClientDocument representing the report being used
     * @param printerName    Name of printer used to print the report
     * @param startPage        Starting page
     * @param endPage        Ending page.
     * @throws ReportSDKPrinterException
     */
    public static void printToServer (ReportClientDocument clientDoc, String printerName, int startPage, int endPage)
            throws ReportSDKException
    {
        PrintReportOptions printOptions = new PrintReportOptions ();
        // Note: Printer with the <printer name> below must already be
        // configured.
        printOptions.setPrinterName (printerName);
        printOptions.setJobTitle ("Sample Print Job from JRC.");
        printOptions.setPrinterDuplex (PrinterDuplex.useDefault);
        printOptions.setPaperSource (PaperSource.auto);
        printOptions.setPaperSize (PaperSize.paperLetter);
        printOptions.setNumberOfCopies (1);
        printOptions.setCollated (false);
        PrintReportOptions.PageRange printPageRange = new PrintReportOptions.PageRange (startPage, endPage);
        printOptions.addPrinterPageRange (printPageRange);
 
        // Print report
        clientDoc.getPrintOutputController ().printReport (printOptions);
    }
}
SampleViewerFrame
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
 * This sample code is an example of how to use the Business Objects APIs. 
 * Because the sample code is designed for demonstration only, it is 
 * unsupported.  You are free to modify and distribute the sample code as needed.   
 */
package com.businessobjects.samples;
 
import java.awt.BorderLayout;
import java.awt.Insets;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
 
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
 
import com.crystaldecisions.ReportViewer.ReportViewerBean;
import com.crystaldecisions.sdk.occa.report.application.OpenReportOptions;
import com.crystaldecisions.sdk.occa.report.application.ReportClientDocument;
import com.crystaldecisions.sdk.occa.report.lib.ReportSDKException;
 
/**
 * A sample report viewer class which can load a report and display it in 
 * a ReportViewerBean embedded in a JFrame.
 */
@SuppressWarnings("serial")
public class SampleViewerFrame extends JFrame
{
    public static final String FRAME_TITLE = "Sample Report Viewer";
 
    /** The report viewer bean instance. */ 
    private final ReportViewerBean reportViewer;
 
    /** The ReportClientDocument instance being used. 
     *  Set by loadReport(). */
    private ReportClientDocument reportClientDocument;
 
    /**
     * Private constructor for this class.
     * Call showViewer() to obtain instances.
     */
    private SampleViewerFrame() {
 
        setTitle (FRAME_TITLE);
 
        this.reportViewer = new ReportViewerBean();
        reportViewer.init ();
 
        // A menu bar can be added here if desired
 
        // Handle closing of the viewer.
        addWindowListener (new WindowAdapter ()
        {
            public void windowClosing (WindowEvent e)
            {
                closeViewer ();
            }
        });
 
        getContentPane ().add (reportViewer, BorderLayout.CENTER);
 
        // Set to some default size
        Insets insets = getInsets ();
        setSize (insets.left + 700 + insets.right, insets.top + 500 + insets.bottom);
 
        // Show in a sensible location for the platform.
        setLocationByPlatform (true);
    }
 
    /**
     * Create a new instance of this viewer class and show it.
     *
     * @return the new instance of this class that was created.
     */
    static SampleViewerFrame showViewerFrame () 
    {
        SampleViewerFrame viewerFrame = new SampleViewerFrame();
        viewerFrame.setVisible (true);
 
        // Start the viewer
        viewerFrame.reportViewer.start ();
 
        return viewerFrame;
    }
 
    /**
     * Entry point for this class.
     * Create and show the report viewer frame, then bind a report to it so that it can be viewed. 
     */
    public static void showViewer () 
    {
        SampleViewerFrame viewerFrame = showViewerFrame ();
        boolean success = viewerFrame.showReport ();
        if (!success) {
            viewerFrame.closeViewer ();
        }
    }
 
    /**
     * Close the viewer.
     */
    private void closeViewer ()
    {
        if (reportViewer != null)
        {
            reportViewer.stop ();
            reportViewer.destroy ();
        }
 
        removeAll ();
        dispose ();
    }
 
    /**
     * Load a report and show it in the viewer.
     * @return whether a report was successfully displayed.
     */
    private boolean showReport () 
    {
        try
        {
            loadReport ();
 
            if (reportClientDocument != null) {
                setDatabaseLogon ();
                setParameterFieldValues ();
                setReportSource ();
 
                return true;
            }
        }
        catch (ReportSDKException e)
        {
            String localizedMessage = e.getLocalizedMessage ();
            int errorCode = e.errorCode ();
 
            String title = "Problem showing report";
            String message = localizedMessage + "\nError code: " + errorCode;
            JOptionPane.showMessageDialog (SampleViewerFrame.this, message, title, JOptionPane.WARNING_MESSAGE);
        }
        return false;
    }
 
    /**
     * Determine which report to display, and use this to set the reportClientDocument field.
     * @throws ReportSDKException if there is a problem opening the specified document. 
     */
    private void loadReport () throws ReportSDKException
    {
        if (reportClientDocument == null) 
        {
            // Determine the report to display using a file chooser
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setDialogTitle ("Select a report to display");
            fileChooser.setFileFilter(new FileFilter() {
 
                @Override
                public boolean accept (File f)
                {
                    if (f != null) {
                        if (f.isDirectory()) {
                            return true;
                        }
                        return f.getName ().endsWith (".rpt");
                    }
                    return false;
                }
 
                @Override
                public String getDescription ()
                {
                    return "Crystal Reports (*.rpt)";
                }
            });
 
            int returnVal = fileChooser.showOpenDialog(SampleViewerFrame.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                String reportFilePath = fileChooser.getSelectedFile().getAbsolutePath ();
 
               // Create a new client document and use it to open the desired report.
               reportClientDocument = new ReportClientDocument ();
               reportClientDocument.setReportAppServer(ReportClientDocument.inprocConnectionString);
               reportClientDocument.open (reportFilePath, OpenReportOptions._openAsReadOnly);
            }
        }
    }
 
 
    /**
     * Set the database logon associated with the report document.
     * @throws ReportSDKException if there is a problem setting the database logon. 
     */
    private void setDatabaseLogon () throws ReportSDKException
    {
        // TODO Set up database logon here to have the report log onto the
    	// data sources defined in the report automatically, without prompting the
    	// user.  For more information about this feature, refer to the documentation.
    	// For example:
    	//  CRJavaHelper.logonDataSource (reportClientDocument, "username", "password");
    	// will log onto the data sources defined in the report with username "username"
    	// and password "password".
    }
 
    /**
     * Set values for parameter fields in the report document.
     * @throws ReportSDKException if there is a problem setting parameter field values. 
     */
    private void setParameterFieldValues () throws ReportSDKException
    {
    	// TODO Populate the parameter fields in the report document here, to
    	// view the report without prompting the user for parameter values.  For
    	// more information about this feature, refer to the documentation.
    	// For example:
        //  CRJavaHelper.addDiscreteParameterValue(reportClientDocument, "subreportName", 
    	//			"parameterName", newValue);
    	// will populate the discrete parameter "parameterName" under the subreport
    	// "subreportName" with a new value (newValue).  To set a parameter in the main
    	// report, use an empty string ("") instead of "subreportName".
    }
 
    /**
     * Bind the report document to the report viewer so that the report is displayed.
     */
    private void setReportSource ()
    {
        reportViewer.setReportSource (reportClientDocument.getReportSource ());
    }
}
et le lanceur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * This sample code is an example of how to use the Business Objects APIs. 
 * Because the sample code is designed for demonstration only, it is 
 * unsupported.  You are free to modify and distribute the sample code as needed.   
 */
package com.businessobjects.samples;
 
import com.crystaldecisions.sdk.occa.report.lib.ReportSDKException;
 
/**
 * Class with an entry point to display the SampleViewerFrame.
 */
public class SampleViewerFrameClient
{
    public static void main (String[] args) throws ReportSDKException
    {
        SampleViewerFrame.showViewer ();
    }
 
}