@@ -30,68 +30,70 @@ public static boolean hasContent(XSSFCell cell) {
3030
3131 @ SuppressWarnings ("rawtypes" )
3232 public static void processDiffForColumn (XSSFCell cell1 , boolean commentFlag , String note , StringBuilder sb ) throws Exception {
33-
33+
3434 Sheet sheet = cell1 .getSheet ();
35-
35+
3636 sb .append (String .format ("Diff at cell[%s] of sheet[%s]\n " , cell1 .getReference (), sheet .getSheetName ()));
37-
37+
3838 if (!commentFlag ) {
3939 sb .append (String .format ("Expected: [%s], Found: [%s]\n " , getCellValue (cell1 ), note ));
4040 return ;
4141 }
42-
43- CreationHelper factory = sheet .getWorkbook ().getCreationHelper ();
44- //get an existing cell or create it otherwise:
45-
46- ClientAnchor anchor = factory .createClientAnchor ();
47- //i found it useful to show the comment box at the bottom right corner
48- anchor .setCol1 (cell1 .getColumnIndex () + 1 ); //the box of the comment starts at this given column...
49- anchor .setCol2 (cell1 .getColumnIndex () + 3 ); //...and ends at that given column
50- anchor .setRow1 (cell1 .getRowIndex () + 1 ); //one row below the cell...
51- anchor .setRow2 (cell1 .getRowIndex () + 5 ); //...and 4 rows high
52-
53- Drawing drawing = sheet .createDrawingPatriarch ();
54- Comment comment = drawing .createCellComment (anchor );
55-
56- //set the comment text and author
57- comment .setString (factory .createRichTextString ("Found " + note ));
58- comment .setAuthor ("SYSTEM" );
59-
60- cell1 .setCellComment (comment );
42+
43+ synchronized (sheet ) {
44+ CreationHelper factory = sheet .getWorkbook ().getCreationHelper ();
45+ //get an existing cell or create it otherwise:
46+
47+ ClientAnchor anchor = factory .createClientAnchor ();
48+ //i found it useful to show the comment box at the bottom right corner
49+ anchor .setCol1 (cell1 .getColumnIndex () + 1 ); //the box of the comment starts at this given column...
50+ anchor .setCol2 (cell1 .getColumnIndex () + 3 ); //...and ends at that given column
51+ anchor .setRow1 (cell1 .getRowIndex () + 1 ); //one row below the cell...
52+ anchor .setRow2 (cell1 .getRowIndex () + 5 ); //...and 4 rows high
53+
54+ Drawing drawing = sheet .createDrawingPatriarch ();
55+ Comment comment = drawing .createCellComment (anchor );
56+
57+ //set the comment text and author
58+ comment .setString (factory .createRichTextString ("Found " + note ));
59+ comment .setAuthor ("SYSTEM" );
60+
61+ cell1 .setCellComment (comment );
62+ }
6163 }
6264
6365 public static String getCellValue (XSSFCell cell ) throws Exception {
6466 String content = "" ;
65-
67+
6668 CellType cellType = cell .getCellType ();
67-
69+
6870 if (cellType == CellType .FORMULA )
6971 cellType = cell .getCachedFormulaResultType ();
70-
72+
7173 switch (cellType ) {
7274 case BLANK : content += null ;
73- break ;
75+ break ;
7476 case BOOLEAN : content += cell .getBooleanCellValue ();
75- break ;
77+ break ;
7678 case ERROR : content += cell .getErrorCellString ();
77- break ;
79+ break ;
7880 case STRING : content += cell .getRichStringCellValue ();
79- break ;
81+ break ;
8082 case NUMERIC : content += DateUtil .isCellDateFormatted (cell ) ? cell .getDateCellValue () :
8183 cell .getNumericCellValue ();
82- break ;
84+ break ;
8385 case _NONE : content += null ;
84- break ;
86+ break ;
8587 default : throw new Exception (String .format ("Unexpected Cell[%s] Type[%s] of sheet[%s]" , cell .getReference (),
8688 cell .getCellType (), cell .getSheet ().getSheetName ()));
87- }
89+ }
8890 return content ;
8991 }
90-
92+
9193 public static boolean deleteIfExists (File file ) {
9294 if (file .exists ())
9395 return file .delete ();
94-
96+
9597 return false ;
9698 }
9799
0 commit comments