It’s common for organization to update their data, stored in excel files such as students data, patients records and warehouse items list etc via company software. Aspose.Total for Java API provides the functionality of modifying the spreadsheets using their own software. Programmers can enhance the software with the modification capabilities by just writing few lines of API code. Aspose.Cells for Java API that is part of Aspose.Total for Java package makes this modification process easy. Below is the process of updating the Excel document.
Update Excel Documents using Java
Aspose.Cells for Java API provides Workbook class that handles the loading of Excel spreadsheets. Process is simple. Create the Workbook class object by providing the source file as parameter. Access the relevant Worksheet and relevant cell using getWorksheets().get(index).getCells().get(column) method. Use the getCells().get(indexValue).setValue(data) method to modify the content in the accessed cell and finally call the save() method to save the document.
Java Code - Update Excel Documents
Workbook wkb = new Workbook("sourceFile.xlsx"); | |
Cell cellWithData = wkb.getWorksheets().get(0).getCells().get("A1"); | |
cellWithData.setValue(100); | |
Cell cellWithFormula = wkb.getWorksheets().get(1).getCells().get("C1"); | |
cellWithFormula.setFormula("=Sum(A1,A20)"); | |
wkb.calculateFormula(); | |
Worksheet sheet = wkb.getWorksheets().get(2); | |
Cell cell = sheet.getCells().get("A1"); | |
cell.setValue("Hello World!"); | |
wkb.save("updated-excel-file.xlsx"); |