For a developer, who is trying to update TSV files in any Java application. Aspose.Total for Java API can help to automate the updating process. It’s a full package of various Java APIs dealing multiple formats including Microsoft Excel documents. Aspose.Cells for Java API that is part of Aspose.Total for Java package makes this modifying process easy. Process of updating the TSV document is simple by firstly accessing the sheet and then update cell value in excel using java.
How to Update TSV File in Java
- Create new Workbook class object having the source TSV file as parameter
- Access of relevant Worksheet and relevant cell using getWorksheets().get(index).getCells().get(column) method
- Insert new data in the accessed cell using getCells().get(indexValue).setValue(data) method
- Save the file as .tsv file using save() method by passing the file with path as the parameter
Modification Requirements
- For TSV modification, Microsoft Windows or a compatible OS with Java Runtime Environment for JSP/JSF Application and Desktop Applications.
- J2SE 6.0 (1.6), J2SE 7.0 (1.7), or above.
- Get latest API version directly from Downloads
Code - Update TSV File in Java
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"); |