Я использую apache-poi для изменения ячейки Excel (с помощью setCellValue) и получения значения cellM14, значение которого зависит от измененной ячейки.
Когда я вручную открываю Excel, ячейка M14 обновляется правильно, но когда я пытаюсь распечатайте
System.out.println("Updated Value at M14: " + cellM14.getNumericCellValue());
печатается старое значение ячейкиM14. Я не могу использовать Formula Evaluator, так как существует ошибка с именованием, см.:
FormulaEvaluatorFormulaParseException Выражение точечного диапазона (полная строка или столбец) «C.aRG» должно содержать ровно 2 точки.
Может ли кто-нибудь помочь мне распечатать обновленную версию cellM14?
String filePath = "file";
try (FileInputStream fileInputStream = new FileInputStream(new File(filePath));
XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream)) {
Sheet sheet = workbook.getSheet("input");
workbook.setForceFormulaRecalculation(true);
// Check if Row 13 exists and print original value if the cell exists
Row row13 = sheet.getRow(13);
if (row13 != null) {
Cell cellM14 = row13.getCell(11);
if (cellM14 != null) {
System.out.println("Original Value at M14: " + cellM14.getNumericCellValue());
} else {
System.out.println("Cell M14 is null.");
}
} else {
System.out.println("Row 13 is null.");
}
// Change the value in cell H5 (row index 4, column index 7)
Row row4 = sheet.getRow(4);
if (row4 == null) {
row4 = sheet.createRow(4);
}
Cell sub = row4.getCell(7);
if (sub == null) {
sub = row4.createCell(7);
}
sub.setCellValue("nanoparticle");
// Save workbook
try (FileOutputStream fileOutputStream = new FileOutputStream(new File(filePath))) {
workbook.write(fileOutputStream);
}
} catch (Exception e) {
e.printStackTrace();
}
try (FileInputStream fileInputStream = new FileInputStream(new File(filePath));
XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream)) {
workbook.setForceFormulaRecalculation(true);
try (FileOutputStream fileOutputStream = new FileOutputStream(new File(filePath))) {
workbook.write(fileOutputStream);
}
Sheet sheet = workbook.getSheet("input");
// Check if Row 13 exists and print original value if the cell exists
Row row13 = sheet.getRow(13);
if (row13 != null) {
Cell cellM14 = row13.getCell(11);
if (cellM14 != null) {
System.out.println("Updated Value at M14: " + cellM14.getNumericCellValue());
} else {
System.out.println("Cell M14 is null.");
}
} else {
System.out.println("Row 13 is null.");
}
} catch (Exception e) {
e.printStackTrace();
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... -correctly
Ячейка Excel не обновлена правильно ⇐ Apache
1719384952
Anonymous
Я использую apache-poi для изменения ячейки Excel (с помощью setCellValue) и получения значения cellM14, значение которого зависит от измененной ячейки.
Когда я вручную открываю Excel, ячейка M14 обновляется правильно, но когда я пытаюсь распечатайте
System.out.println("Updated Value at M14: " + cellM14.getNumericCellValue());
печатается старое значение ячейкиM14. Я не могу использовать Formula Evaluator, так как существует ошибка с именованием, см.:
FormulaEvaluatorFormulaParseException Выражение точечного диапазона (полная строка или столбец) «C.aRG» должно содержать ровно 2 точки.
Может ли кто-нибудь помочь мне распечатать обновленную версию cellM14?
String filePath = "file";
try (FileInputStream fileInputStream = new FileInputStream(new File(filePath));
XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream)) {
Sheet sheet = workbook.getSheet("input");
workbook.setForceFormulaRecalculation(true);
// Check if Row 13 exists and print original value if the cell exists
Row row13 = sheet.getRow(13);
if (row13 != null) {
Cell cellM14 = row13.getCell(11);
if (cellM14 != null) {
System.out.println("Original Value at M14: " + cellM14.getNumericCellValue());
} else {
System.out.println("Cell M14 is null.");
}
} else {
System.out.println("Row 13 is null.");
}
// Change the value in cell H5 (row index 4, column index 7)
Row row4 = sheet.getRow(4);
if (row4 == null) {
row4 = sheet.createRow(4);
}
Cell sub = row4.getCell(7);
if (sub == null) {
sub = row4.createCell(7);
}
sub.setCellValue("nanoparticle");
// Save workbook
try (FileOutputStream fileOutputStream = new FileOutputStream(new File(filePath))) {
workbook.write(fileOutputStream);
}
} catch (Exception e) {
e.printStackTrace();
}
try (FileInputStream fileInputStream = new FileInputStream(new File(filePath));
XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream)) {
workbook.setForceFormulaRecalculation(true);
try (FileOutputStream fileOutputStream = new FileOutputStream(new File(filePath))) {
workbook.write(fileOutputStream);
}
Sheet sheet = workbook.getSheet("input");
// Check if Row 13 exists and print original value if the cell exists
Row row13 = sheet.getRow(13);
if (row13 != null) {
Cell cellM14 = row13.getCell(11);
if (cellM14 != null) {
System.out.println("Updated Value at M14: " + cellM14.getNumericCellValue());
} else {
System.out.println("Cell M14 is null.");
}
} else {
System.out.println("Row 13 is null.");
}
} catch (Exception e) {
e.printStackTrace();
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78670716/excel-cell-not-updated-correctly[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия