Skip to content
Snippets Groups Projects
Commit f264e2b7 authored by Stéphane  DALLONGEVILLE's avatar Stéphane DALLONGEVILLE
Browse files

Fixed bugs on workbook merging operation

parent e3186ee6
No related branches found
No related tags found
No related merge requests found
......@@ -138,9 +138,7 @@ public class WorkbookToFile extends Plugin implements IOBlock
{
try
{
Workbook wb = FileToWorkbook.readWorkbook(file);
mergeWorkbooks(workbook, wb, mergePolicy);
workbook = wb;
mergeWorkbooks(FileToWorkbook.readWorkbook(file), workbook, mergePolicy);
}
catch (IllegalArgumentException e)
{
......@@ -229,9 +227,7 @@ public class WorkbookToFile extends Plugin implements IOBlock
if (file.exists() && mergePolicy != MergePolicy.Overwrite)
try
{
Workbook wb = FileToWorkbook.readWorkbook(file);
mergeWorkbooks(workbook, wb, mergePolicy);
workbook = wb;
mergeWorkbooks(FileToWorkbook.readWorkbook(file), workbook, mergePolicy);
}
catch (Exception e)
{
......@@ -389,7 +385,7 @@ public class WorkbookToFile extends Plugin implements IOBlock
if (!styles.containsKey(hashCode))
{
CellStyle targetStyle = target.createCellStyle();
targetStyle.cloneStyleFrom(sourceCell.getCellStyle());
Workbooks.copyStyle(sourceCell.getCellStyle(), targetStyle);
styles.put(hashCode, targetStyle);
}
targetCell.setCellStyle(styles.get(hashCode));
......
......@@ -10,6 +10,8 @@ import javax.swing.BoxLayout;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
......@@ -85,7 +87,7 @@ public class Workbooks extends PluginActionable implements PluginThreaded
}
/**
* @return A new empty workbook using the old compatibility format (XLS).
* @return A new empty workbook using the new XLSX format.
*/
public static Workbook createEmptyWorkbook()
{
......@@ -236,6 +238,54 @@ public class Workbooks extends PluginActionable implements PluginThreaded
}
}
/**
* Copies the {@link CellStyle} of <code>srcStyle</code> into <code>dstStyle</code>.
*
* @param srcStyle
* source style
* @param dstStyle
* destination style
*/
public static void copyStyle(CellStyle srcStyle, CellStyle dstStyle)
{
dstStyle.setAlignment(srcStyle.getAlignmentEnum());
dstStyle.setBorderBottom(srcStyle.getBorderBottomEnum());
dstStyle.setBorderLeft(srcStyle.getBorderLeftEnum());
dstStyle.setBorderRight(srcStyle.getBorderRightEnum());
dstStyle.setBorderTop(srcStyle.getBorderTopEnum());
dstStyle.setFillBackgroundColor(srcStyle.getFillBackgroundColor());
dstStyle.setFillForegroundColor(srcStyle.getFillForegroundColor());
dstStyle.setFillPattern(srcStyle.getFillPatternEnum());
// dstStyle.setDataFormat(this.transform(srcStyle.getDataFormat()));
// dstStyle.setFont(this.transform(srcStyle.getFont(this.workbookOld)));
dstStyle.setHidden(srcStyle.getHidden());
dstStyle.setIndention(srcStyle.getIndention());
dstStyle.setLocked(srcStyle.getLocked());
dstStyle.setVerticalAlignment(srcStyle.getVerticalAlignmentEnum());
dstStyle.setWrapText(srcStyle.getWrapText());
}
/**
* Copies the {@link Font} of <code>srcFont</code> into <code>dstFont</code>.
*
* @param srcFont
* source font
* @param dstFont
* destination font
*/
public static void copyFont(Font srcFont, Font dstFont)
{
dstFont.setBold(srcFont.getBold());
dstFont.setCharSet(srcFont.getCharSet());
dstFont.setColor(srcFont.getColor());
dstFont.setFontName(srcFont.getFontName());
dstFont.setFontHeight(srcFont.getFontHeight());
dstFont.setItalic(srcFont.getItalic());
dstFont.setStrikeout(srcFont.getStrikeout());
dstFont.setTypeOffset(srcFont.getTypeOffset());
dstFont.setUnderline(srcFont.getUnderline());
}
/**
* Checks whether the specified workbook contains a sheet with the specified name.<br>
* NB: If the provided sheet name contains invalid characters, they are automatically replaced
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment