|
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 Save 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. |
| 10 | +Run the app and execute the following actions: |
11 | 11 |
|
12 | | -## Testing the example |
| 12 | +- Customize our predefined layout and save it to a new file. |
| 13 | +- Create a new report layout and save it to a file. |
| 14 | +- Import a report layout you created earlier from a file. |
13 | 15 |
|
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. |
| 16 | +<img width="450" src="./images/app.png" alt="An application with buttons to create a new report, import and save reports, open a report designer and report viewer" /> |
20 | 17 |
|
21 | | -## Documentation |
22 | 18 |
|
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) |
| 19 | +## Prerequisites |
25 | 20 |
|
26 | | -<!-- 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 --> |
| 21 | +See: [DevExpress Reports Prerequisites](https://docs.devexpress.com/VCL/405469/ExpressReports/vcl-reports#expressreports-prerequisites) |
| 22 | + |
| 23 | + |
| 24 | +## Implementation Details |
| 25 | + |
| 26 | +### Import a Report Layout from a File |
| 27 | + |
| 28 | +To import (load) a report layout from a file, call the |
| 29 | +[`Layout.LoadFromFile`](https://docwiki.embarcadero.com/Libraries/Athens/en/System.Classes.TStrings.LoadFromFile) |
| 30 | +method and assign a name to the |
| 31 | +[`ReportName`](https://docs.devexpress.com/VCL/dxReport.TdxReport.ReportName) property: |
| 32 | + |
| 33 | +**Delphi:** |
| 34 | +```delphi |
| 35 | +procedure TMainForm.ImportReport(const AFileName: string); |
| 36 | +begin |
| 37 | + // Import a report layout from a file |
| 38 | + dxReport1.Layout.LoadFromFile(AFileName); |
| 39 | + // Assign the file's name as an internal report name |
| 40 | + dxReport1.ReportName := ChangeFileExt(ExtractFileName(AFileName), ''); |
| 41 | +end; |
| 42 | +``` |
| 43 | + |
| 44 | +**C++Builder:** |
| 45 | +```cpp |
| 46 | +void __fastcall TMainForm::ImportReport(const String &FileName) |
| 47 | +{ |
| 48 | + // Import a report layout from a file |
| 49 | + dxReport1->Layout->LoadFromFile(FileName); |
| 50 | + // Assign the file's name as an internal report name |
| 51 | + dxReport1->ReportName = ChangeFileExt(ExtractFileName(FileName), ""); |
| 52 | +} |
| 53 | +``` |
| 54 | +
|
| 55 | +> [!Note] |
| 56 | +> An internal report name may differ from the source REPX file name. |
| 57 | +
|
| 58 | +
|
| 59 | +### Save a Report Layout to a File |
| 60 | +
|
| 61 | +To save the current report layout to a file, call the |
| 62 | +[`Layout.SaveToFile`](https://docwiki.embarcadero.com/Libraries/Athens/en/System.Classes.TStrings.SaveToFile) method: |
| 63 | +
|
| 64 | +**Delphi:** |
| 65 | +```delphi |
| 66 | +procedure TMainForm.SaveReport(const AFileName: string); |
| 67 | +begin |
| 68 | + // Save the report layout to a file |
| 69 | + dxReport1.Layout.SaveToFile(AFileName); |
| 70 | +end; |
| 71 | +``` |
| 72 | + |
| 73 | +**C++Builder:** |
| 74 | +```cpp |
| 75 | +void __fastcall TMainForm::SaveReport(const String &FileName) |
| 76 | +{ |
| 77 | + // Save the report layout to a file |
| 78 | + dxReport1->Layout->SaveToFile(FileName); |
| 79 | +} |
| 80 | +``` |
| 81 | +
|
| 82 | +> [!Note] |
| 83 | +> Internal report names are not stored in REPX files. |
33 | 84 |
|
34 | 85 |
|
| 86 | +## Test the Example |
35 | 87 |
|
| 88 | +### Modify the Pre-loaded Layout and Save to a New File |
| 89 | +
|
| 90 | +The example application loads a predefined layout at startup: `TableReport.repx`. |
| 91 | +You can modify this preloaded report layout and then save changes to a REPX file. |
| 92 | +
|
| 93 | +1. Build and run the sample application. |
| 94 | + Note the preloaded layout's name in the application's caption. |
| 95 | +2. Click **Open Designer** to edit the loaded layout in the DevExpress |
| 96 | + [Report Designer](https://docs.devexpress.com/XtraReports/119176/web-reporting/web-end-user-report-designer). |
| 97 | + Modify the layout as you see fit. |
| 98 | +3. Once you have made changes in the **Report Designer** dialog, click the hamburger button, select **Save**, and close the dialog. |
| 99 | +4. Click **Save to File** to save the report layout to 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 Save a New Layout |
| 107 | +
|
| 108 | +You can design a new layout from scratch and then save it to a REPX file: |
| 109 | +
|
| 110 | +1. Build and run the sample 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 have made all necessary 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 | +5. Click **Save to File** to save the report layout to a REPX file. |
| 117 | +6. Restart the application and click **Import from File** to import a report layout from the previously saved REPX file. |
| 118 | +7. Click **Open Viewer** to display the imported layout in the DevExpress |
| 119 | + [Report Viewer](https://docs.devexpress.com/XtraReports/401850/web-reporting/web-document-viewer). |
| 120 | +
|
| 121 | +
|
| 122 | +## Documentation and Examples |
| 123 | +
|
| 124 | +- [Introduction to VCL Reports](https://docs.devexpress.com/VCL/405469/ExpressReports/vcl-reports) |
| 125 | +- [How to store report layouts in REPX files at design-time](https://docs.devexpress.com/VCL/dxReport.TdxReport.Layout#string-list-editor) |
| 126 | +- [How to store report layouts in a database (example application)](https://github.com/DevExpress-Examples/vcl-reports-store-layout-template-database) |
| 127 | +- [How to use SQLite as a data source for reports (as demonstrated in this example)](https://docs.devexpress.com/VCL/405750/ExpressCrossPlatformLibrary/vcl-backend/database-engines/vcl-backend-sqlite-support) |
| 128 | +- [TdxReport.Layout Property API reference](https://docs.devexpress.com/VCL/dxReport.TdxReport.Layout) |
| 129 | +- [TdxBackendDatabaseSQLConnection Component API reference](https://docs.devexpress.com/VCL/dxBackend.ConnectionString.SQL.TdxBackendDatabaseSQLConnection) |
| 130 | +
|
| 131 | +
|
| 132 | +<!-- feedback --> |
| 133 | +## Does this example address your development requirements/objectives? |
| 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) |
| 136 | +
|
| 137 | +(you will be redirected to DevExpress.com to submit your response) |
| 138 | +<!-- feedback end --> |
0 commit comments