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

Encoding support #30

Closed
evserykh opened this issue Oct 6, 2017 · 6 comments
Closed

Encoding support #30

evserykh opened this issue Oct 6, 2017 · 6 comments

Comments

@evserykh
Copy link

evserykh commented Oct 6, 2017

@sbraconnier are you going to support your branch?
Do you know does OO/jodconverter support converting with setting output file's encoding?

@sbraconnier
Copy link
Member

sbraconnier commented Oct 6, 2017

@evserykh Sure I am. I'm about to release the next version of JODConverter. It should be out within a week.

Not sure I understand your question. But everything you can do using OO only (without JODConverter) is doable with JODConverter. We just have to figure out how to do it programmatically.

What are you tryinh to do exactly ? (what is you input and output format?).

@evserykh
Copy link
Author

evserykh commented Oct 6, 2017

Sounds great, it would be amazing 👍

Let me explain what I mean. For example I have a csv file in cp1251 encoding and I want to convert it to a xls file. Using OO I have to open the csv file and select file's encoding to have it properly showed. Do you know is it possible to set input file's encoding for converting requests to jodconverter?

@sbraconnier
Copy link
Member

OK got it.

First, take a look at this wiki page to understand what I'm about to explain.

The default filter options applied when a csv file is imported is 44,34,0, which means comma as field separator, " as text delimiter and system encoding as file encoding.

What you want, according to this table, is 44,34,34.

You can change these default options by forcing a custom format as source format:

Using the latest master:

File inputFile = new File("document.csv");
File outputFile = new File("document.xls");

DocumentFormat csv = DocumentFormat.copy(DefaultDocumentFormatRegistry.CSV);
csv.getLoadProperties().put("FilterOptions", "44,34,34");

JodConverter.convert(inputFile).as(csv).to(outputFile).execute();

Using the 4.0.0 version:

OfficeDocumentConverter converter = ...

File inputFile = new File("document.csv");
File outputFile = new File("document.xls");

final DocumentFormatRegistry registry = DefaultDocumentFormatRegistry.create();
DocumentFormat inputFormat = registry.getFormatByExtension("csv");
DocumentFormat outputFormat = registry.getFormatByExtension("xls");

inputFormat.getLoadProperties().put("FilterOptions", "44,34,34");
converter.convert(inputFile, outputFile, inputFormat, outputFormat);

Note that I didn't test this but it should work as expected...

@evserykh
Copy link
Author

evserykh commented Oct 7, 2017

@sbraconnier thanks a lot. I got what you meant, but I use jodconverter web app. I asked whether can I modify my requests to jodconverter web app to set input file's encoding.

@sbraconnier
Copy link
Member

Hmm...

Do you mean you use the jodconverter-sample-webapp sample ?

If yes, my answer remains the same. The sample webapp is... well, just a sample. It is not too hard to send request parameters through a web request. You could add a drop down list of available encoding and send the selected option to the server using a request parameter (see query string). Server side, you would retrieve the request parameter using ServletRequest#getParameter and then use the retrieved encoding as shown in my previous answer.

@evserykh
Copy link
Author

@sbraconnier I got it. Thanks a lot for help

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