|
1 | 1 | <!-- default badges list --> |
2 | | - |
3 | 2 | [](https://supportcenter.devexpress.com/ticket/details/T1306454) |
4 | 3 | [](https://docs.devexpress.com/GeneralInformation/403183) |
5 | 4 | [](#does-this-example-address-your-development-requirementsobjectives) |
6 | 5 | <!-- default badges end --> |
7 | 6 |
|
8 | | -# DevExpress VCL Reports - Store Report Layouts within Text Files |
| 7 | +# DevExpress VCL Reports – Import and Export Report Layouts to XML Files |
9 | 8 |
|
10 | | -This example stores a [report layout](https://docs.devexpress.com/VCL/dxReport.TdxReport.Layout) (XML-based template) within a text file. |
| 9 | +This example uses XML-based REPX files as [report layout](https://docs.devexpress.com/VCL/dxReport.TdxReport.Layout) storage. Run the app and try the following actions: |
11 | 10 |
|
12 | | -## Testing the example |
| 11 | +- Customize the predefined layout and export it to a new file. |
| 12 | +- Create a new report layout and export it to a file. |
| 13 | +- Import a report layout you created earlier from a file. |
13 | 14 |
|
14 | | -* Run the sample app and click **New Report**. |
15 | | -* Create a report layout (template) using tools available in the DevExpress [Report Designer](https://docs.devexpress.com/XtraReports/119176/web-reporting/web-end-user-report-designer). |
16 | | -* Click the hamburger button, select the **Save** option, enter a report template name, and close the dialog. |
17 | | -* Click **Save Report** to export the generated report template as a REPX file. |
18 | | -* Restart the app and click **Open Report** to import a report template from a previously saved REPX file. |
19 | | -* Click **Show Designer** to display the imported template. |
| 15 | +<img width="450" src="./images/app.png" alt="An application that includes buttons designed to create a new report, import and export reports, open a report designer and report viewer" /> |
20 | 16 |
|
21 | | -## Documentation |
22 | 17 |
|
23 | | -* [TdxReport.Layout Property](https://docs.devexpress.com/VCL/dxReport.TdxReport.Layout) |
24 | | -* [TdxReportDataSetJSONConnection Component](https://docs.devexpress.com/VCL/dxReport.ConnectionString.JSON.DB.TdxReportDataSetJSONConnection) |
| 18 | +## Prerequisites |
| 19 | + |
| 20 | +See the [DevExpress Reports Prerequisites](https://docs.devexpress.com/VCL/405469/ExpressReports/vcl-reports#expressreports-prerequisites). |
| 21 | + |
| 22 | + |
| 23 | +## Implementation Details |
| 24 | + |
| 25 | +### Import a Report Layout from a File |
| 26 | + |
| 27 | +To import (load) a report layout from a file, call the |
| 28 | +[`Layout.LoadFromFile`](https://docwiki.embarcadero.com/Libraries/Athens/en/System.Classes.TStrings.LoadFromFile) |
| 29 | +method and assign a name to the |
| 30 | +[`ReportName`](https://docs.devexpress.com/VCL/dxReport.TdxReport.ReportName) property: |
| 31 | + |
| 32 | +**Delphi:** |
| 33 | +```delphi |
| 34 | +procedure TMainForm.ImportReport(const AFileName: string); |
| 35 | +begin |
| 36 | + // Import a report layout from a file |
| 37 | + dxReport1.Layout.LoadFromFile(AFileName); |
| 38 | + // Assign the file's name as an internal report name |
| 39 | + dxReport1.ReportName := ChangeFileExt(ExtractFileName(AFileName), ''); |
| 40 | +end; |
| 41 | +``` |
| 42 | + |
| 43 | +**C++Builder:** |
| 44 | +```cpp |
| 45 | +void __fastcall TMainForm::ImportReport(const String &FileName) |
| 46 | +{ |
| 47 | + // Import a report layout from a file |
| 48 | + dxReport1->Layout->LoadFromFile(FileName); |
| 49 | + // Assign the file's name as an internal report name |
| 50 | + dxReport1->ReportName = ChangeFileExt(ExtractFileName(FileName), ""); |
| 51 | +} |
| 52 | +``` |
| 53 | +
|
| 54 | +> [!Note] |
| 55 | +> An internal report name may differ from the source REPX file name. |
| 56 | +
|
| 57 | +
|
| 58 | +### Export a Report Layout to a File |
| 59 | +
|
| 60 | +To export (save) the current report layout to a file, call the |
| 61 | +[`Layout.SaveToFile`](https://docwiki.embarcadero.com/Libraries/Athens/en/System.Classes.TStrings.SaveToFile) method: |
| 62 | +
|
| 63 | +**Delphi:** |
| 64 | +```delphi |
| 65 | +procedure TMainForm.ExportReport(const AFileName: string); |
| 66 | +begin |
| 67 | + // Export the report layout to a file |
| 68 | + dxReport1.Layout.SaveToFile(AFileName); |
| 69 | +end; |
| 70 | +``` |
| 71 | + |
| 72 | +**C++Builder:** |
| 73 | +```cpp |
| 74 | +void __fastcall TMainForm::ExportReport(const String &FileName) |
| 75 | +{ |
| 76 | + // Export the report layout to a file |
| 77 | + dxReport1->Layout->SaveToFile(FileName); |
| 78 | +} |
| 79 | +``` |
| 80 | +
|
| 81 | +> [!Note] |
| 82 | +> Internal report names are not exported to REPX files. |
| 83 | +
|
| 84 | +
|
| 85 | +## Test the Example |
| 86 | +
|
| 87 | +### Modify the Pre-loaded Layout and Export to a New File |
| 88 | +
|
| 89 | +The example application loads a predefined layout at startup: `TableReport.repx`. |
| 90 | +You can modify this preloaded report layout and then save changes to a REPX file. |
| 91 | +
|
| 92 | +1. Build and run the example application. |
| 93 | + Note the preloaded layout's name in the application's caption. |
| 94 | +2. Click **Open Designer** to edit the loaded layout in the DevExpress |
| 95 | + [Report Designer](https://docs.devexpress.com/XtraReports/119176/web-reporting/web-end-user-report-designer). |
| 96 | + Modify the layout as you see fit. |
| 97 | +3. Once you're done with changes in the **Report Designer** dialog, click the hamburger button, select **Save**, and close the dialog. |
| 98 | + Now you have saved changes in the report. |
| 99 | +4. Click **Export to File** to export the generated report layout as a REPX file. |
| 100 | + You can overwrite an existing file or create a new file. |
| 101 | +5. Restart the application and click **Import from File** to import a report layout from the previously saved REPX file. |
| 102 | +6. Click **Open Viewer** to display the imported layout in the DevExpress |
| 103 | + [Report Viewer](https://docs.devexpress.com/XtraReports/401850/web-reporting/web-document-viewer). |
| 104 | +
|
| 105 | +
|
| 106 | +### Create, Design, and Export a New Layout |
| 107 | +
|
| 108 | +You can design a new layout from scratch and then export it to a REPX file: |
| 109 | +
|
| 110 | +1. Build and run the example application. |
| 111 | +2. Click **Create New** to open a new blank report layout in the DevExpress |
| 112 | + [Report Designer](https://docs.devexpress.com/XtraReports/119176/web-reporting/web-end-user-report-designer). |
| 113 | +3. Design the report layout (template) using tools available in the **Report Designer**. |
| 114 | +4. Once you're done with changes in the **Report Designer** dialog, click the hamburger button, select **Save**, and enter a report layout name. |
| 115 | + Click **Save** and close the dialog. |
| 116 | + Now you have saved changes in the report. |
| 117 | +5. Click **Export to File** to export the generated report layout as a REPX file. |
| 118 | +6. Restart the application and click **Import from File** to import a report layout from the previously saved REPX file. |
| 119 | +7. Click **Open Viewer** to display the imported layout in the DevExpress |
| 120 | + [Report Viewer](https://docs.devexpress.com/XtraReports/401850/web-reporting/web-document-viewer). |
| 121 | +
|
| 122 | +
|
| 123 | +## Documentation and Examples |
| 124 | +
|
| 125 | +- [VCL Reports: Getting Started](https://docs.devexpress.com/VCL/405761/ExpressReports/vcl-reports-getting-started) |
| 126 | +- [VCL Reports Backend: How to Use SQLite](https://docs.devexpress.com/VCL/405750/ExpressCrossPlatformLibrary/vcl-backend/database-engines/vcl-backend-sqlite-support) |
| 127 | +- [VCL Reports: Store Report Layouts in a Database](https://github.com/DevExpress-Examples/vcl-reports-store-layout-template-database) |
| 128 | +- [TdxReport.Layout Property](https://docs.devexpress.com/VCL/dxReport.TdxReport.Layout) |
| 129 | +- [TdxBackendDatabaseSQLConnection Component](https://docs.devexpress.com/VCL/dxBackend.ConnectionString.SQL.TdxBackendDatabaseSQLConnection) |
| 130 | +
|
25 | 131 |
|
26 | 132 | <!-- feedback --> |
27 | | -## Does this example address your development requirements/objectives? |
28 | | - |
29 | | -[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=vcl-reports-store-layout-template-file&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=vcl-reports-store-layout-template-file&~~~was_helpful=no) |
30 | | - |
31 | | -(you will be redirected to DevExpress.com to submit your response) |
32 | | -<!-- feedback end --> |
| 133 | +## Does this example address your development requirements/objectives? |
33 | 134 |
|
| 135 | +[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=vcl-reports-store-layout-template-file&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=vcl-reports-store-layout-template-file&~~~was_helpful=no) |
34 | 136 |
|
| 137 | +(you will be redirected to DevExpress.com to submit your response) |
| 138 | +<!-- feedback end --> |
35 | 139 |
|
0 commit comments