Updated formula not saving when it contains an external reference

(Using Apose.Cells 8.3.2.1)

We have a large number of Excel 97-2003 spreadsheets with large numbers of named ranges in them. We need to upgrade them all to Excel 2010. Unfortunately a lot of the named ranges are of the form "ABC1234" which is now a valid cell reference in Excel 2010, so we're trying to rename all the named ranges and fix the relevant formulae with Aspose.Cells.

The problem we're having is that the formulae just aren't saving.

This is the test code that isn't working :

var workbooks = new List
{
new Workbook(@"C:\Temp\Book1.xls"),
new Workbook(@"C:\Temp\Book2.xls")
};

var regex = new Regex(@"!([A-Za-z0-9_]+)");

foreach (var workbook in workbooks)
{
// Named Ranges -> "FIX_" + name
foreach (var name in workbook.Worksheets.Names)
{
name.Text = "FIX_" + name.Text;
}

// Update Formula References to renamed Named Ranges
foreach (var worksheet in workbook.Worksheets)
{
foreach (Cell cell in worksheet.Cells)
{
if (!cell.IsFormula || cell.IsInTable || (cell.IsInArray && !cell.IsArrayHeader)) continue;
if (!regex.IsMatch(cell.Formula)) continue;
var newformula = regex.Replace(cell.Formula, "!FIX_$1");
cell.Formula = newformula;
}
}
}

foreach (var workbook in workbooks)
{
workbook.Save(workbook.FileName, SaveFormat.Excel97To2003);
}

"Book1.xls" and "Book2.xls" are new excel 97-2003 spreadsheets with only one cell in each. A1 in Book1.xls contains the value "1337" and the workbook has a single named range referencing A1 called "MyNamedRange". A1 in Book2.xls contains the formula "='C:\Temp\Book1.xls'!MyNamedRange".

When I run the above code, the named range in Book1 is updated, but the formula in Book2 remains unchanged, even though I know that the line "cell.Formula = newformula" has actually been run on that formula.

This works for all formulae containing named ranges within the workbook, but external references don't appear to save.

Hi Jo,

Thanks for your posting and using Aspose.Cells.

We were able to observe this issue after executing the following sample code with the latest version: Aspose.Cells
for .NET v8.3.2.3
. We found the formula is not updated when it contains external reference.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-43398 - Updated formula not saving when it contains an external reference

C#

string filePath = @“F:\Shak-Data-RW\Downloads\t\Book2.xls”;


Workbook workbook = new Workbook(filePath);


Worksheet worksheet = workbook.Worksheets[0];


Cell cell = worksheet.Cells[“A1”];


string form = cell.Formula;

form = form.Replace(“MYNAMEDRANGE”, “FIXMYNAMEDRANGE”);


cell.Formula = form;


workbook.Save(filePath + “.out.xls”);

Hi,

Thanks for your using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for .NET v8.3.2.4 and let us know your feedback.

The issues you have found earlier (filed as CELLSNET-43398) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.