Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global float style is ignored #242

Open
andreas-mausch opened this issue Dec 30, 2022 · 3 comments
Open

Global float style is ignored #242

andreas-mausch opened this issue Dec 30, 2022 · 3 comments

Comments

@andreas-mausch
Copy link

andreas-mausch commented Dec 30, 2022

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

// this.setImplicitDataStyle(this.dataStyles.getFloatDataStyle());

and this
7e84c8b

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
Copy link
Owner

jferard commented Dec 31, 2022

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

@jferard
Copy link
Owner

jferard commented Jan 14, 2023

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

jferard added a commit that referenced this issue Jan 15, 2023
@jferard
Copy link
Owner

jferard commented Jan 15, 2023

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:

  • FloatDataStyle implcit data style is null by default, thus no implicit data style is present for floats (in line with Default-_-float-data #217)
  • If you set the implicit data styles (OdsFactoryBuilder.dataStyles(...)), the FloatDataStyle implicit data style may or may not be null.
    • If it is null, then no implicit data style is present for floats.
    • If it is not, as in your example, then the implicit data style will be set (it was wrongly ignored).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants