Bug 56017: Fix comment-ref when shiftig rows with comments, this probably does not fix the bug itself, though
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1563587 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c1a7ab3860
commit
cdb915a279
@ -42,16 +42,7 @@ import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
|
|||||||
import org.apache.poi.ss.SpreadsheetVersion;
|
import org.apache.poi.ss.SpreadsheetVersion;
|
||||||
import org.apache.poi.ss.formula.FormulaShifter;
|
import org.apache.poi.ss.formula.FormulaShifter;
|
||||||
import org.apache.poi.ss.formula.SheetNameFormatter;
|
import org.apache.poi.ss.formula.SheetNameFormatter;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.ss.usermodel.CellRange;
|
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
|
||||||
import org.apache.poi.ss.usermodel.DataValidation;
|
|
||||||
import org.apache.poi.ss.usermodel.DataValidationHelper;
|
|
||||||
import org.apache.poi.ss.usermodel.Footer;
|
|
||||||
import org.apache.poi.ss.usermodel.Header;
|
|
||||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||||
import org.apache.poi.ss.util.CellReference;
|
import org.apache.poi.ss.util.CellReference;
|
||||||
@ -67,48 +58,7 @@ import org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter;
|
|||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
import org.apache.xmlbeans.XmlOptions;
|
||||||
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAutoFilter;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBreak;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataValidation;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataValidations;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDrawing;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHyperlink;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTLegacyDrawing;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCell;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCells;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTOutlinePr;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageBreak;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetUpPr;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPane;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPrintOptions;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSelection;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetCalcPr;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetPr;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetView;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetViews;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTablePart;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableParts;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCalcMode;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellFormulaType;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPaneState;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnsignedShortHex;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorksheetDocument;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* High level representation of a SpreadsheetML worksheet.
|
* High level representation of a SpreadsheetML worksheet.
|
||||||
@ -2440,10 +2390,12 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
//TODO shift Note's anchor in the associated /xl/drawing/vmlDrawings#.vml
|
//TODO shift Note's anchor in the associated /xl/drawing/vmlDrawings#.vml
|
||||||
CTCommentList lst = sheetComments.getCTComments().getCommentList();
|
CTCommentList lst = sheetComments.getCTComments().getCommentList();
|
||||||
for (CTComment comment : lst.getCommentArray()) {
|
for (CTComment comment : lst.getCommentArray()) {
|
||||||
CellReference ref = new CellReference(comment.getRef());
|
String oldRef = comment.getRef();
|
||||||
|
CellReference ref = new CellReference(oldRef);
|
||||||
if(ref.getRow() == rownum){
|
if(ref.getRow() == rownum){
|
||||||
ref = new CellReference(rownum + n, ref.getCol());
|
ref = new CellReference(rownum + n, ref.getCol());
|
||||||
comment.setRef(ref.formatAsString());
|
comment.setRef(ref.formatAsString());
|
||||||
|
sheetComments.referenceUpdated(oldRef, comment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import org.apache.poi.ss.usermodel.BaseTestSheetShiftRows;
|
import org.apache.poi.ss.usermodel.BaseTestSheetShiftRows;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
|
import org.apache.poi.ss.usermodel.Comment;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
@ -141,4 +142,49 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
|
|||||||
verifyCellContent(readSheet, 7, "6.0");
|
verifyCellContent(readSheet, 7, "6.0");
|
||||||
verifyCellContent(readSheet, 8, "8.0");
|
verifyCellContent(readSheet, 8, "8.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug56017() throws IOException {
|
||||||
|
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56017.xlsx");
|
||||||
|
|
||||||
|
Sheet sheet = wb.getSheetAt(0);
|
||||||
|
|
||||||
|
Comment comment = sheet.getCellComment(0, 0);
|
||||||
|
assertNotNull(comment);
|
||||||
|
assertEquals("Amdocs", comment.getAuthor());
|
||||||
|
assertEquals("Amdocs:\ntest\n", comment.getString().getString());
|
||||||
|
|
||||||
|
sheet.shiftRows(0, 1, 1);
|
||||||
|
|
||||||
|
// comment in row 0 is gone
|
||||||
|
comment = sheet.getCellComment(0, 0);
|
||||||
|
assertNull(comment);
|
||||||
|
|
||||||
|
// comment is now in row 1
|
||||||
|
comment = sheet.getCellComment(1, 0);
|
||||||
|
assertNotNull(comment);
|
||||||
|
assertEquals("Amdocs", comment.getAuthor());
|
||||||
|
assertEquals("Amdocs:\ntest\n", comment.getString().getString());
|
||||||
|
|
||||||
|
// FileOutputStream outputStream = new FileOutputStream("/tmp/56017.xlsx");
|
||||||
|
// try {
|
||||||
|
// wb.write(outputStream);
|
||||||
|
// } finally {
|
||||||
|
// outputStream.close();
|
||||||
|
// }
|
||||||
|
|
||||||
|
Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||||
|
assertNotNull(wbBack);
|
||||||
|
|
||||||
|
Sheet sheetBack = wbBack.getSheetAt(0);
|
||||||
|
|
||||||
|
// comment in row 0 is gone
|
||||||
|
comment = sheetBack.getCellComment(0, 0);
|
||||||
|
assertNull(comment);
|
||||||
|
|
||||||
|
// comment is now in row 1
|
||||||
|
comment = sheetBack.getCellComment(1, 0);
|
||||||
|
assertNotNull(comment);
|
||||||
|
assertEquals("Amdocs", comment.getAuthor());
|
||||||
|
assertEquals("Amdocs:\ntest\n", comment.getString().getString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user