EPPlus
EPPlus copied to clipboard
Xamarin forms UWP problem: excel cannot open the file because the file format or file extension is not valid.
I am testing the library and cant generate a valid output.
This library in version 7 works on UWP?
Tested: ExcelPackage.LicenseContext = LicenseContext.NonCommercial; using (var package = new ExcelPackage(rutaArchivo)) { var sheet = package.Workbook.Worksheets.Add("My Sheet"); sheet.Cells["A1"].Value = "Hello World!";
// Save to file
package.Save();
}
Opening the file i get this error: Excel cannot open the file because the file format or file extension is not valid. verify that the file has not been corrupted and that the file extension matches the format of the file.
What is the value of the variable rutaArchivo
?
What is the value of the variable
rutaArchivo
?
The file is created correctly, the path comes from a FileSavePicker: C:\Users\Pablo\Desktop\Export040320241343.xlsx
That shold be ok then. Does it work if you create a new file on UWP?
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
using (var package = new ExcelPackage())
{
var sheet = package.Workbook.Worksheets.Add("My Sheet");
sheet.Cells["A1"].Value = "Hello World!";
// Save to file
package.SaveAs(@"C:\Users\Pablo\Desktop\EPPlusTest.xlsx");
}
If you can upload the corrupted file here we can have a look at it.
That shold be ok then. Does it work if you create a new file on UWP?
ExcelPackage.LicenseContext = LicenseContext.NonCommercial; using (var package = new ExcelPackage()) { var sheet = package.Workbook.Worksheets.Add("My Sheet"); sheet.Cells["A1"].Value = "Hello World!"; // Save to file package.SaveAs(@"C:\Users\Pablo\Desktop\EPPlusTest.xlsx"); }
If you can upload the corrupted file here we can have a look at it.
It creates a new file ok always, but i cant open it.
That shold be ok then. Does it work if you create a new file on UWP?
ExcelPackage.LicenseContext = LicenseContext.NonCommercial; using (var package = new ExcelPackage()) { var sheet = package.Workbook.Worksheets.Add("My Sheet"); sheet.Cells["A1"].Value = "Hello World!"; // Save to file package.SaveAs(@"C:\Users\Pablo\Desktop\EPPlusTest.xlsx"); }
If you can upload the corrupted file here we can have a look at it.
I have to use the FileSavePicker to have permision to save the file, if i try the path directly i have an access denied exception.
The file you sent is an empty file (0 Kb), so nothing has been written to it.
I would suggest that you don't let EPPlus save the file directly via a file path, I assume that it has to be done via the UWP storage API:s somehow. You can get Excel-file as a byte-array by calling:
var bytes = package.GetAsByteArray();
instead of using package.Save()
or package.SaveAs(...)
.
The file you sent is an empty file (0 Kb), so nothing has been written to it.
I would suggest that you don't let EPPlus save the file directly via a file path, I assume that it has to be done via the UWP storage API:s somehow. You can get Excel-file as a byte-array by calling:
var bytes = package.GetAsByteArray();
instead of using
package.Save()
orpackage.SaveAs(...)
.
Thanks, i will try that
Closed due to inactivity