https://bz.apache.org/bugzilla/show_bug.cgi?id=58909

            Bug ID: 58909
           Summary: Performance problem on cloneSheet
           Product: POI
           Version: 3.13-FINAL
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
          Assignee: [email protected]
          Reporter: [email protected]

Created attachment 33476
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=33476&action=edit
proposed patch

Hi all,
I noticed a performance problem using the cloneSheet method of the XSSFWorbook
class.
Currently, the cloneSheet generates an unique name for the cloned sheet.
However, it is common that the generated name has to be changed later to
something more meaningful.
So, a typical use is the following:

XSSFSheet cloned = wb.cloneSheet(idx);
int origCopyIndex = wb.getSheetIndex(cloned);
wb.setSheetName(origCopyIndex, "OtherName");

In our application we use this pattern and we have noticed a huge performance
hit in the setSheetName method because the setSheetName triggers the check of
all the formulas in the workbook to update references to the sheet whose name
was changed. When the workbook has a lot of cells this operation can last a
significant amount of time.

However, this operation on a cloned sheet is completely not necessary because
the generated name won't be in any formula in the workbook.

What I suggest is to add another version of the clonedSheet method for creating
a cloned version with a given name. In this way, it is possible to avoid the
setSheetName.

Something like:

/**
  * Create an XSSFSheet from an existing sheet in the XSSFWorkbook.
  *  The cloned sheet is a deep copy of the original but with a new given
  *  name.
  *
  * @return XSSFSheet representing the cloned sheet.
  * @throws IllegalArgumentException if the sheet index or the sheet
  *         name is invalid
  * @throws POIXMLException if there were errors when cloning
  */
  public XSSFSheet cloneSheet(int sheetNum, String newName)


I attach a patch that includes the newly added method on the XSSFWorkbook class
and some unit tests. I already checked that all existing tests still succeed
after the application of the patch.

You can evaluate if this method should be pull up to the Workbook interface (in
this case it is necessary to provide implementations for the other formats).

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to