Hi Team,
Hi,
Thanks for your posting and using Aspose.Cells.
No, your file is not deleted but it is overwritten. If you want that it is not overwritten then please change the name of your output file that should be different than your source excel file.
Suppose your source excel file is
F:\temp\abc.xlsx
then you can save it as
F:\temp\abc-output.xlsx
Now a new file abc-output.xlsx will be created and your existing abc.xlsx file will not be changed.
Hi Kapil,
Overwrite means it replaces an existing file, correct?
//Save in Excel2003 format
workbook.save(stream, SaveFormat.EXCEL_97_TO_2003);
Will this API write into same file or Overwrite that file?
Performance wise, is there any difference in these two flavor of save API’s?
Hi,
Thanks for your question and using Aspose.Cells.
Actually workbook object is created with your source excel file and after that it has nothing to do with your source excel file. Everything is done inside the workbook object and nothing happens with your source excel file with which your workbook object is constructed. It means everything is done inside the memory not hard drive.
So when you want to save your workbook object in disk, you provide it some name, if the name is same as your source excel file, then your existing source excel file is overwritten, means the existing source excel file is lost and the new excel file with the same name is generated.
Hi Shakeel,
Hi Kapil,
Thanks for your nice inquisitive questions and considering Aspose.Cells.
Actually, you do not get any performance improvement if you use the same file name on saving. Because Aspose.Cells will load all the data inside the memory and when you save it back with the same file name, then that file stream is first deleted and then overwritten. The file actually does not get deleted but the data inside it is deleted. This has nothing to do with Aspose.Cells. It is actually the behavior of Java and .NET file stream APIs. You can replicate it by first loading your file in file stream and then writing it again on the same file stream, then existing stream will be deleted and new stream will be written.
What I understand, you want to do it because of performance and memory optimization but this way you are not getting any performance improvement but also your main file is overwritten too. So I suggest you use different file name on re-saving.
Thanks Shakeel for reply, that clears my doubts.
Hi Kapil,
Thanks for your question and using Aspose.Cells.
You can find it through some Java APIs but for that you need to research on internet.
Here is the one such query on StackOverflow related to your question.
( How to check if a file is open by another process (Java/Linux)? - Stack Overflow )