wpf-devexpress-dot-xpf-dot-map-dot-mapcontrol-dot-exporttoxlsx-x28-system-dot-string-x29.md
Using file paths sourced from untrusted input may expose unauthorized files or allow unintended file access. Always validate and normalize all external paths to prevent path manipulation.
Exports the map data to the specified XLSX file.
Namespace : DevExpress.Xpf.Map
Assembly : DevExpress.Xpf.Map.v25.2.dll
NuGet Package : DevExpress.Wpf.Map
public void ExportToXlsx(
string filePath
)
Public Sub ExportToXlsx(
filePath As String
)
| Name | Type | Description |
|---|---|---|
| filePath | String |
A string value, specifying the file path.
|
To export a map image to a file, use one of the following methods.
MapControl.ExportToHtml - exports the map to a *.HTML file;
MapControl.ExportToImage - exports the map to an image file;
MapControl.ExportToMht - exports the map to a *.MHT file;
MapControl.ExportToPdf - exports the map to a *.PDF file;
MapControl.ExportToRtf - exports the map to a *.RTF file;
MapControl.ExportToXls - exports the map to a *.XLS file;
MapControl.ExportToXlsx - exports the map to a *.XLSX file;
MapControl.ExportToXps - exports the map to a *.XPS file;
using System;
using System.Windows;
using DevExpress.XtraPrinting;
namespace Exporting {
public partial class MainWindow : Window {
const string filename = "exportedMap";
public MainWindow() {
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e) {
ExportFormat format = (ExportFormat)cbExportFormat.SelectedItem;
string filepath;
if (format == ExportFormat.Image)
filepath = String.Format("{0}.jpg", filename);
else
filepath = String.Format("{0}.{1}", filename, format);
bool isExported = true;
switch (format) {
case (ExportFormat.Htm):
mapControl.ExportToHtml(filepath);
break;
case (ExportFormat.Image):
mapControl.ExportToImage(filepath);
break;
case (ExportFormat.Mht):
mapControl.ExportToMht(filepath);
break;
case (ExportFormat.Pdf):
mapControl.ExportToPdf(filepath);
break;
case (ExportFormat.Rtf):
mapControl.ExportToRtf(filepath);
break;
case (ExportFormat.Xls):
mapControl.ExportToXls(filepath);
break;
case (ExportFormat.Xlsx):
mapControl.ExportToXlsx(filepath);
break;
case (ExportFormat.Xps):
mapControl.ExportToXps(filepath);
break;
default:
isExported = false;
break;
}
if (isExported)
MessageBox.Show(String.Format("Map exported successfully."));
else
MessageBox.Show(String.Format("Map exporting does not support the {0} file format.", format));
}
}
}
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map"
xmlns:dxp="clr-namespace:DevExpress.XtraPrinting;assembly=DevExpress.Printing.v14.2.Core"
x:Class="Exporting.MainWindow"
Title="MainWindow" Height="600" Width="800">
<Window.Resources>
<ObjectDataProvider x:Key="ExportFormatValues"
MethodName="GetValues"
ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="dxp:ExportFormat"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ObjectDataProvider x:Key="MapPrintSizeModeValues"
MethodName="GetValues"
ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="dxm:MapPrintSizeMode"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<Grid>
<dxlc:LayoutControl Orientation="Vertical">
<dxlc:LayoutItem VerticalAlignment="Stretch">
<dxm:MapControl x:Name="mapControl">
<dxm:MapControl.PrintOptions>
<dxm:MapPrintOptions SizeMode="{Binding SelectedItem, ElementName=cbPrintSizeMode}"/>
</dxm:MapControl.PrintOptions>
<dxm:ImageTilesLayer>
<dxm:ImageTilesLayer.DataProvider>
<dxm:BingMapDataProvider BingKey="Your Bing Key"/>
</dxm:ImageTilesLayer.DataProvider>
</dxm:ImageTilesLayer>
</dxm:MapControl>
</dxlc:LayoutItem>
<dxlc:LayoutGroup>
<dxlc:LayoutItem Label="Print Size Mode:">
<ComboBox x:Name="cbPrintSizeMode"
ItemsSource="{Binding Source={StaticResource MapPrintSizeModeValues}}"
SelectedIndex="0"/>
</dxlc:LayoutItem>
<dxlc:LayoutItem Label="Export to" AddColonToLabel="True">
<ComboBox x:Name="cbExportFormat"
ItemsSource="{Binding Source={StaticResource ExportFormatValues}}"
SelectedIndex="0"/>
</dxlc:LayoutItem>
<dxlc:LayoutItem Width="100">
<Button Content="Export" Click="Button_Click"/>
</dxlc:LayoutItem>
</dxlc:LayoutGroup>
</dxlc:LayoutControl>
</Grid>
</Window>
Imports System
Imports System.Windows
Imports DevExpress.XtraPrinting
Namespace Exporting
Partial Public Class MainWindow
Inherits Window
Private Const filename As String = "exportedMap"
Public Sub New()
InitializeComponent()
End Sub
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim format As ExportFormat = CType(cbExportFormat.SelectedItem, ExportFormat)
Dim filepath As String
If format = ExportFormat.Image Then
filepath = String.Format("{0}.jpg", filename)
Else
filepath = String.Format("{0}.{1}", filename, format)
End If
Dim isExported As Boolean = True
Select Case format
Case (ExportFormat.Htm)
mapControl.ExportToHtml(filepath)
Case (ExportFormat.Image)
mapControl.ExportToImage(filepath)
Case (ExportFormat.Mht)
mapControl.ExportToMht(filepath)
Case (ExportFormat.Pdf)
mapControl.ExportToPdf(filepath)
Case (ExportFormat.Rtf)
mapControl.ExportToRtf(filepath)
Case (ExportFormat.Xls)
mapControl.ExportToXls(filepath)
Case (ExportFormat.Xlsx)
mapControl.ExportToXlsx(filepath)
Case (ExportFormat.Xps)
mapControl.ExportToXps(filepath)
Case Else
isExported = False
End Select
If isExported Then
MessageBox.Show(String.Format("Map exported successfully."))
Else
MessageBox.Show(String.Format("Map exporting does not support the {0} file format.", format))
End If
End Sub
End Class
End Namespace
Imports System
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Threading.Tasks
Imports System.Windows
Namespace Exporting
''' <summary>
''' Interaction logic for App.xaml
''' </summary>
Partial Public Class App
Inherits Application
End Class
End Namespace
<Application x:Class="Exporting.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
See Also