I'm using the following code to add a background image to Excel sheets using EPPlus.But the saved Excel does not have any background imgae.And on on opening the file with online excel it says that the workbook is damaged.
foreach (var file in Filelist)
{
// Load workbook
//var fileInfo = new FileInfo(@file);
FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
Bitmap bmp = new Bitmap("image.png");
//ExcelPackage pkg = new ExcelPackage(fs);
using (var package = new ExcelPackage(fs))
{
// Itterate through workbook sheets
foreach (var sheet in package.Workbook.Worksheets)
{
sheet.BackgroundImage.Image = bmp;
sheet.Protection.IsProtected = false;
}
package.SaveAs(new FileInfo(@"New.xlsx"));
}
fs.Close();
}