Open xls file keeping already existing cell names in it

Hi… I’m trying to open a xls file to write some data in it with aspose, (I’m using it to do some automated offline smoke tests), but when I open the xls file, it loses all cell names.


Here is my code:
try {
// License…
new AsposeAPI(null);
Workbook workbook = new Workbook(new FileInputStream(new File(“d:\21_161_en_US.xls”)));
WorksheetCollection col = workbook.getWorksheets();

Iterator<?> it = col.iterator();
while(it.hasNext()){
Worksheet sheet = (Worksheet) it.next();
if(!sheet.isGridlinesVisible()){
System.out.println(sheet.getName());
sheet.getCells().get(“F2”).setValue(new Integer(10));
sheet.getCells().get(“F3”).setValue(new Integer(5));
sheet.getCells().get(“F5”).setValue(new Double(32.56));
sheet.getCells().get(“F6”).setValue(new Double(40.00));
} else {
}
}

FileOutputStream fos = new FileOutputStream(new File(“d:\figayra2.xls”));
workbook.getSettings().setRecommendReadOnly(false);
workbook.getSettings().setShowTabs(true);
workbook.save(fos, workbook.getSaveOptions());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}

Could you tell me how can I open a xls file, keeping all cell references it already has? I tried to just open it and save it right after that to check if it was related to the fact I’m writting in the sheet, but it also loses the cell names :(. Please… tell me this is possible! :smiley: Thanks in advance.

Hi,

Thanks for your posting and using Aspose.Cells.

As per your code, you are accessing the cells F2, F3, F5 and F6 by using their cell names and writing the double values. So in the output of the xls file, you will have some double values in these cells.

Are you getting something else? Please explain your issue more with the help of source file and screenshots. It will help us look into your issue more precisely.

Please see the following articles that explains how to access the cells and use them to insert data for your reference.


Hi Shakeel,

I’ll try to explain all the situation:
I have this spreadsheet generated by my system, and this spreadsheet is downloaded by a user and this user can fill data in it and them import it into my system. This spreadsheet generated by the system has some cells with names.

What I’m trying to do is simulate the user filling data into this spreadsheet, so i’m using aspose to open this spreadsheet downloaded from the system and I’m writing some data in cells F2, F3, F5 and F6. The problem is that when I open the spreadsheet using aspose, all the cell references in this same spreadsheet are lost. for example. If cell F2 has a name like biddervalue1, when I open it this way I’m doing in the code I posted above, the cell in coordinates F2, which had name biddervalue1, now is just F2 (and it happens with all named cells… so this spreadsheet won’t be valid in my system to be reimported, and lots of data cannot be calculated in it, since the named cells are lost.

So, the problem is how to open an xls file keeping named cells in it.

You can test it by creating a simple xls file in excel giving A1 a cell name, then save it. Use aspose to open this file and then just save it as another file. Open this file in excel and check cell A1. The name of the cell won’t be there anymore :’(

Hi,

Thanks for your posting and using Aspose.Cells.

We have tested your issue by assigning the cell name to cell A1, then opened and resaved the file using the following code and it worked fine. The name of the cell A1 is TestCell which is preserved in the output file. Please download and use the latest version: Aspose.Cells
for Java v7.7.0.2
and it should fix your issue.

We have attached the source and output xls files for your reference.

Java


String filePath = “F:\Shak-Data-RW\Downloads\source.xls”;


Workbook workbook = new Workbook(filePath);


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