From 51c898d6026a129f756aa5ab00dcf78f35c1959d Mon Sep 17 00:00:00 2001 From: Tom Morris Date: Tue, 7 Jun 2011 23:55:00 +0000 Subject: [PATCH] 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 --- .../google/refine/exporters/XlsExporter.java | 75 +++++++++++-------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/main/src/com/google/refine/exporters/XlsExporter.java b/main/src/com/google/refine/exporters/XlsExporter.java index 181c20d5f..cafe14095 100644 --- a/main/src/com/google/refine/exporters/XlsExporter.java +++ b/main/src/com/google/refine/exporters/XlsExporter.java @@ -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); } } }