Asked to Save when Opening an Edited Document

Hi,


I’ve been using Aspose to edit some Excel spreedsheets, but users are reporting a peculiar issue that I can’t seem to get to the bottom of. Once the file has been edited by the program, a user opens the file up and then, without making any changes at all, closes it, rather than simply closing, the save changes dialog box pops up asking the user if they want to discard their changes.

If they do the same before the file has been processed by Aspose, this doesn’t happen. It’s not a major issue, but it is causing some annoyance/confusion with users. I have put together some test code and attached a sample file that replicates the issue.

class Program
{
static void Main(string[] args)
{

if (File.Exists(@“C:\temp\promptTest1.xlsx”))
File.Delete(@“C:\temp\promptTest1.xlsx”);

var lic = new License();
lic.SetLicense(“Aspose.Total.lic”);

var template = @“C:\sandbox\ExcelSavePrompt\ExcelSavePrompt\App_Data\Test1.xlsx”;

Workbook wb = new Workbook(template);

foreach (Worksheet sh in wb.Worksheets)
{
if (sh.Name.Equals(“Aspose Test”, StringComparison.InvariantCultureIgnoreCase))
wb.Worksheets.RemoveAt(“Aspose Test”);

var textboxes = sh.TextBoxes;
for (var index = 0; index < sh.TextBoxes.Count; index++)
{
if (textboxes[index].Name.Contains(“Aspose_Test_Banner”))
{
textboxes.RemoveAt(index);
index–;
}
}
}

Worksheet classifiedSheet = wb.Worksheets[wb.Worksheets.Add()];
classifiedSheet.Name = “Aspose Test”;

Worksheet sheet = wb.Worksheets[“Aspose Test”];

int textboxIndex = sheet.TextBoxes.Add(0, 0, 20, 1000);
TextBox banner = sheet.TextBoxes[textboxIndex];
banner.Text = “TEST BANNER”;
banner.Name = “Aspose_Test_Banner” + Guid.NewGuid().ToString();
banner.Placement = PlacementType.FreeFloating;
banner.Font.Color = Color.White;
banner.Font.Size = 10;
banner.TextHorizontalAlignment = TextAlignmentType.Center;
banner.TextVerticalAlignment = TextAlignmentType.Center;
MsoFillFormat fillFormat = banner.FillFormat;
fillFormat.ForeColor = Color.Red;
MsoLineFormat lineFormat = banner.LineFormat;
lineFormat.Style = MsoLineStyle.Single;
lineFormat.Weight = 0;
banner.ZOrderPosition = 1;

wb.Save(@“C:\temp\Output.xlsx”);
}
}

If someone could shed some light on what’s happening it would be much appreciated!

Many thanks!

Hi,

Thanks for your posting and using Aspose.Cells.

Actually, this issue occurs because some formulas which are inside the Excel file are calculated by Microsoft Excel automatically and their values change which modifies the Excel file and then when the file is closed, Microsoft Excel prompts the user to save the changes.

Please check the source.xlsx file for your reference. It has two formulas, Sum and Rand, when you open it and close it, you will see Microsoft Excel asks you to save the changes. If you remove the Rand formula, then save it and then open it again, Microsoft Excel will not prompt you to save the changes.

Fantastic, thanks for that, was quite a simple resolution then. I will go back to our users and provide them with this update, hopefully it should suffice.


Thanks again!

Hi,

Thanks for your posting and using Aspose.Cells.

It is good to know that you now know the root cause of this issue. Let us know if you encounter any other issue, we will be glad to look into it and help you further.