From 775d561ee6427467aecfbe698b66ff7dd1d0debb Mon Sep 17 00:00:00 2001 From: SethupathyD Date: Mon, 5 Aug 2024 19:32:34 +0530 Subject: [PATCH] Code updated. --- README.md | 77 +++- SfDataGridSample/App.xaml | 14 + SfDataGridSample/App.xaml.cs | 12 + SfDataGridSample/AppShell.xaml | 15 + SfDataGridSample/AppShell.xaml.cs | 10 + SfDataGridSample/Helper/SaveService.cs | 14 + SfDataGridSample/MainPage.xaml | 43 ++ SfDataGridSample/MainPage.xaml.cs | 88 ++++ SfDataGridSample/MauiProgram.cs | 27 ++ SfDataGridSample/Model/Employee.cs | 167 +++++++ .../Platforms/Android/AndroidManifest.xml | 17 + .../Platforms/Android/MainActivity.cs | 11 + .../Platforms/Android/MainApplication.cs | 16 + .../Android/Resources/values/colors.xml | 6 + .../Android/Resources/xml/provider_paths.xml | 4 + .../Platforms/Android/SaveAndroid.cs | 75 +++ .../Platforms/MacCatalyst/AppDelegate.cs | 10 + .../Platforms/MacCatalyst/Entitlements.plist | 14 + .../Platforms/MacCatalyst/Info.plist | 38 ++ .../Platforms/MacCatalyst/Program.cs | 16 + SfDataGridSample/Platforms/Tizen/Main.cs | 17 + .../Platforms/Tizen/tizen-manifest.xml | 15 + SfDataGridSample/Platforms/Windows/App.xaml | 8 + .../Platforms/Windows/App.xaml.cs | 25 + .../Platforms/Windows/Package.appxmanifest | 46 ++ .../Platforms/Windows/SaveWindows.cs | 72 +++ .../Platforms/Windows/app.manifest | 15 + SfDataGridSample/Platforms/iOS/AppDelegate.cs | 10 + SfDataGridSample/Platforms/iOS/Info.plist | 32 ++ SfDataGridSample/Platforms/iOS/Program.cs | 16 + SfDataGridSample/Platforms/iOS/SaveIOS.cs | 120 +++++ .../Properties/launchSettings.json | 8 + .../Resources/AppIcon/appicon.svg | 4 + .../Resources/AppIcon/appiconfg.svg | 8 + .../Resources/Fonts/OpenSans-Regular.ttf | Bin 0 -> 107184 bytes .../Resources/Fonts/OpenSans-Semibold.ttf | Bin 0 -> 111072 bytes .../Resources/Images/dotnet_bot.png | Bin 0 -> 69811 bytes .../Resources/Raw/AboutAssets.txt | 15 + SfDataGridSample/Resources/Splash/splash.svg | 8 + SfDataGridSample/Resources/Styles/Colors.xaml | 45 ++ SfDataGridSample/Resources/Styles/Styles.xaml | 426 ++++++++++++++++++ SfDataGridSample/SfDataGridSample.csproj | 71 +++ SfDataGridSample/SfDataGridSample.csproj.user | 36 ++ SfDataGridSample/SfDataGridSample.sln | 27 ++ .../ViewModel/EmployeeViewModel.cs | 273 +++++++++++ 45 files changed, 1969 insertions(+), 2 deletions(-) create mode 100644 SfDataGridSample/App.xaml create mode 100644 SfDataGridSample/App.xaml.cs create mode 100644 SfDataGridSample/AppShell.xaml create mode 100644 SfDataGridSample/AppShell.xaml.cs create mode 100644 SfDataGridSample/Helper/SaveService.cs create mode 100644 SfDataGridSample/MainPage.xaml create mode 100644 SfDataGridSample/MainPage.xaml.cs create mode 100644 SfDataGridSample/MauiProgram.cs create mode 100644 SfDataGridSample/Model/Employee.cs create mode 100644 SfDataGridSample/Platforms/Android/AndroidManifest.xml create mode 100644 SfDataGridSample/Platforms/Android/MainActivity.cs create mode 100644 SfDataGridSample/Platforms/Android/MainApplication.cs create mode 100644 SfDataGridSample/Platforms/Android/Resources/values/colors.xml create mode 100644 SfDataGridSample/Platforms/Android/Resources/xml/provider_paths.xml create mode 100644 SfDataGridSample/Platforms/Android/SaveAndroid.cs create mode 100644 SfDataGridSample/Platforms/MacCatalyst/AppDelegate.cs create mode 100644 SfDataGridSample/Platforms/MacCatalyst/Entitlements.plist create mode 100644 SfDataGridSample/Platforms/MacCatalyst/Info.plist create mode 100644 SfDataGridSample/Platforms/MacCatalyst/Program.cs create mode 100644 SfDataGridSample/Platforms/Tizen/Main.cs create mode 100644 SfDataGridSample/Platforms/Tizen/tizen-manifest.xml create mode 100644 SfDataGridSample/Platforms/Windows/App.xaml create mode 100644 SfDataGridSample/Platforms/Windows/App.xaml.cs create mode 100644 SfDataGridSample/Platforms/Windows/Package.appxmanifest create mode 100644 SfDataGridSample/Platforms/Windows/SaveWindows.cs create mode 100644 SfDataGridSample/Platforms/Windows/app.manifest create mode 100644 SfDataGridSample/Platforms/iOS/AppDelegate.cs create mode 100644 SfDataGridSample/Platforms/iOS/Info.plist create mode 100644 SfDataGridSample/Platforms/iOS/Program.cs create mode 100644 SfDataGridSample/Platforms/iOS/SaveIOS.cs create mode 100644 SfDataGridSample/Properties/launchSettings.json create mode 100644 SfDataGridSample/Resources/AppIcon/appicon.svg create mode 100644 SfDataGridSample/Resources/AppIcon/appiconfg.svg create mode 100644 SfDataGridSample/Resources/Fonts/OpenSans-Regular.ttf create mode 100644 SfDataGridSample/Resources/Fonts/OpenSans-Semibold.ttf create mode 100644 SfDataGridSample/Resources/Images/dotnet_bot.png create mode 100644 SfDataGridSample/Resources/Raw/AboutAssets.txt create mode 100644 SfDataGridSample/Resources/Splash/splash.svg create mode 100644 SfDataGridSample/Resources/Styles/Colors.xaml create mode 100644 SfDataGridSample/Resources/Styles/Styles.xaml create mode 100644 SfDataGridSample/SfDataGridSample.csproj create mode 100644 SfDataGridSample/SfDataGridSample.csproj.user create mode 100644 SfDataGridSample/SfDataGridSample.sln create mode 100644 SfDataGridSample/ViewModel/EmployeeViewModel.cs diff --git a/README.md b/README.md index 9cd98f4..3070459 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,75 @@ -# How-can-we-fetch-excel-file-with-file-picker-in-.NET-MAUI-DataGrid -How can we fetch excel file with file picker in .NET MAUI DataGrid +# How can we fetch a excel file with file picker and import data into the .NET MAUI DataGrid? +In this article, we will show you how can we fetch a excel file with file picker and import data into the [.Net Maui DataGrid](https://www.syncfusion.com/maui-controls/maui-datagrid). + +## C# +The below code illustrates how to fetch a excel file with file picker and import data into the DataGrid. +``` + void Import_Clicked(System.Object sender, System.EventArgs e) + { + LoadDataGridAsync(); + } + + private async Task LoadDataGridAsync() + { + //Creates a new instance for ExcelEngine + ExcelEngine excelEngine = new ExcelEngine(); + + //Initialize IApplication + Syncfusion.XlsIO.IApplication application = excelEngine.Excel; + + + var customFileType = new FilePickerFileType( + new Dictionary> + { + // iOS: using Uniform Type Identifiers (UTIs) + { DevicePlatform.iOS, new[] { "public.data" } }, + + // Android: using MIME types + { DevicePlatform.Android, new[] { "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" } }, + + // Windows: using file extensions + { DevicePlatform.WinUI, new[] { ".xlsx" } }, + }); + + PickOptions pickOptions = new PickOptions() + { + PickerTitle = "Please select DataGrid file", + FileTypes = customFileType, + }; + + var result = await FilePicker.Default.PickAsync(pickOptions); + if (result != null) + { + //Load the file into stream + Stream inputStream = await result.OpenReadAsync(); + + //Loads or open an existing workbook through Open method of IWorkbooks + IWorkbook workbook = excelEngine.Excel.Workbooks.Open(inputStream); + + IWorksheet worksheet = workbook.Worksheets[0]; + + DataTable customersTable = worksheet.ExportDataTable(1, 1, 10, 6, ExcelExportDataTableOptions.ColumnNames); + + this.dataGrid.ItemsSource = customersTable; + + workbook.Close(); + } + + excelEngine.Dispose(); + } +``` + + ![FilePicker.png](https://support.syncfusion.com/kb/agent/attachment/inline?token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjI3NzczIiwib3JnaWQiOiIzIiwiaXNzIjoic3VwcG9ydC5zeW5jZnVzaW9uLmNvbSJ9.lNSPuqqSHipgdcTfTf8_nieKs-jomRpzqVzN5sxg7gc) + +[View sample in GitHub](https://github.com/SyncfusionExamples/How-can-we-fetch-excel-file-with-file-picker-in-.NET-MAUI-DataGrid) + +Take a moment to explore this [documentation](https://help.syncfusion.com/maui/datagrid/overview), where you can find more information about Syncfusion .NET MAUI DataGrid (SfDataGrid) with code examples. Please refer to this [link](https://www.syncfusion.com/maui-controls/maui-datagrid) to learn about the essential features of Syncfusion .NET MAUI DataGrid (SfDataGrid). + +##### Conclusion + +I hope you enjoyed learning about how to fetch a excel file with file picker and import data into .NET MAUI DataGrid (SfDataGrid) Pdf Exporting. + +You can refer to our [.NET MAUI DataGrid’s feature tour](https://www.syncfusion.com/maui-controls/maui-datagrid) page to learn about its other groundbreaking feature representations. You can also explore our [.NET MAUI DataGrid Documentation](https://help.syncfusion.com/maui/datagrid/getting-started) to understand how to present and manipulate data. +For current customers, you can check out our .NET MAUI components on the [License and Downloads](https://www.syncfusion.com/sales/teamlicense) page. If you are new to Syncfusion, you can try our 30-day [free trial](https://www.syncfusion.com/downloads/maui) to explore our .NET MAUI DataGrid and other .NET MAUI components. + +If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our [support forums](https://www.syncfusion.com/forums), [Direct-Trac](https://support.syncfusion.com/create) or [feedback portal](https://www.syncfusion.com/feedback/maui?control=sfdatagrid), or the feedback portal. We are always happy to assist you! \ No newline at end of file diff --git a/SfDataGridSample/App.xaml b/SfDataGridSample/App.xaml new file mode 100644 index 0000000..17ccdfd --- /dev/null +++ b/SfDataGridSample/App.xaml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/SfDataGridSample/App.xaml.cs b/SfDataGridSample/App.xaml.cs new file mode 100644 index 0000000..70f8033 --- /dev/null +++ b/SfDataGridSample/App.xaml.cs @@ -0,0 +1,12 @@ +namespace SfDataGridSample +{ + public partial class App : Application + { + public App() + { + InitializeComponent(); + + MainPage = new AppShell(); + } + } +} diff --git a/SfDataGridSample/AppShell.xaml b/SfDataGridSample/AppShell.xaml new file mode 100644 index 0000000..36f37ae --- /dev/null +++ b/SfDataGridSample/AppShell.xaml @@ -0,0 +1,15 @@ + + + + + + diff --git a/SfDataGridSample/AppShell.xaml.cs b/SfDataGridSample/AppShell.xaml.cs new file mode 100644 index 0000000..f5ff6e6 --- /dev/null +++ b/SfDataGridSample/AppShell.xaml.cs @@ -0,0 +1,10 @@ +namespace SfDataGridSample +{ + public partial class AppShell : Shell + { + public AppShell() + { + InitializeComponent(); + } + } +} diff --git a/SfDataGridSample/Helper/SaveService.cs b/SfDataGridSample/Helper/SaveService.cs new file mode 100644 index 0000000..ea5c6b6 --- /dev/null +++ b/SfDataGridSample/Helper/SaveService.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SfDataGridSample +{ + public partial class SaveService + { + //Method to save document as a file and view the saved document. + public partial void SaveAndView(string filename, string contentType, MemoryStream stream); + } +} diff --git a/SfDataGridSample/MainPage.xaml b/SfDataGridSample/MainPage.xaml new file mode 100644 index 0000000..9646a4b --- /dev/null +++ b/SfDataGridSample/MainPage.xaml @@ -0,0 +1,43 @@ + + + + + + + + + + +