You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2013/11/23 00:30:10 UTC
[Bug 55814] New: Comments are not cloned properly by
XSSFWorkbook.cloneSheet(...)
https://issues.apache.org/bugzilla/show_bug.cgi?id=55814
Bug ID: 55814
Summary: Comments are not cloned properly by
XSSFWorkbook.cloneSheet(...)
Product: POI
Version: 3.10-dev
Hardware: All
OS: All
Status: NEW
Severity: minor
Priority: P2
Component: XSSF
Assignee: dev@poi.apache.org
Reporter: corey@teffetalor.com
Created attachment 31068
--> https://issues.apache.org/bugzilla/attachment.cgi?id=31068&action=edit
Example XLSX, Java, and Outputs
When cloning an XSSFWorksheet with the cloneSheet method, the cloned sheet does
not display the comments associated with the original sheet:
This appears to be due to <legacyDrawing r:id="..."/> not appearing in the
<worksheet /> element.
XSSFWorksheet.getCTWorksheet().setLegacyDrawing(old
XSSFWorksheet.getCTWorksheet().getLegacyDrawing());
Appears to work around or resolve the issue with comments not appearing.
I suspect there is a further problem where after cloneSheet(...) is called any
modification of comments for both sheets will become linked. The relationships
from the sheet XML point toward the same comment XML document, instead of a
cloned copy of that document.
Example Code (Included in Zip)
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class POICloneComments {
public static void main(String[] args) {
try {
XSSFWorkbook wb = new XSSFWorkbook(new
FileInputStream("comment.xlsx"));
int oldsheetIndex = wb.getSheetIndex("example");
XSSFSheet oldsheet = wb.getSheetAt(oldsheetIndex);
XSSFSheet newsheet = wb.cloneSheet(oldsheetIndex);
wb.removeSheetAt(oldsheetIndex);
wb.write(new FileOutputStream("outnocomment.xlsx"));
wb = new XSSFWorkbook(new FileInputStream("comment.xlsx"));
oldsheetIndex = wb.getSheetIndex("example");
oldsheet = wb.getSheetAt(oldsheetIndex);
newsheet = wb.cloneSheet(oldsheetIndex);
wb.removeSheetAt(oldsheetIndex);
// This fixes the comment going missing
newsheet.getCTWorksheet().setLegacyDrawing(oldsheet.getCTWorksheet().getLegacyDrawing());
wb.write(new FileOutputStream("outhascomment.xlsx"));
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
}
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org