aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/reports/ReportUtils.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-03-16 19:01:05 +1300
committerGitHub <noreply@github.com>2017-03-16 19:01:05 +1300
commit308d00b7f72b7455c58a98013fff06e227360097 (patch)
tree55367dae3f7e85c65432dfbf91adc4496df16254 /src/org/traccar/reports/ReportUtils.java
parent2f782faaf27ffdae3753e06a6386c1cd49b2ed16 (diff)
parentf7a668371769a7b4c176e57626f23314e3838e1c (diff)
downloadtrackermap-server-308d00b7f72b7455c58a98013fff06e227360097.tar.gz
trackermap-server-308d00b7f72b7455c58a98013fff06e227360097.tar.bz2
trackermap-server-308d00b7f72b7455c58a98013fff06e227360097.zip
Merge pull request #3011 from Abyss777/reports_timezone
Use timezone from preferences for excel reports
Diffstat (limited to 'src/org/traccar/reports/ReportUtils.java')
-rw-r--r--src/org/traccar/reports/ReportUtils.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java
index ed97c6857..e2a743b2f 100644
--- a/src/org/traccar/reports/ReportUtils.java
+++ b/src/org/traccar/reports/ReportUtils.java
@@ -16,14 +16,27 @@
*/
package org.traccar.reports;
+import org.apache.velocity.tools.generic.DateTool;
+import org.jxls.area.Area;
+import org.jxls.builder.xls.XlsCommentAreaBuilder;
+import org.jxls.common.CellRef;
+import org.jxls.formula.StandardFormulaProcessor;
+import org.jxls.transform.Transformer;
+import org.jxls.transform.poi.PoiTransformer;
+import org.jxls.util.TransformerFactory;
import org.traccar.Context;
import org.traccar.helper.Log;
import org.traccar.model.Position;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
import java.util.TimeZone;
public final class ReportUtils {
@@ -96,4 +109,29 @@ public final class ReportUtils {
return "-";
}
+ public static org.jxls.common.Context initializeContext(long userId) {
+ org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext();
+ jxlsContext.putVar("distanceUnit", getDistanceUnit(userId));
+ jxlsContext.putVar("speedUnit", getSpeedUnit(userId));
+ jxlsContext.putVar("webUrl", Context.getVelocityEngine().getProperty("web.url"));
+ jxlsContext.putVar("dateTool", new DateTool());
+ jxlsContext.putVar("timezone", getTimezone(userId));
+ jxlsContext.putVar("locale", Locale.getDefault());
+ jxlsContext.putVar("bracketsRegex", "[\\{\\}\"]");
+ return jxlsContext;
+ }
+
+ public static void processTemplateWithSheets(InputStream templateStream, OutputStream targetStream,
+ org.jxls.common.Context jxlsContext) throws IOException {
+ Transformer transformer = TransformerFactory.createTransformer(templateStream, targetStream);
+ List<Area> xlsAreas = new XlsCommentAreaBuilder(transformer).build();
+ for (Area xlsArea : xlsAreas) {
+ xlsArea.applyAt(new CellRef(xlsArea.getStartCellRef().getCellName()), jxlsContext);
+ xlsArea.setFormulaProcessor(new StandardFormulaProcessor());
+ xlsArea.processFormulas();
+ }
+ transformer.deleteSheet(xlsAreas.get(0).getStartCellRef().getSheetName());
+ transformer.write();
+ }
+
}