mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merge 3.2 to HEAD
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@16988 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -33,11 +33,11 @@ import org.alfresco.service.cmr.repository.ContentWriter;
|
|||||||
import org.alfresco.service.cmr.repository.TransformationOptions;
|
import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.poi.hssf.record.RecordFormatException;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
|
import org.apache.poi.util.RecordFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes use of the {@link http://jakarta.apache.org/poi/ POI} library to
|
* Makes use of the {@link http://jakarta.apache.org/poi/ POI} library to
|
||||||
@@ -152,24 +152,25 @@ public class PoiHssfContentTransformer extends AbstractContentTransformer2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private void writeRow(OutputStream os, HSSFRow row, String encoding) throws Exception
|
private void writeRow(OutputStream os, HSSFRow row, String encoding) throws Exception
|
||||||
{
|
{
|
||||||
short firstCellNum = row.getFirstCellNum();
|
short firstCellNum = row.getFirstCellNum();
|
||||||
short lastCellNum = row.getLastCellNum();
|
short lastCellNum = row.getLastCellNum();
|
||||||
// pad out to first cell
|
// pad out to first cell
|
||||||
for (short i = 0; i < firstCellNum; i++)
|
for (int i = 0; i < firstCellNum; i++)
|
||||||
{
|
{
|
||||||
PoiHssfContentTransformer.writeString(os, encoding, ",", false); // CSV up to first cell
|
PoiHssfContentTransformer.writeString(os, encoding, ",", false); // CSV up to first cell
|
||||||
}
|
}
|
||||||
// write each cell
|
// write each cell
|
||||||
for (short i = 0; i <= lastCellNum; i++)
|
for (int i = 0; i <= lastCellNum; i++)
|
||||||
{
|
{
|
||||||
HSSFCell cell = row.getCell(i);
|
HSSFCell cell = row.getCell(i);
|
||||||
if (cell != null)
|
if (cell != null)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder(10);
|
int cellType = cell.getCellType();
|
||||||
switch (cell.getCellType())
|
|
||||||
|
StringBuilder sb = new StringBuilder(10);
|
||||||
|
switch (cellType)
|
||||||
{
|
{
|
||||||
case HSSFCell.CELL_TYPE_BLANK:
|
case HSSFCell.CELL_TYPE_BLANK:
|
||||||
// ignore
|
// ignore
|
||||||
@@ -180,25 +181,35 @@ public class PoiHssfContentTransformer extends AbstractContentTransformer2
|
|||||||
case HSSFCell.CELL_TYPE_ERROR:
|
case HSSFCell.CELL_TYPE_ERROR:
|
||||||
sb.append("ERROR");
|
sb.append("ERROR");
|
||||||
break;
|
break;
|
||||||
case HSSFCell.CELL_TYPE_FORMULA:
|
|
||||||
double dataNumber = cell.getNumericCellValue();
|
|
||||||
if (Double.isNaN(dataNumber))
|
|
||||||
{
|
|
||||||
// treat it as a string
|
|
||||||
sb.append(cell.getStringCellValue());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// treat it as a number
|
|
||||||
sb.append(dataNumber);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case HSSFCell.CELL_TYPE_NUMERIC:
|
case HSSFCell.CELL_TYPE_NUMERIC:
|
||||||
sb.append(cell.getNumericCellValue());
|
sb.append(cell.getNumericCellValue());
|
||||||
break;
|
break;
|
||||||
case HSSFCell.CELL_TYPE_STRING:
|
case HSSFCell.CELL_TYPE_STRING:
|
||||||
sb.append(cell.getStringCellValue());
|
sb.append(cell.getStringCellValue());
|
||||||
break;
|
break;
|
||||||
|
case HSSFCell.CELL_TYPE_FORMULA:
|
||||||
|
final int formulaResultType = cell.getCachedFormulaResultType();
|
||||||
|
if (HSSFCell.CELL_TYPE_NUMERIC == formulaResultType)
|
||||||
|
{
|
||||||
|
sb.append(cell.getNumericCellValue());
|
||||||
|
}
|
||||||
|
else if (HSSFCell.CELL_TYPE_STRING == formulaResultType)
|
||||||
|
{
|
||||||
|
sb.append(cell.getStringCellValue());
|
||||||
|
}
|
||||||
|
else if (HSSFCell.CELL_TYPE_BOOLEAN == formulaResultType)
|
||||||
|
{
|
||||||
|
sb.append(cell.getBooleanCellValue());
|
||||||
|
}
|
||||||
|
else if (HSSFCell.CELL_TYPE_ERROR == formulaResultType)
|
||||||
|
{
|
||||||
|
sb.append(cell.getErrorCellValue());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new RuntimeException("Unknown formula result type: " + formulaResultType);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unknown HSSF cell type: " + cell);
|
throw new RuntimeException("Unknown HSSF cell type: " + cell);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user