Re: Cell Styles

458 views
Skip to first unread message

Jason Miller

unread,
Jun 11, 2014, 11:15:47 AM6/11/14
to r-packa...@googlegroups.com
I have the same issue.

On Monday, March 11, 2013 9:31:36 AM UTC-4, hsli...@gmail.com wrote:

Hi!

I have a problem with setting the cell styles, while using the xlsx package. The problem seems to be that getCellStyle and setCellStyle don't seem to recognize 
objects of the type XSSFCellStyle as valid objects. What I'm trying to do is to copy most of the style settings from the original spreadsheet, and actually change only
the color of the font. 

For example, using the getCellStyle -function, I get an object originalStyle which in R shows as

 Java-Object{org.apache.poi.xssf.usermodel.XSSFCellStyle@1cd3ff73}

ie. an XSSFCellStyle object. However, when I try to copy the style (which worked well in previous versions) by using

newStyle<-CellStyle(workbook)
.jcall(newStyle,,"cloneStyleFrom",originalStyle)

it doesn't work. Instead 

newStyle$ref<-originalStyle$clone()

seems to do the trick. Then I change the color of the font by

redFont<-Font(workbook,"red")
.jcall(newStyle$ref,,"setFont",redFont$ref)

However setting the new cellstyle of "cell" by

 setCellStyle(cell,newStyle)

fails with the error message

Error in .jcall(cell, "V", "setCellStyle", cellStyle$ref) :
  method setCellStyle with signature (Lorg/apache/poi/xssf/usermodel/XSSFCellStyle;)V not found

Actually, if i do 

.jmethods(cell) there seems to be for instance two different getCellStyle -methods:

...
[35] "public boolean org.apache.poi.xssf.usermodel.XSSFCell.getBooleanCellValue()"
[36] "public byte org.apache.poi.xssf.usermodel.XSSFCell.getErrorCellValue()"
[37] "public void org.apache.poi.xssf.usermodel.XSSFCell.setCellStyle(org.apache.poi.ss.usermodel.CellStyle)"
[38] "public org.apache.poi.xssf.usermodel.XSSFCellStyle org.apache.poi.xssf.usermodel.XSSFCell.getCellStyle()"
[39] "public org.apache.poi.ss.usermodel.CellStyle org.apache.poi.xssf.usermodel.XSSFCell.getCellStyle()"
[40] "public void org.apache.poi.xssf.usermodel.XSSFCell.setAsActiveCell()"
[41] "public void org.apache.poi.xssf.usermodel.XSSFCell.removeCellComment()"
...

Could this somehow cause a confilict? The problems started when we updated to a new version of R and all packaqes we use.

Bw.

Henri Lindén, Aktia Bank Plc, Helsinki




Reply all
Reply to author
Forward
0 new messages