Giter VIP home page Giter VIP logo

Comments (4)

elong0527 avatar elong0527 commented on August 15, 2024

Could you provide an example to illustrate what exactly you would like to achieve? (either in Word document as attachment or a screenshot)

from r2rtf.

DawnYe avatar DawnYe commented on August 15, 2024

Sorry for the inconvenience. Please see the screenshot below.

table_format

As you can see, the table page header and footer have multiple lines and they are in a table environment (one column and multiple rows) with a bottom border in the header and a top border in the footer. And in the header, the first line about page number is right aligned.

Thanks.

from r2rtf.

elong0527 avatar elong0527 commented on August 15, 2024

Multiple line can be handled by provide a vector of text as input.

I will add feature to vectorize text alignment and other formatting argument in rtf_header and rtf_footer.

I am not sure why a borderline is required for header and footer. No plan to implement them at current stage.
But you can see how to do it by using some internal function in r2rtf.

library(r2rtf)
library(magrittr)

# Define a paragraph with different text justification
# ToDo: enable this feature in rtf_header and rtf_footer
header <- r2rtf:::rtf_paragraph(
              c("{Page \\pagenumber of \\pagefield}",
              "{text1}", 
              "{text2}"),
              justification = c("r", "l","l"), 
              space_before = 0, 
              space_after = 0
)

# Defin a dummy table for page header and page footer line 
line <- data.frame(x = "") %>% 
            rtf_page(border_first = "", border_last = "single") %>% 
            rtf_body(as_colheader = FALSE, 
                     border_left = "",
                     border_right = "", 
                     border_bottom = "", 
                     cell_height = 0.1) %>% 
            rtf_footnote(c("foot1", "foot2"), as_table = FALSE, text_font_size = 12) %>% 
            r2rtf:::rtf_encode_table(verbose = TRUE)
line$body <- gsub("\n", "", line$body, fixed = TRUE)

header <- paste(paste(header, collapse = ""), line$body)
footer <- paste0(line$body, line$footnote)

tbl <- head(iris) %>% 
          rtf_page_header(header) %>% 
          rtf_body() %>% 
          rtf_page_footer(footer)

x <- tbl %>% rtf_encode()
cat(x$body)

tbl %>% rtf_encode() %>% write_rtf("tmp.rtf")

from r2rtf.

DawnYe avatar DawnYe commented on August 15, 2024

This was very helpful. Thanks for the kindly reply. I'll close the issue page.

from r2rtf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.