Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Word中使用officer在图像周围创建边框_R_Shiny_Ms Word_Officer - Fatal编程技术网

如何在Word中使用officer在图像周围创建边框

如何在Word中使用officer在图像周围创建边框,r,shiny,ms-word,officer,R,Shiny,Ms Word,Officer,我想创建一个Word文件,左边有一个文本段落,左边有一个 右侧的传单地图图像 到目前为止,我可以这样做,但我也想在整个传单图像周围做一个边框 在我的示例中,边框的大小只有图像的一半,因此似乎只有左侧有边框 如何使边框与图像一样大? library(shiny) library(officer) library(leaflet) library(mapview) ui <- fluidPage( leafletOutput("leafletmap"), downloadLink("

我想创建一个Word文件,左边有一个文本段落,左边有一个 右侧的传单地图图像

到目前为止,我可以这样做,但我也想在整个传单图像周围做一个边框

在我的示例中,边框的大小只有图像的一半,因此似乎只有左侧有边框

如何使边框与图像一样大?

library(shiny)
library(officer)
library(leaflet)
library(mapview)

ui <- fluidPage(
  leafletOutput("leafletmap"),
  downloadLink("downloadWord", "Download Word Docx")
)

getLeafletMap <- function() {
  leaflet() %>%
    addTiles() %>% 
    addPopups(-93.65, 42.0285, "Here is the <b>Department of Statistics</b>, ISU")
}

server <- function(input, output, session) {
  output$leafletmap <- renderLeaflet({
    getLeafletMap()
  })

  output$downloadWord <- downloadHandler(
    filename = 'Report.docx',
    content = function(file) {
      ## Map #########################
      map <- getLeafletMap()
      mapshot(x = map, file=paste0(getwd(), "/map.png"),
              remove_controls = c("layersControl"))

      ## Title & Texts #########################
      subtitle <- "Report Map"
      str5 <- "Lorem ipsum dolor sit amet, ligula iaculis mollis lacus consectetur, urna vitae potenti tortor!
      Sit commodo, venenatis leo at et. Ligula ac pulvinar sollicitudin gravida, lobortis lectus ligula et.
      Nisl tristique est erat lectus. Sodales egestas amet ac, ultricies nulla eu, risus blandit."

      ## Styles #########################
      text_style_title <- fp_text(font.size = 20, bold = FALSE, font.family = "Arial", color = "#808080")
      text_style <- fp_text(font.size = 10, bold = FALSE, font.family = "Arial")
      par_style <- fp_par(text.align = "justify")

      ## Make Word Docs #########################
      doc <- read_docx() %>%
        body_add_fpar(fpar(ftext("Report with Map", prop = text_style_title), fp_p = par_style)) %>%
        body_add_par("", style = "Normal") %>% # blank paragraph
        body_end_section_continuous() %>%

        body_add_fpar(fpar(ftext(str5, prop = text_style), fp_p = par_style)) %>%
        body_add_fpar(fpar(external_img(src = paste0(getwd(), "/map.png"), height = 3, width = 4.52),
                           fp_p = fp_par(text.align = "right", padding.top = 6,
                                         border = fp_border(width = 1, color = "red")))) %>%
        body_end_section_columns(widths = c(1.5,2), sep = FALSE, space = 0.2) %>%
        print(doc, target = file)
    }
  )
}

shinyApp(ui, server)
库(闪亮)
图书馆(主任)
图书馆(单张)
图书馆(地图视图)
ui%
addPopups(-93.65,42.0285,“这是ISU统计部”)
}

服务器我可以用
flextable
vline
hline
来完成。一项免责声明,由于我无法将
hline
用于
I=0
,因此
I=0
表中有一个空行

library(flextable)
library(officer)

inputFolder <- "test/"
std_border = fp_border(color="orange")

testtable <- data.frame("text" = c("",""), "image" = c("",""))

testft <- flextable(testtable) %>%
  delete_part(part = "header") %>%
  theme_box() %>%
  compose(i = 2, j = 2, value= as_paragraph(as_image(src = paste(inputFolder, "smiley.png", sep = ""), width = 1, height = 1))) %>%
  compose(i = 2, j = 1, value = as_paragraph(as_chunk("Just some random text"))) %>%
  border_remove() %>%
  vline(i=2, j=1, border = std_border) %>%
  vline(i=2, j=2, border = std_border) %>%
  hline(i=1, j=2, border = std_border) %>%
  hline(i=2, j=2, border = std_border)

我可以用
flextable
vline
hline
来完成。一项免责声明,由于我无法将
hline
用于
I=0
,因此
I=0
表中有一个空行

library(flextable)
library(officer)

inputFolder <- "test/"
std_border = fp_border(color="orange")

testtable <- data.frame("text" = c("",""), "image" = c("",""))

testft <- flextable(testtable) %>%
  delete_part(part = "header") %>%
  theme_box() %>%
  compose(i = 2, j = 2, value= as_paragraph(as_image(src = paste(inputFolder, "smiley.png", sep = ""), width = 1, height = 1))) %>%
  compose(i = 2, j = 1, value = as_paragraph(as_chunk("Just some random text"))) %>%
  border_remove() %>%
  vline(i=2, j=1, border = std_border) %>%
  vline(i=2, j=2, border = std_border) %>%
  hline(i=1, j=2, border = std_border) %>%
  hline(i=2, j=2, border = std_border)


它对其他图片有效吗?据我所知,它不起作用。我个人对专栏也有很多问题。一个解决方法是使用一个包含两列的flextable。我也考虑过这一点,但是我怎么能只给右边的列边框上色呢?你可以控制flextables的边框:它是否适用于其他图像?据我所知,它不适用。我个人对列也有很多问题。一种解决方法是使用具有2列的flextable。我也考虑过这一点,但我如何才能只为右侧列边框上色?您可以控制flextables的边框:不幸的是,这适用于这个小示例,但如果列的宽度不同且图像更大,则不起作用。我怎样才能使文本左对齐?只需添加一行
align(j=1,align=“left”,part=“body”)
就可以了,不知道为什么它不能处理不同的宽度和更大的图像?您可以创建任意数量的列和行,并为它们指定所需的宽度和高度。也可以合并单元格。因此,最后您可以将其精确定位在您想要的位置,并在图像的单元格周围放置一个边框,使用正确的i和j值。我的最终解决方案有点不同,不使用
hline
vline
而是
border
,但无论如何,我认为您应该得到赏金,既然你给我指出了正确的方向!:)再次谢谢你,我还不知道边界,谢谢你的提示!不幸的是,这适用于这个小示例,但是如果列的宽度不同,并且图像更大,则不起作用。我怎样才能使文本左对齐?只需添加一行
align(j=1,align=“left”,part=“body”)
就可以了,不知道为什么它不能处理不同的宽度和更大的图像?您可以创建任意数量的列和行,并为它们指定所需的宽度和高度。也可以合并单元格。因此,最后您可以将其精确定位在您想要的位置,并在图像的单元格周围放置一个边框,使用正确的i和j值。我的最终解决方案有点不同,不使用
hline
vline
而是
border
,但无论如何,我认为您应该得到赏金,既然你给我指出了正确的方向!:)再次谢谢你,我还不知道边界,谢谢你的提示!