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 2014/03/20 20:34:05 UTC

[Bug 56295] New: Cell styles are not copied from one workbook to another

https://issues.apache.org/bugzilla/show_bug.cgi?id=56295

            Bug ID: 56295
           Summary: Cell styles are not copied from one workbook to
                    another
           Product: POI
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P2
         Component: XSSF
          Assignee: dev@poi.apache.org
          Reporter: nestor.urquiza@gmail.com

Attached you will find a zip file containing a JUnit test to replicate the
issue. Basically we open a first workbook and add to it a new sheet where we
clone the content from a second workbook sheet. We are expecting the style from
the second to appear in the first however that does not happen as the
screenshots show.

1. Download poi-3.10-FINAL

2. Download the junit-4.11.jar which includes hamcrest (POI lib ships the
version without hamcrest)

3. Download the zip file and uncompress it somewhere

4. Compile and run the test as per the below (Note I downloaded everything to
my ~/Downloads MAC directory):
$ cd xlsx-xslm-style-lost-on-merge/
$ javac -cp
".:/Users/nu/Downloads/poi-3.10-FINAL/*:/Users/nu/Downloads/poi-3.10-FINAL/lib/*"
*.java
$ java -cp
".:/Users/nu/Downloads/poi-3.10-FINAL/*:/Users/nu/Downloads/poi-3.10-FINAL/lib/*:/Users/nu/Downloads/poi-3.10-FINAL/ooxml-lib/*:/Users/nu/Downloads/junit-4.11.jar"
org.junit.runner.JUnitCore XlsxSheetCopyUtilTest

5. Look into the output.xlsm file to confirm the styles from pet.xlsx are lost
when its sheet is copied to zoom200.xlsm file.

BTW the attached files are coming from
https://issues.apache.org/bugzilla/show_bug.cgi?id=52348 with small
modifications.

Thanks,
- Nestor

-- 
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


[Bug 56295] Cell styles are not copied from one workbook to another

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56295

nestor.urquiza@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |NEW

-- 
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


[Bug 56295] Cell styles are not copied from one workbook to another

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56295

--- Comment #5 from nestor.urquiza@gmail.com ---
Nick thanks for the suggestion. I chenged the below in
XlsxSheetCopyUtil#copyCell:
//newCell.setCellStyle(newCellStyle);
newCell.getCellStyle().cloneStyleFrom(newCellStyle);


However I got the failure below even though files and code are Excel 2013
compatible as far as I understand:

There was 1 failure:
1) testMergeXlslsWithStyles(XlsxSheetCopyUtilTest)
java.lang.IllegalArgumentException: Can only clone from one XSSFCellStyle to
another, not between HSSFCellStyle and XSSFCellStyle
    at
org.apache.poi.xssf.usermodel.XSSFCellStyle.cloneStyleFrom(XSSFCellStyle.java:186)
    at XlsxSheetCopyUtil.copyCell(XlsxSheetCopyUtil.java:113)
    at XlsxSheetCopyUtil.copyRow(XlsxSheetCopyUtil.java:80)
    at XlsxSheetCopyUtil.copySheets(XlsxSheetCopyUtil.java:49)
    at XlsxSheetCopyUtil.copySheets(XlsxSheetCopyUtil.java:34)
    at
XlsxSheetCopyUtilTest.testMergeXlslsWithStyles(XlsxSheetCopyUtilTest.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runners.Suite.runChild(Suite.java:127)
    at org.junit.runners.Suite.runChild(Suite.java:26)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:138)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:117)
    at org.junit.runner.JUnitCore.runMain(JUnitCore.java:96)
    at org.junit.runner.JUnitCore.runMainAndExit(JUnitCore.java:47)
    at org.junit.runner.JUnitCore.main(JUnitCore.java:40)

There is no reference to HSSF at all as you can see:
Nestors-MacBook-Pro:xlsx-xslm-style-lost-on-merge nu$ find ./ -name "*.java"
.//CellRangeAddressWrapper.java
.//XlsxSheetCopyUtil.java
.//XlsxSheetCopyUtilTest.java
Nestors-MacBook-Pro:xlsx-xslm-style-lost-on-merge nu$ find ./ -name
"*.java"|xargs grep HSSF
Nestors-MacBook-Pro:xlsx-xslm-style-lost-on-merge nu$ 

Any ideas?

Thanks!
- Nestor

-- 
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


[Bug 56295] Cell styles are not copied from one workbook to another

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56295

--- Comment #8 from nestor.urquiza@gmail.com ---
See v2 file and follow the original instructions to run the project. Let me
know please if you need any more information. Thanks, - Nestor

-- 
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


[Bug 56295] Cell styles are not copied from one workbook to another

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56295

--- Comment #3 from nestor.urquiza@gmail.com ---
Created attachment 31420
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=31420&action=edit
received result

-- 
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


[Bug 56295] Cell styles are not copied from one workbook to another

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56295

--- Comment #7 from nestor.urquiza@gmail.com ---
Created attachment 31475
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=31475&action=edit
v2

-- 
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


[Bug 56295] Cell styles are not copied from one workbook to another

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56295

Nick Burch <ap...@gagravarr.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

--- Comment #4 from Nick Burch <ap...@gagravarr.org> ---
Looking at your program, I can't spot any logic where you clone the styles from
the old workbook to the new one. If you want the styles to come across, you
need to use the cloneStyleFrom method:
http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/CellStyle.html#cloneStyleFrom%28org.apache.poi.ss.usermodel.CellStyle%29

Can you try that and see if it resolves the problem?

-- 
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


[Bug 56295] Cell styles are not copied from one workbook to another

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56295

--- Comment #1 from nestor.urquiza@gmail.com ---
Created attachment 31418
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=31418&action=edit
java sources and resources

-- 
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


[Bug 56295] Cell styles are not copied from one workbook to another

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56295

--- Comment #6 from nestor.urquiza@gmail.com ---
I have commented out the whole old code and leverage only to the
cloneStyleFrom() as shown below. No errors but the style is still not there in
the output. I will attach the whole project again with the latest changes with
the hope you guys can quickly replicate and determine why the code below has no
effect:

newCell.getCellStyle().cloneStyleFrom(oldCell.getCellStyle());

Thanks!
- Nestor

-- 
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


[Bug 56295] Cell styles are not copied from one workbook to another

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56295

--- Comment #2 from nestor.urquiza@gmail.com ---
Created attachment 31419
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=31419&action=edit
expected result

-- 
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