BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
Hi David
Thank you for contacting Syncfusion support.
In Xamarin.Forms, workbook can be saved as stream using XlsIO. This stream can be saved as an Excel file by invoking Save method of ISave which is a user-defined interface. The following code example illustrates how to save an Excel file from a stream in Xamarin.Forms.
Code example:
ExcelEngine excelEngine = new ExcelEngine(); IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Excel2013; string resourcePath = "SampleBrowser.Samples.XlsIO.Template.Sample.xlsx"; Assembly assembly = typeof(App).GetTypeInfo().Assembly; Stream fileStream = assembly.GetManifestResourceStream(resourcePath);
//Opens the workbook. IWorkbook workbook = application.Workbooks.Open(fileStream); MemoryStream stream = new MemoryStream(); workbook.SaveAs(stream); workbook.Close(); excelEngine.Dispose();
//Save the stream into xlsx file Xamarin.Forms.DependencyService.Get<ISave>().Save("sample.xlsx","application/msexcel", stream);
public interface ISave { Task Save(string filename, string contentType, MemoryStream stream); }
class SaveAndroid: ISave { public async Task Save(string fileName, String contentType, MemoryStream stream) { string root = null; if (Android.OS.Environment.IsExternalStorageEmulated) { root = Android.OS.Environment.ExternalStorageDirectory.ToString(); } else root = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
Java.IO.File myDir = new Java.IO.File(root + "/Syncfusion"); myDir.Mkdir();
Java.IO.File file = new Java.IO.File(myDir, fileName);
if (file.Exists()) file.Delete();
try { FileOutputStream outs = new FileOutputStream(file); outs.Write(stream.ToArray());
outs.Flush(); outs.Close(); } catch (Exception e) {
} if (file.Exists()) { Android.Net.Uri path = Android.Net.Uri.FromFile(file); string extension = Android.Webkit.MimeTypeMap.GetFileExtensionFromUrl(Android.Net.Uri.FromFile(file).ToString()); string mimeType = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension); Intent intent = new Intent(Intent.ActionView); intent.SetDataAndType(path, mimeType); Forms.Context.StartActivity(Intent.CreateChooser(intent, "Choose App")); } } |
We will update this information in the documentation.
Regards,
Dilli babu.