我一直在使用优秀的R包ReporteRs来获取我的R表和情节。 David Gohel在这里做得很好(David's site)。
我遇到的问题是无法使表格单元格中的填充功能起作用。
以下是我的代码的一部分:
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.bottom.width = 0, border.top.width = 0, border.left.width = 0, border.right.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
, row.names = FALSE
, cell_format = dataCellProp
, text_format = dataTextProp
)
.names = names(MyDataFrame)
headerRow = FlexRow(.names, textProp = headerTextProp, cellProp = headerCellProp )
mfMyDataFrame = addHeaderRow( mfMyDataFrame, headerRow)
footerRow = FlexRow()
footerRow[1] = FlexCell( pot( " ", format = headerTextProp ), cellProp = footerCellProp, colspan = length(.names) )
mfMyDataFrame = addFooterRow( mfMyDataFrame, footerRow)
mfMyDataFrame[,] = parProperties( padding.top = 0, padding.bottom = 0, padding.left = 10, padding.right = 5, text.align = "right" )
doc = addTitle( doc, "Table title", level = 4, stylename= "rTableLegend")
doc = addFlexTable(doc, mfMyDataFrame)
输出.docx文件没有显示表格单元格中的任何填充(没有10个左边,没有5个右边)。我在这里错过了什么吗?
非常感谢提前!
答案 0 :(得分:2)
作者David Gohel:
在github上也有人询问: https://github.com/davidgohel/ReporteRs/issues/10 这是自0.5.3版本以来解决的一个小错误。
以下是适用于单元格填充的代码:
选项(“ReporteRs-fontsize”= 9) dataParProp = parProperties(padding.top = 0,padding.bottom = 0,padding.left = 10,padding.right = 5,text.align =“right”)
mfMyDataFrame = FlexTable(data = iris,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”))