使用 POI 更新 .xlsx 文件中的现有单元格值后,如果 API 使用该文件,则该文件将给出 HTTP 403

After updating existing cell value in .xlsx file using POI, the file is giving HTTP 403 if used by an API

我有一个 excel 文件,其中包含许多列和一组数据行。 更改 asOf 字段的值后,因为我在正在使用 excel 文件的 API 中使用它,出现 403 Forbidden 错误。我检查了以下内容:

  1. 该字段已正确更新。 (我手动更新后检查了 excel 的格式和单元格样式。)
  2. 如果我手动更改单元格值,则 API 给出 200。

失败响应图像: 当 asOf 字段由 Java 代码

更新时

通过响应的图像:手动更新 asOf 字段时。

我正在更新的字段图像如下:

下面是我正在使用的 java 代码:

   public static void excelFileReadAndUpdate() throws IOException {
    XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream("./src/test/resources/testdata/HoldingDataWeekendDate.xlsx"));
    FileOutputStream fileOut = new FileOutputStream("./src/test/resources/testdata/HoldingDataWeekendDate.xlsx");
    XSSFSheet sheet1 = wb.getSheetAt(0);
    XSSFRow row = sheet1.getRow(1);
    XSSFCell cell = row.getCell(0);
    cell.setCellValue("2018-10-31");
    wb.write(fileOut);
    fileOut.close();
}

注意:我尝试了其他方法,例如使用工作簿并保留格式,但它不起作用。如果我在打开 excel 后手动更新该字段,那么它会起作用。

任何 suggestion/advice 都会有很大帮助。 提前致谢。

在搜索和应用许多方法后,最后,通过应用一些代码解决了这个问题,该代码给予 read/write 权限 folder/file in [=17] =].

 public static void excelFileReadAndUpdate() throws IOException {

   final File file = new File("location of your excel file directory");
   file.setReadable(true, false);
   file.setExecutable(true, false);
   file.setWritable(true, false);

XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream("./src/test/resources/testdata/HoldingDataWeekendDate.xlsx"));
FileOutputStream fileOut = new FileOutputStream("./src/test/resources/testdata/HoldingDataWeekendDate.xlsx");
XSSFSheet sheet1 = wb.getSheetAt(0);
XSSFRow row = sheet1.getRow(1);
XSSFCell cell = row.getCell(0);
cell.setCellValue("2018-10-31");
wb.write(fileOut);
fileOut.close();
}