Skip to content
This repository has been archived by the owner on Mar 23, 2020. It is now read-only.

Bug in cellpadding function? Cellpadding in word tables doesn't work. #10

Closed
sculptor3 opened this issue May 3, 2014 · 12 comments
Closed
Labels

Comments

@sculptor3
Copy link

I left it as a question on stackoverflow, but perhaps I am dealing with a bug here.

Here's the stackoverflow topic :http://stackoverflow.com/questions/23434035/r-package-reporters-how-to-let-it-show-cell-padding-in-generated-docx-document

many thanks in advance!

@davidgohel
Copy link
Owner

Hi.
I can't see what's going on with that for now. I will reply later.
David
Le 3 mai 2014 12:23, "sculptor3" notifications@github.com a écrit :

I left it as a question on stackoverflow, but perhaps I am dealing with a
bug here.

Here's the stackoverflow topic :
http://stackoverflow.com/questions/23434035/r-package-reporters-how-to-let-it-show-cell-padding-in-generated-docx-document

many thanks in advance!


Reply to this email directly or view it on GitHubhttps://github.com//issues/10
.

@sculptor3
Copy link
Author

Thanks in advance!

kind regards,
Jelle

@davidgohel
Copy link
Owner

It's corrected (paddings were not translated in EMUs as expected by Office).

Below a code I am using (some FlexTable arguments have changed a little to let body and header/footers be formatted differently). You can modify parProp to see padding effects on paragraphs (the cell[1,1] of the FlexTable).

David

library( ReporteRs )

data1 = data.frame( col1 = 1:5, col2 = rnorm(5), col3 = letters[1:5]
    , col4 = as.Date("2011-09-04", "2011-09-04", "2011-08-20", "2010-12-01", "2013-02-01")
    , col5 = (1:5)/5)


parProp = parProperties( text.align = "right", padding = 15 )


MyFTable = FlexTable( data = data1
  , body.par.props= parProp
  )
MyFTable[1,1, newpar = TRUE] = "Another text. see space before and after"
doc = docx( title = "title" )

doc = addTitle( doc, "addTable", level = 1)
doc = addTable( doc
  , data = data1
  , col.types = c("integer", "double", "character", "date", "percent")
  , layout.properties = tableProperties(
      data.text = textProperties( color = "#354B5E" )
    , data.par = parProp
    , data.cell = cellProperties( border.color= "#354B5E" )
  )
)
doc = addTitle( doc, "addFlexTable", level = 1)
doc = addFlexTable( doc, MyFTable )

writeDoc( doc, "testpaddingparagraph.docx")

@sculptor3
Copy link
Author

Hi David,

Thanks! Do I understand you changed the parProperties function (in which case need to update the library)? I will check it out.

KInd regards,
jelle

@davidgohel
Copy link
Owner

Hi,

Yes, update your package with the following command:

devtools::install_github('ReporteRs', 'davidgohel')

Also, note that FlexTable arguments have changed: cell_format, par_format, text_format have been dropped and replaced by arguments body.cell.props, body.par.props, body.text.props, header.cell.props, header.par.props, header.text.props

David

@sculptor3
Copy link
Author

Hi David,

One final question. Do I understand my old code doesn't work anymore? Or did you just add new functions wihout removing the old ones?

Kind regards,
Jelle

@davidgohel
Copy link
Owner

Yes, you have to rename arguments in your function calls. Formatting properties arguments have been renamed in FlexRow, FlexTable, FlexCell, etc.

Below a "translation" of your code and then 2 suggestions to reduce the code:

library( ReporteRs )
MyDataFrame = iris[1:10,]

###########################################
#### TRANSLATION
headerCellProp = cellProperties(background.color="#ffffff",border.bottom.width = 1, border.top.width = 1, border.left.width = 0, border.right.width = 0)
headerTextProp = textProperties(font.weight="bold", color = "#000000", font.size=9 )
dataCellProp = cellProperties(border.width = 0)
dataTextProp = textProperties(font.size=9, color = "#000000")
dataParProp = parProperties(padding.top = 0, padding.bottom = 0, padding.left = 10, padding.right = 5, text.align = "right")
footerCellProp = cellProperties(background.color="#ffffff",border.bottom.width = 0, border.top.width = 1, border.left.width = 0, border.right.width = 0)

mfMyDataFrame = FlexTable( data = MyDataFrame
  , header.columns = FALSE
  , add.rownames = FALSE #replace row.names by add.rownames
  , body.cell.props = dataCellProp #replace cell_format by body.cell.props
  , body.par.props = dataParProp #add body.par.props
  , body.text.props = dataTextProp #replace text_format by body.text.props
)
.names = names(MyDataFrame)
headerRow = FlexRow(.names, text.properties = headerTextProp, cell.properties = headerCellProp )#replace cellProp  by cell.properties and textProp by text.properties
mfMyDataFrame = addHeaderRow( mfMyDataFrame, headerRow)
footerRow = FlexRow()
footerRow[1] = FlexCell( pot( " ", format = headerTextProp ), cell.properties = footerCellProp, colspan = length(.names) )#replace cellProp  by cell.properties
mfMyDataFrame = addFooterRow( mfMyDataFrame, footerRow)
mfMyDataFrame[,] = parProperties( padding.top = 0, padding.bottom = 0, padding.left = 10, padding.right = 5, text.align = "right" )

###########################################
#### SUGGESTION 1
headerCellProp = cellProperties(background.color="#ffffff",border.bottom.width = 1, border.top.width = 1, border.left.width = 0, border.right.width = 0)
headerTextProp = textProperties(font.weight="bold", color = "#000000", font.size=9 )
dataCellProp = cellProperties(border.width = 0)
dataTextProp = textProperties(font.size=9, color = "#000000")
dataParProp = parProperties(padding.top = 0, padding.bottom = 0, padding.left = 10, padding.right = 5, text.align = "right")
footerCellProp = cellProperties(background.color="#ffffff",border.bottom.width = 0, border.top.width = 1, border.left.width = 0, border.right.width = 0)

mfMyDataFrame = FlexTable( data = MyDataFrame
  , header.columns = TRUE, add.rownames = FALSE
  , body.cell.props = dataCellProp
  , body.par.props = dataParProp
  , body.text.props = dataTextProp
  , header.cell.props = headerCellProp
  , header.par.props = dataParProp
  , header.text.props = headerTextProp
)
#I dropped the footer row as it is empty in your example

###########################################
#### SUGGESTION 2 - need less properties definitions
options( "ReporteRs-fontsize" = 9 )
dataParProp = parProperties(padding.top = 0, padding.bottom = 0, padding.left = 10, padding.right = 5, text.align = "right")

mfMyDataFrame = FlexTable( data = MyDataFrame, body.par.props = dataParProp, header.par.props = dataParProp )

mfMyDataFrame = setFlexTableBorders( mfMyDataFrame, inner.vertical = borderProperties( style = "none" )
  , inner.horizontal = borderProperties( style = "none" ), outer.vertical = borderProperties( style = "none" ) )

David

@sculptor3
Copy link
Author

And again, I thank you so much!! You are very helpful. I hope the ReporteRs package will get many users. It really is a very useful package. I will keep on spreading the word :-)

Kind regards,
jelle

@davidgohel
Copy link
Owner

Thanks!
David

@sculptor3
Copy link
Author

Hi David,

I am not sure what's going wrong, but the installment of your update didn't succeed. Maybe it's my machine that causes the problem. Or shall I wait till your update is on CRAN?

Kind regards,
Jelle

This the error:

*** arch - i386
Warning: running command 'make -f "C:/R/R-301.3/etc/i386/Makeconf" -f "C:/R/R-301.3/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="ReporteRs.dll" OBJECTS="DOCX.o PPTX.o RAPHAEL.o colors.o common.o dml_utils.o raphael_utils.o utils.o"' had status 127
ERROR: compilation failed for package 'ReporteRs'

  • removing 'C:/R/R-3.0.3/library/ReporteRs'
  • restoring previous 'C:/R/R-3.0.3/library/ReporteRs'
    Error: Command failed (1)

@davidgohel
Copy link
Owner

Hi

Do you have Rtools installed? It is required to compile the souces of the package.
http://cran.r-project.org/bin/windows/Rtools/

If you just want the Windows binaries, go to the new release page:
https://github.com/davidgohel/ReporteRs/releases/tag/v0.5.3

David

@sculptor3
Copy link
Author

Thanks! I got it running now.

kind regards,
Jelle

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants