Back to Devexpress

TdxCustomChartControl.ExportToDOCX(TStream,Integer,Integer) Method

vcl-dxchartcontrol-dot-tdxcustomchartcontrol-dot-exporttodocx-x28-system-dot-classes-dot-tstream-system-dot-integer-system-dot-integer-x29.md

latest7.2 KB
Original Source

TdxCustomChartControl.ExportToDOCX(TStream,Integer,Integer) Method

Exports content as an image container within a DOCX (Office OpenXML) document and saves it to the target stream.

Declaration

delphi
procedure ExportToDOCX(const AStream: TStream; AImageWidth: Integer = 0; AImageHeight: Integer = 0); overload;

Parameters

NameTypeDescription
AStreamTStream

The target stream.

| | AImageWidth | Integer |

Optional. The width (in pixels) of the chart image inserted into the resulting DOCX document. If this parameter is omitted, the pixel width of the resulting image container in the created document matches the current pixel width of the Chart control client area on the parent form.

The export procedure stretches or shrinks the Chart control layout horizontally to fit the resulting image in a document into the target width. If target image dimensions exceed the document page width, the export procedure proportionally shrinks the image to fit it into the page.

All font sizes remain unchanged. If title or label text does not fit into the corresponding visual Chart element, the Chart control crops the text and ends it with an ellipsis in the exported layout.

| | AImageHeight | Integer |

Optional. The height (in pixels) of the chart image inserted into the resulting DOCX document. If this parameter is omitted, the pixel height of the resulting image container in the created document matches the current pixel height of the Chart control client area on the parent form.

The export procedure stretches or shrinks the Chart control layout vertically to fit the resulting image in a document into the target height. If target image dimensions exceed the document page height, the export procedure proportionally shrinks the image to fit it into the page.

All font sizes remain unchanged. If title or label text does not fit into the corresponding visual Chart element, the Chart control crops the text and ends it with an ellipsis in the exported layout.

|

Remarks

Call the ExportToDOCX procedure to save content of the Chart control client area as an inline image container in a DOCX document created in the target stream. The resulting image size matches the actual pixel dimensions of the Chart control client area on a form.

If the resulting image width or height exceeds the document page width or height, the ExportToDOCX procedure shrinks the image proportionally to fit it into the page.

Exported Content Example

The following image demonstrates a DOCX document with exported chart content opened in a VCL Rich Edit Control-based application:

Code Example: Export Chart Content as DOCX

The following code example exports shrunk content of the Chart control client area (original dimensions on the parent form are 600 by 700 pixels):

delphi
var
  AStream: TMemoryStream;
begin
  dxSavePictureDialog1.Execute(Handle);
  if dxSavePictureDialog1.FileName = '' then Exit;
  AStream := TMemoryStream.Create;
  try
    dxChartControl1.ExportToDOCX(AStream, 315, 385);
    AStream.SaveToFile(dxSavePictureDialog1.FileName);
  finally
    AStream.Free;
  end;
end;
cpp
TMemoryStream *AStream = nullptr;
  // ...
  dxSavePictureDialog1->Execute(Handle);
  if(dxSavePictureDialog1->FileName == "") { return; }
  AStream = new TMemoryStream();
  try
  {
    dxChartControl1->ExportToDOCX(AStream, 315, 385);
    AStream->SaveToFile(dxSavePictureDialog1->FileName);
  }
  __finally
  {
    delete AStream;
  }

To see the export to DOCX functionality in action, run the Chart Control demo in the VCL Demo Center installed with compiled DevExpress VCL demos. Click Export and choose the Export to DOCX option to export chart content in the DOCX (Office OpenXML Document) format.

Download: Compiled VCL Demos

Tip

Compiled DevExpress demos ship with source code installed in the Public Documents folder (%Public%) for all users ( default ). You can find all project and source code files for the Chart control in the following folder:

_%Public%\Documents\DevExpress VCL Demos\MegaDemos\Product Demos\ExpressChart_

Other Export Methods

You can call the following procedures to export chart content to a file or stream in other formats:

ExportToImageExport the current state of the Chart control client area as an individual image in any supported format.ExportToBMP | ExportToGIF | ExportToJPEG | ExportToPNG | ExportToSVG | ExportToTIFFExport the current state of the Chart control client area as an individual image in corresponding formats.ExportToXLSXExports the current state of the Chart control client area as an inline or floating image in the XLSX (Office OpenXML Spreadsheet) document.ExportToEMF | ExportToWMFExport the current state of the Chart control client area as an individual image in Windows Metafile (EMF and WMF) formats. See Also

TdxCustomChartControl.ExportToDOCX(System.String,System.Integer,System.Integer) Procedure

TdxCustomChartControl.ExportToXLSX(System.Classes.TStream,System.Integer,System.Integer) Procedure

TdxCustomChartControl.ExportToXLSX(System.String,System.Integer,System.Integer) Procedure

TdxCustomChartControl Class

TdxCustomChartControl Members

dxChartControl Unit