Andrzej Sołtysik
Andrzej Sołtysik

Reputation: 320

Set workbook's date system to 1904 with Apache POI

Using Apache POI, I need to have negative durations in Excel in some of my cells, like this -03:35:13. Also the underlying value needs to be an actual negative numeric, not a text, because people using this workbook will do calculations on it.

Using [HH]:MM:SS as format actually works in Libreoffice Calc, no matter the date system configured there. However, the only thing that seems to be working for Excel is manually, through Excel UI, setting workbook's date system to 1904. However, after looking through javadocs I can't find any method to do that in code.

Upvotes: 0

Views: 280

Answers (1)

Andrzej Sołtysik
Andrzej Sołtysik

Reputation: 320

I found the solution. If you have an XSSFWorkbook, you can access the underlying XML properties, like this:

var workbook = new SXSSFWorkbook();
workbook.getXSSFWorkbook().getCTWorkbook().getWorkbookPr().setDate1904(true);

Upvotes: 1

Related Questions