Issue 313 - fix cell format so dates export as dates rather than numbers.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@2334 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Tom Morris 2011-10-14 20:23:59 +00:00
parent 2d5125af1e
commit 5d6ab76b7c

View File

@ -1,6 +1,6 @@
/* /*
Copyright 2010, Google Inc. Copyright 2010,2011 Google Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@ -43,6 +43,7 @@ import java.util.Properties;
import org.apache.poi.hssf.usermodel.HSSFHyperlink; import org.apache.poi.hssf.usermodel.HSSFHyperlink;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
@ -74,11 +75,16 @@ public class XlsExporter implements StreamExporter {
TabularSerializer serializer = new TabularSerializer() { TabularSerializer serializer = new TabularSerializer() {
Sheet s; Sheet s;
int rowCount = 0; int rowCount = 0;
CellStyle dateStyle;
@Override @Override
public void startFile(JSONObject options) { public void startFile(JSONObject options) {
s = wb.createSheet(); s = wb.createSheet();
wb.setSheetName(0, ProjectManager.singleton.getProjectMetadata(project.id).getName()); wb.setSheetName(0, ProjectManager.singleton.getProjectMetadata(project.id).getName());
dateStyle = wb.createCellStyle();
dateStyle.setDataFormat(
wb.getCreationHelper().createDataFormat().getFormat("YYYY-MM-DD")); // TODO what format here?
} }
@Override @Override
@ -104,8 +110,10 @@ public class XlsExporter implements StreamExporter {
c.setCellValue(((Boolean) v).booleanValue()); c.setCellValue(((Boolean) v).booleanValue());
} else if (v instanceof Date) { } else if (v instanceof Date) {
c.setCellValue((Date) v); c.setCellValue((Date) v);
c.setCellStyle(dateStyle);
} else if (v instanceof Calendar) { } else if (v instanceof Calendar) {
c.setCellValue((Calendar) v); c.setCellValue((Calendar) v);
c.setCellStyle(dateStyle);
} else { } else {
String s = cellData.text; String s = cellData.text;
if (s.length() > 32767) { if (s.length() > 32767) {