jferard / fastods

A very fast and lightweight (no dependency) library for creating ODS (Open Document Spreadsheet, mainly for Calc) files in Java. It's a Martin Schulz's SimpleODS fork
GNU General Public License v3.0
35 stars 6 forks source link

Global float style is ignored #242

Open andreas-mausch opened 1 year ago

andreas-mausch commented 1 year ago

Hi,

I tried to create a .ods file based on the example https://github.com/jferard/fastods/blob/master/fastods-examples/src/main/java/com/github/jferard/fastods/examples/D_SettingTheCellDataStyle.java

I modified it a bit, so I am not 100% sure if I made a mistake or if it's a bug.

However, I tried to use a global style for all floating numbers, but it is not applied. Note: If I set the floatStyle on the cell directly (last value, 1005.123), it works! The global date style works also.

Tested with com.github.jferard:fastods:0.8.1 and LibreOffice 7.4.3

Did I miss something, or is it a bug?

Edit: After looking at the source code I found this https://github.com/jferard/fastods/blob/4a3d5e1cde08a95612727a2677d15b0c547188b3/fastods/src/main/java/com/github/jferard/fastods/TableCellImpl.java#L308

and this https://github.com/jferard/fastods/commit/7e84c8bfb3e126f8c99e222f87aed241e278d065

and it seems to be related to #217 and is intended I guess? Is there a way to enable the implicit styling for floats?

grafik
val dsb = DataStylesBuilder.create(Locale.US)
dsb.floatStyleBuilder().minIntegerDigits(20).negativeValueRed().decimalPlaces(0).locale(Locale.US)
dsb.dateStyleBuilder().dateFormat(DateTimeStyleFormat(DateTimeStyleFormat.LONG_DAY, DateTimeStyleFormat.SLASH, DateTimeStyleFormat.LONG_MONTH, DateTimeStyleFormat.SLASH, DateTimeStyleFormat.LONG_YEAR))

val ds = dsb.build()

val odsFactory = OdsFactory.builder(Logger.getLogger("cells2"), Locale.US)
        .dataStyles(ds).build()

val writer = odsFactory.createWriter()
val document = writer.document()

val table = document.addTable("data styles")
val walker = table.getWalker()

walker.setFloatValue(123456.789)
val cal = GregorianCalendar(2018, 1, 1, 0, 0, 0)
walker.next()
walker.setDateValue(cal)
walker.next()
walker.setFloatValue(-123456.789)
walker.next()
walker.setFloatValue(301)
walker.next()
walker.setFloatValue(1005.123)
walker.setDataStyle(dsb.floatStyleBuilder().build())

val destFile = File("d_data_style2.ods")
writer.saveAs(destFile)
jferard commented 1 year ago

Hi. Thanks for reporting. I'll have a look... next year.

jferard commented 1 year ago

Note for myself : this one should display only the int part.

jferard commented 1 year ago

A bit late, but:

  1. It is indeed a bug;
  2. this commit should fix the issue.

Now, implicit data styles (for types) may be null: