Git Product home page Git Product logo

Comments (6)

davidgohel avatar davidgohel commented on June 24, 2024

hello, I just had a trial. I can see the page numbers after the inserted section in the default document provided in the package (doc here: https://github.com/davidgohel/officedown/blob/master/inst/rmarkdown/templates/word/skeleton/skeleton.Rmd)

Capture d’écran 2023-03-10 à 10 25 59

Can you provide a reproducible example? I think you may have inserted a section but not the default one, just a new one (before the default one as it is defined at the end of the doc)

from officedown.

fernandoroa avatar fernandoroa commented on June 24, 2024

thanks for the answer, Please confirm if you used the header code provided or similar.

from officedown.

davidgohel avatar davidgohel commented on June 24, 2024

I don't understand, sorry. I am asking if you can provide a reproducible example because I want to try to reproduce your issue. I can not confirm you anything until I am able to reproduce your issue :)

from officedown.

davidgohel avatar davidgohel commented on June 24, 2024

I would use a template where header is containing the page number:

template.docx

Capture d’écran 2023-03-10 à 16 46 40

---
output:
  officedown::rdocx_document:
    reference_docx: template.docx
---
```{r, echo = FALSE}
library(officer)
library(officedown)
```

```{r results='asis', echo = F}
for(i in 1:50) cat("string1", "\n\n", sep = "")
```


```{r, echo = F, results = "asis"}
knit_print_run(
    run_pagebreak()
)
```

```{r results='asis', echo = F}
for(i in 1:50) cat("string2", "\n\n", sep = "")
```

Capture d’écran 2023-03-10 à 16 48 49

If you need to add Word sections, you will have to define the header corresponding to each new section. It applies to previous content (until previous section).

Capture d’écran 2023-03-10 à 16 54 46

Capture d’écran 2023-03-10 à 16 54 51

---
output:
  officedown::rdocx_document:
    reference_docx: template.docx
---
```{r, echo = FALSE}
library(officer)
library(officedown)
srcfile <- file.path(R.home("doc"), "html", "logo.jpg" )
header_template <- function(txt) {
  block_list(
    fpar(ftext(txt),
        external_img(src = srcfile, 
        width = 0.435, height = .175),
        "this is page number ",
        run_word_field(field = "PAGE  \\* MERGEFORMAT"),
        fp_p = fp_par(
                      line_spacing = 2,
                      text.align = "left")
        )
  )
}

sec_pr <- prop_section(
  header_default = header_template("text"),
  type = "continuous"
)
```

```{r results='asis', echo = F}
for(i in 1:50) cat("string1", "\n\n", sep = "")
```

```{r, echo = F}
block_section(sec_pr)
```

```{r, echo = F, results = "asis"}
knit_print_run(
    run_pagebreak()
)
```

```{r results='asis', echo = F}
for(i in 1:50) cat("string2", "\n\n", sep = "")
```

The last example shows the default section is used after a new section have been added. If you want to manage all headers, add a last section at then end so that it will be the last content defined in the doc and the default section will not have to appear:

---
output:
  officedown::rdocx_document:
    reference_docx: template.docx
---
```{r, echo = FALSE}
library(officer)
library(officedown)
srcfile <- file.path(R.home("doc"), "html", "logo.jpg" )
header_template <- function(txt) {
  block_list(
    fpar(ftext(txt),
        external_img(src = srcfile, 
        width = 0.435, height = .175),
        "this is page number ",
        run_word_field(field = "PAGE  \\* MERGEFORMAT"),
        fp_p = fp_par(
                      line_spacing = 2,
                      text.align = "left")
        )
  )
}

sec_pr <- prop_section(
  header_default = header_template("text"),
  type = "continuous"
)
```

```{r results='asis', echo = F}
for(i in 1:50) cat("string1", "\n\n", sep = "")
```

```{r, echo = F}
block_section(sec_pr)
```

```{r, echo = F, results = "asis"}
knit_print_run(
    run_pagebreak()
)
```

```{r results='asis', echo = F}
for(i in 1:50) cat("string2", "\n\n", sep = "")
```


```{r, echo = F}
block_section(sec_pr)
```

Capture d’écran 2023-03-10 à 17 02 59

from officedown.

davidgohel avatar davidgohel commented on June 24, 2024

@fernandoroa why did you cross posted?

from officedown.

fernandoroa avatar fernandoroa commented on June 24, 2024

Thanks for the answers, really helpful. Because after analysis it seems it is not a bug/issue, so I imagined stack was a more appropriate place to continue and you could close the non-bug.

from officedown.

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.