Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fastExcel.Update() breaks when making changes to an existing sheet #69

Open
atomicHamsters opened this issue Aug 10, 2022 · 0 comments
Open

Comments

@atomicHamsters
Copy link

I have an existing excel file that I need to go through and change a cell value depending on the column values around it. Basically, I'm changing the cell values of 1 column. Everything works well until I get to update and then it throws a System.IO.IOException. However, if I call update before making changes, there is no error. I also tried using the original file as a template but it threw the same error. I included an abbreviated version of my code.

using FastExcel.FastExcel fastExcel = new FastExcel.FastExcel(new System.IO.FileInfo(excelPath));

var sheet = fastExcel.Read(1);
var rows = sheet.Rows.ToList();

for (int i = 1; i < rows.Count; i++)
{
      if(rows[i].GetCellByColumnName("H").Value == "Change me") {
         rows[i].GetCellByColumnName("G").Value = "Changed"
      } 
}

fastExcel.Update(sheet, 1); // errors here

Maybe I'm misunderstanding how the update works, but I'm hoping to get some clarity on this issue.
Full error message:
System.IO.IOException HResult=0x80131620 Message=Entries cannot be opened multiple times in Update mode. Source=System.IO.Compression StackTrace: at System.IO.Compression.ZipArchiveEntry.OpenInUpdateMode() at System.IO.Compression.ZipArchiveEntry.Open() at FastExcel.Worksheet.GetWorksheetPropertiesAndValidateNewName(FastExcel fastExcel, Nullable1 sheetNumber, String sheetName, String newSheetName) at FastExcel.Worksheet.GetWorksheetProperties(FastExcel fastExcel, Nullable1 sheetNumber, String sheetName) at FastExcel.Worksheet.Read(Nullable1 sheetNumber, String sheetName, Int32 existingHeadingRows) at FastExcel.FastExcel.Read(Nullable1 sheetNumber, String sheetName, Int32 existingHeadingRows) at FastExcel.FastExcel.Update(Worksheet data, Nullable`1 sheetNumber, String sheetName) at FastExcel.FastExcel.Update(Worksheet data, Int32 sheetNumber) at PopulateAllCells.Program.Main(String[] args) in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant