Issue 351 - truncate exports to Excel at 256 columns (limitation of Excel format)

git-svn-id: http://google-refine.googlecode.com/svn/trunk@2094 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Tom Morris 2011-06-07 23:55:00 +00:00
parent 6a14049652
commit 51c898d602

View File

@ -75,8 +75,12 @@ public class XlsExporter implements StreamExporter {
int cellCount = 0;
for (Column column : project.columnModel.columns) {
org.apache.poi.ss.usermodel.Cell c = r.createCell(cellCount++);
c.setCellValue(column.getName());
if (cellCount++ > 255) {
// TODO: Warn user about truncated data
} else {
org.apache.poi.ss.usermodel.Cell c = r.createCell(cellCount);
c.setCellValue(column.getName());
}
}
}
@ -101,43 +105,48 @@ public class XlsExporter implements StreamExporter {
// nothing to do
}
@Override
public boolean visit(Project project, int rowIndex, Row row) {
org.apache.poi.ss.usermodel.Row r = sheet.createRow(rowCount++);
int cellCount = 0;
for (Column column : project.columnModel.columns) {
org.apache.poi.ss.usermodel.Cell c = r.createCell(cellCount++);
int cellIndex = column.getCellIndex();
if (cellIndex < row.cells.size()) {
Cell cell = row.cells.get(cellIndex);
if (cell != null) {
if (cell.recon != null && cell.recon.match != null) {
c.setCellValue(cell.recon.match.name);
HSSFHyperlink hl = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
hl.setLabel(cell.recon.match.name);
hl.setAddress("http://www.freebase.com/view" + cell.recon.match.id);
c.setHyperlink(hl);
} else if (cell.value != null) {
Object v = cell.value;
if (v instanceof Number) {
c.setCellValue(((Number) v).doubleValue());
} else if (v instanceof Boolean) {
c.setCellValue(((Boolean) v).booleanValue());
} else if (v instanceof Date) {
c.setCellValue((Date) v);
} else if (v instanceof Calendar) {
c.setCellValue((Calendar) v);
} else if (v instanceof String) {
String s = (String) v;
if (s.length() > 32767) {
// The maximum length of cell contents (text) is 32,767 characters
s = s.substring(0, 32767);
if (cellCount++ > 255) {
// TODO: Warn user about truncated data
} else {
org.apache.poi.ss.usermodel.Cell c = r.createCell(cellCount);
int cellIndex = column.getCellIndex();
if (cellIndex < row.cells.size()) {
Cell cell = row.cells.get(cellIndex);
if (cell != null) {
if (cell.recon != null && cell.recon.match != null) {
c.setCellValue(cell.recon.match.name);
HSSFHyperlink hl = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
hl.setLabel(cell.recon.match.name);
hl.setAddress("http://www.freebase.com/view" + cell.recon.match.id);
c.setHyperlink(hl);
} else if (cell.value != null) {
Object v = cell.value;
if (v instanceof Number) {
c.setCellValue(((Number) v).doubleValue());
} else if (v instanceof Boolean) {
c.setCellValue(((Boolean) v).booleanValue());
} else if (v instanceof Date) {
c.setCellValue((Date) v);
} else if (v instanceof Calendar) {
c.setCellValue((Calendar) v);
} else if (v instanceof String) {
String s = (String) v;
if (s.length() > 32767) {
// The maximum length of cell contents (text) is 32,767 characters
s = s.substring(0, 32767);
}
c.setCellValue(s);
}
c.setCellValue(s);
}
}
}