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

Decimal number, from comma to dot #371

Closed
kemuning opened this issue Feb 17, 2024 · 17 comments
Closed

Decimal number, from comma to dot #371

kemuning opened this issue Feb 17, 2024 · 17 comments
Assignees
Labels

Comments

@kemuning
Copy link

kemuning commented Feb 17, 2024

I have a .xlsx file with a number cell. With LO, the format in that cell is displayed with a comma ( decimal with comma - lang FR ), and when I exported as PDF, it is still displayed with a comma. But when I convert it with JOD, it is displayed with a dot ( decimal with dot - lang EN ). The conversion code I am using is just a common one :

public ByteArrayOutputStream doConvert(final DocumentFormat targetFormat, final InputStream inputFile) throws OfficeException {

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    final DocumentConverter converter;

    converter = LocalConverter
                    .builder()
                    .officeManager(officeManager)
                    .build();

    converter
        .convert(inputFile)
        .to(outputStream)
        .as(targetFormat)
        .execute();

    return outputStream;
}

Any idea about this decimal format issue ?

@kemuning kemuning changed the title Decimal number, from dot to comma Decimal number, from comma to dot Feb 18, 2024
@sbraconnier
Copy link
Member

sbraconnier commented Feb 19, 2024

You may take a look here, I think it would solve your problem.

@sbraconnier sbraconnier self-assigned this Feb 19, 2024
@kemuning
Copy link
Author

Thanks @sbraconnier for your reply. I am not sure if I understand the FilterOptions on that wiki page. Besides, the filter options are for CSV input file. There is also that Token 6 ... confusing.

@sbraconnier
Copy link
Member

sbraconnier commented Feb 19, 2024

Can you please attach a sample file (xlsx) here I could work with, with some cells you want to properly convert using comma instead of dots? I'll try to find the right options for you. It often takes some tries/errors before finding the right options/values we need.

@kemuning
Copy link
Author

kemuning commented Feb 20, 2024

Sure @sbraconnier

I attach 3 files, test.xlsx, test_JOD.pdf ( the PDF generated by JOD ), & test_LO.pdf ( exported via the LO ).

There are two cells in the sample file. The cell 'A1' is a decimal number in FR format, and the 'B1' in EN format.
test_LO.pdf
test_JOD.pdf
test.xlsx

As you can see, the test_LO.pdf has the same format as the sample file, but not the test_JOD.pdf

@sbraconnier
Copy link
Member

Hmmm. I just tested and on my end the output is the same as your test_LO.pdf. Obviously, there's something different with our setups. My OS language is EN (even if my primary language is FR). Maybe your's different?

I'll try to find how to control this...

@sbraconnier
Copy link
Member

sbraconnier commented Feb 22, 2024

Ah I just got it... The Cell A1 is not FR format, it is default format, which is FR in your case I suppose.

When I open the test.xlsx file on my end, both cell are using a dot because my default is EN.

Maybe you could take a look at this property.

Your have an example of its usage here

@kemuning
Copy link
Author

Thanks @sbraconnier.

My OS language is EN ( Windows 11 ). But under the 'Country & region' setting, it is in FR.

Anyway, I tried to implement the templateProfileDir, but something not right because I am calling LocalConverter and not LocalOfficeManager :

@Slf4j
@Service
public class JODService extends BaseService {

    private final OfficeManager officeManager;

    public JODService(OfficeManager officeManager) {
        this.officeManager = officeManager;
    }

    public ByteArrayOutputStream doConvert(final DocumentFormat targetFormat, final InputStream inputFile) throws OfficeException {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        final DocumentConverter converter;
        converter = LocalConverter.builder()
                // .templateProfileDir("C:\\JodConverter\\LO\\templateProfile")
                .officeManager(officeManager)
		.build();

        log.info("==> JODConverter en action ...");
        converter
            .convert(inputFile)
            .to(outputStream)
            .as(targetFormat)
            .execute();

        return outputStream;
    }
}

What am I missing ?

@sbraconnier
Copy link
Member

This property is for when you create the office manager. Are you using the spring boot module?

@kemuning
Copy link
Author

Yes

@sbraconnier
Copy link
Member

Then try the template-profile-dir properties in your configuration file:

.properties

jodconverter.local.template-profile-dir=C:\JodConverter\LO\templateProfile

or:

.yml

jodconverter:
  locaL:
    template-profile-dir: 'C:\JodConverter\LO\templateProfile'

@kemuning
Copy link
Author

@sbraconnier I tried but I got this error :

Caused by: java.lang.IllegalStateException: templateProfileDir doesn't appear to contain a user profile: C:\Users\ba111\Temp\LO\templateProfile
        at org.jodconverter.local.office.LocalOfficeUtils.validateOfficeTemplateProfileDirectory(LocalOfficeUtils.java:391)
        at org.jodconverter.local.office.LocalOfficeManager$Builder.build(LocalOfficeManager.java:206)
        at org.jodconverter.boot.autoconfigure.JodConverterLocalAutoConfiguration.createOfficeManager(JodConverterLocalAutoConfiguration.java:103)
        at org.jodconverter.boot.autoconfigure.JodConverterLocalAutoConfiguration.localOfficeManager(JodConverterLocalAutoConfiguration.java:151)

So I need to have a user profile in that templateProfileDir, but what user profile ? I checked again the wiki about it, but still don't understand. The LO user profile is located under %APPDATA%\libreoffice\4\user ( Windows 11 ).

And on the Tools->Options, I have this screenshot :

image

I am confused ...

@kemuning
Copy link
Author

As per here, I did copied the whole C:\Users\ba111\AppData\Roaming\LibreOffice\4\user into my templateProfileDir , but the error remains.

@sbraconnier
Copy link
Member

Try to follow the steps explained here

I'm currently using this property a lot cuz LO won't even start as a service on my laptop if OpenGL is enabled to begin with.

You must copy your %APPDATA%\libreoffice\4\user (including the user directory) under the directory you will set as templateProfileDir

On my laptop, the property is set to C:/workarea/LO/config/templateProfileDir, and the content of this directory is:

templateProfileDir
------/user
------------/autocorr
------------/autotext
------------/etc...

So I only have a single user directory under the templateProfileDir directory. Not super intuitive but we must keep it that way for backward compatibility and because it's the hierarchy LO is expecting.

@sbraconnier
Copy link
Member

sbraconnier commented Feb 27, 2024

As per #41 (comment), I did copied the whole C:\Users\ba111\AppData\Roaming\LibreOffice\4\user into my templateProfileDir , but the error remains.

If you take a second look, it's C:\Users\ba111\AppData\Roaming\LibreOffice\4 you should have copied, not C:\Users\ba111\AppData\Roaming\LibreOffice\4\user

@kemuning
Copy link
Author

Yes, I found your answer here

The error is gone.

@kemuning
Copy link
Author

And the decimal format is also gone.
Thanks @sbraconnier

@sbraconnier
Copy link
Member

Very glad to hear that :)

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

No branches or pull requests

2 participants