Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add individual styles to Tables #18

Open
Judochopalots opened this issue Aug 20, 2024 · 5 comments
Open

Add individual styles to Tables #18

Judochopalots opened this issue Aug 20, 2024 · 5 comments

Comments

@Judochopalots
Copy link

Judochopalots commented Aug 20, 2024

Enhancement - it would be great to be able to apply individual Table styles.

Similar to what you can do in the python-docx package.
https://www.geeksforgeeks.org/working-with-tables-python-docx-module/
https://python-docx.readthedocs.io/en/latest/user/styles-using.html

For example:
<w:tblStyle w:val="TableGridLight"/>

@jkrumbiegel
Copy link
Collaborator

jkrumbiegel commented Aug 20, 2024

Have you tried adding a style with table properties? I don't remember but this might already work to some degree. At least Style is parametric on the properties type, and this code here suggests I was using table styles at some point (I don't remember in what way though)

attrstyle(::Style{TableProperties}) = "table"

@Judochopalots
Copy link
Author

Interesting, I gave it a quick try but it didn't change anything. It looks like the tblStyle tag doesn't get written into the docx file.

I need to look into it more, but I think it shouldn't be too hard just to pass in a string into TableProperties, which would bypass all of the cell borders, spacing etc elements.

Adding a style in the docx file seems pretty simple, it looks like just adding a tblStyle tag near the top of the file.

I tried it, but for some reason I can't zip the folder back together to create the docx file.

I'll play around a little, and see if I can get it working.

<?xml version="1.0" encoding="UTF-8"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing">
  <w:body>
    <w:tbl>
      <w:tblPr>
        <w:tblCellSpacing w:w="10"/>
        <w:tblStyle w:val="TableGrid"/>
      </w:tblPr>
      <w:tr>
        <w:trPr/>
        <w:tc>
          <w:tcPr/>

@jkrumbiegel
Copy link
Collaborator

The zip file cannot have a top level folder, but standard tools usually add that. You can check in the WriteDocx code how ZipFiles.jl is used for that

@jkrumbiegel
Copy link
Collaborator

And I'll have to make a test case for the table styles, I don't think I had one.

@Judochopalots
Copy link
Author

Ahh ok thanks, yeah just zipping a folder higher works.

Just adding that one line <w:tblStyle w:val="TableGrid"/> works, but I also have to copy the 'styles' file from an existing word file. I don't know if anything in the word file is proprietary to Microsoft, but I guess a work around would just be to add a few standard table styles to the WriteDocx package.

I'll play around, maybe I can make a pull request.

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

No branches or pull requests

2 participants