I'm using the following code to extract data from sheets within a workbook using EPPlus. The code works fine, except when the workbook is open in Excel. The code returns no data when the Excel file is kept open by the user. How can I get over this issue?
var fileInfo = new FileInfo(@file);
using (var package = new ExcelPackage(fileInfo))
{
label_snum.Text = package.Workbook.Worksheets.Count.ToString();
// Itterate through workbook sheets
foreach (var sheet in package.Workbook.Worksheets)
{
label_csheet.Text = sheet.Name;
// Itterate through each column until final column
for (int i = 1; i <= sheet.Dimension.End.Column; i++)
{
for (int j = 1; j <= sheet.Dimension.End.Row; j++)
{
if (sheet.Cells[j, i].Text.Length != 0)
{
}
}
}
}