我正在尝试使用Apache poi库在.xls文件中编辑。所有更新都在本地计算机上成功完成。但是,当应用程序的jar文件没有在安装它的计算机上保存excel文件时,我被卡住了。
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Generated data of Dvat ");
fileChooser.setTitle("Generate XLS File of " + "Dvat 31");
fileChooser.getExtensionFilters().addAll(
new ExtensionFilter("XLS Files", "*.xls"));
fileChooser.setInitialFileName(Common
.replaceWhiteSpaceAndSlash("Dvat31")
+ "_"
+ Common.replaceWhiteSpaceAndSlash(Common.comp.getName()+"_")
+this.fromdate+"_"+this.todate+ ".xls");
fileChooser.setInitialDirectory(new File(System
.getProperty("user.home") + "/Desktop"));
File selectedFileName = fileChooser.showSaveDialog(null);
if(selectedFileName!=null)
{
String fileName=absolutePath;
HSSFWorkbook wb = HSSFReadWrite.readFile(fileName);
FileOutputStream stream = new FileOutputStream(selectedFileName.getAbsolutePath());
// Updation On .xls Sheet.
row = sheet.getRow(34);
for(int i=1;i<=12;i++)
{
if(i==4)
{
cell=row.getCell(i);
cell.setCellValue(this.consignmentTotal);
}
}
// Closing workbook and outputstream.
wb.write(stream);
stream.close();
wb.close();