Inserting column and changing formula deletes other formulas

Hello!

I’ve noticed an issue with inserting columns and changing formulas that cause other cell’s formulas to be wiped. I will include steps to reproduce the bug and a workbook/code snippet for you to reproduce the issue as well.

  1. Given two cells with formulas, call one of the cells “badCell” and the other cell “victimCell”. They can both have different formulas that have nothing to do with eachother. Lets say our “badCell” is cell BD18, and the victimCell is cell AS17.
  2. Now insert a new column at column BD, which is column 55. Thus, our “badCell” has gone from column BD to column BE, and has now become BE18.
  3. If you now change the formula of the badCell at BE18, the victimCell’s formula gets deleted.

However, if after step 1 above, you change the badCell’s formula to anything (including its original formula), and you continue with the steps, you will see that the victimCell does not get its formula deleted.

Please find the code snippet and attached zipped workbook below to help you reproduce the issue. You can comment/uncomment the line “oldBadCell.Formula = “=+BD$316”;” to see the issue happen/not happen.

Also please replace the filePath with wherever you store the sample file.

Please let me know if you require any more information. Thank you for your assistance!

string filePath = "";

Workbook workbook = new Workbook(filePath);

int newlyInsertedColumnNumber = 55;

Worksheet modelWorksheet = workbook.Worksheets["Model"];

Cell victimCell = modelWorksheet.Cells["AS17"];
Cell oldBadCell = modelWorksheet.Cells["BD18"];

// If the line below (which sets the oldBadCell.Formula to itself) is commented out, the
// victimCell's formula will be wiped. If it isn't commented out, the victimCell's formlua won't be wiped.
// oldBadCell.Formula = "=+BD$316";
Console.WriteLine("Did not insert column yet. The victimCell's formula is "
    + victimCell.Formula.ToString()
    + Environment.NewLine);

modelWorksheet.Cells.InsertColumns(newlyInsertedColumnNumber, 1, true);

Console.WriteLine("Column Inserted" + Environment.NewLine);

// Because a new column was inserted at column 55 which is column "BD", that column has now been
// shifted one over, becoming column 56, or column BE.
Cell newBadCell1 = modelWorksheet.Cells["BE18"];
newBadCell1.Formula = "=+B12";
Console.WriteLine("BadCell's formula changed. Now the victimCell's formula is " + victimCell.Formula.ToString());

WMT US - new.zip (133.6 KB)

@jasonleecanalyst,
We have logged the issue as “CELLSNET-47734” in our database for investigations. Once we will have some news for you, we will update you in this topic.

@jasonleecanalyst,

Please try our latest version/fix: Aspose.Cells for .NET v20.11.5 (attached)

Your issue should be resolved.

Let us know your feedback.
Aspose.Cells20.11.5 For .Net2_AuthenticodeSigned.Zip (5.4 MB)
Aspose.Cells20.11.5 For .Net4.0.Zip (5.4 MB)

Hi @Amjad_Sahi,

I tried this just now with my script that I posted here, I was unable to open the workbook with it saying that the file was corrupt. When I switched back to Aspose.Cells 20.11.0, it no longer said that the workbook was corrupt. I am unable to verify the fix as of this moment. Please advise, thank you.

@jasonleecanalyst,
I have tried to reproduce this scenario by loading the sample Excel file “WMT US - new.xlsx” using the latest hot fix shared above but could not observe any issue. Could you please verify again if correct Excel file and hot fix is used for testing? If still issue is there, share a complete solution along with the hot fix and template Excel file for our reference. We will test the scenario here and share our feedback at the earliest.

I am still getting the same issue of Corrupted File. Please find my solution file attached here.FormulaWiped.zip (6.0 MB)

@jasonleecanalyst,
You have shared a project which is .NET Core based however the issue is logged for .NET framework and hot fix is also provided for .NET. Please provide details about your platform. Also share how you checked the .NET hot fix with a .NET Core based application and got the exception. We will analyze your feedback and assist you further accordingly.

Sorry for this mistake. I have tried it using a console app with .NET framework and have confirmed that it is now working.

@jasonleecanalyst,

Thanks for your feedback and good to know that your issue is sorted out by the new fix.

Hi @Amjad_Sahi

Is it possible to get this DLL built for .NET standard? Would like to run it through our entire test suite just to confirm the issue has been fixed there as well.

@jasonleecanalyst,
You may please give a try to the following version and share your feedback.
Aspose.Cells20.11.10 For .NetStandard20.Zip (5.4 MB)

The issues you have found earlier (filed as CELLSNET-47734) have been fixed in this update. This message was posted using Bugs notification tool by simon.zhao