Skip to content

Commit

Permalink
encoding option for xls exporters
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrenn committed Apr 6, 2024
1 parent 3eb9961 commit 63ec822
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Locale;

import org.phoenixctms.ctsms.fileprocessors.ProcessorJobOutput;
import org.phoenixctms.ctsms.util.CommonUtil;

import jxl.WorkbookSettings;

Expand Down Expand Up @@ -39,9 +40,13 @@ public int getSheetNum() {
return 0;
}

public WorkbookSettings getWorkbookSettings() {
public WorkbookSettings getWorkbookSettings(String encoding) {
WorkbookSettings workbookSettings = new WorkbookSettings();
workbookSettings.setLocale(Locale.getDefault());
if (!CommonUtil.isEmptyString(encoding)) {
jobOutput.println("using " + encoding + " encoding");
workbookSettings.setEncoding(encoding);
}
return workbookSettings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public abstract class XlsExporterBase {
protected void addEmailXlsAttachment(byte[] data) {
}

protected long printRows(XlsExporterContext context, RowWriter writer) throws Throwable {
protected long printRows(XlsExporterContext context, String encoding, RowWriter writer) throws Throwable {
ByteArrayOutputStream buffer = null;
try {
WritableWorkbook workbook;
WorkbookSettings workbookSettings = writer.getWorkbookSettings();
WorkbookSettings workbookSettings = writer.getWorkbookSettings(encoding);
if (!CommonUtil.isEmptyString(context.getFileName())) {
jobOutput.println("writing to file " + context.getFileName());
if (workbookSettings != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ public class XlsExporter extends XlsExporterBase {
public XlsExporter() {
}

public long exportEcrfs(String fileName, AuthenticationVO auth, Long trialId) throws Throwable {
public long exportEcrfs(String fileName, String encoding, AuthenticationVO auth, Long trialId) throws Throwable {
XlsExporterContext context = new XlsExporterContext(this, fileName);
setContext(ecrfRowWriter, context);
setContext(ecrfFieldRowWriter, context);
setContext(inputFieldRowWriter, context);
setContext(selectionSetValueRowWriter, context);
context.setEntityId(ecrfRowWriter, trialId);
context.setAuth(auth);
return printRows(context, ecrfRowWriter);
return printRows(context, encoding, ecrfRowWriter);
}

public long exportInputField(String fileName, AuthenticationVO auth, Long inputFieldId) throws Throwable {
public long exportInputField(String fileName, String encoding, AuthenticationVO auth, Long inputFieldId) throws Throwable {
XlsExporterContext context = new XlsExporterContext(this, fileName);
setContext(inputFieldRowWriter, context);
setContext(selectionSetValueRowWriter, context);
context.setEntityId(inputFieldRowWriter, inputFieldId);
context.setAuth(auth);
return printRows(context, inputFieldRowWriter);
return printRows(context, encoding, inputFieldRowWriter);
}

public EcrfFieldRowWriter getEcrfFieldRowWriter() {
Expand Down

0 comments on commit 63ec822

Please sign in to comment.