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

Table lose their formatting when viewed in Word Online #545

Open
bladekey88 opened this issue May 20, 2020 · 0 comments
Open

Table lose their formatting when viewed in Word Online #545

bladekey88 opened this issue May 20, 2020 · 0 comments

Comments

@bladekey88
Copy link

@bladekey88 bladekey88 commented May 20, 2020

This library is phenomenal and really useful.

I generated a two clolumn table tables with borders in the document in broswer.

This all worked fine, and when viewing the downloaded document in Word 365 on the desktop, everything displays correctly.

However, when viewed through live.com (or the browser plugins), the table loses all its formatting, and reverts to both columns being 1 character wide, with no border. This is easily corrected by dragging the columns and re-applying the formatting, but for more complex tables this could be an issue (assuming it's not an issue with my code use).

Code Used:

`
<script>
    function exportToWord() {

        const subject = (results[0]['subjectid']['subjectname'])
        const topic = (results[0]['topicid']['topicname'])



        let doc = new docx.Document(
            {
        title: subject + ":" + topic + " Worksheet",
                creator: "Unknown",
                title: subject + ":" + topic + " Worksheet",
                description: "Exported Questions for " + topic,
                subject: subject,
                lastModifiedBy: "Unknown",
                revision: 1,
                })

    const mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"



    const docTitle =
        new docx.Paragraph({
        alignment: docx.AlignmentType.CENTER,
            children:
                [new docx.TextRun({
        text: subject + " Questions",
                    bold: true,
                    color: "black",
                    size: 48,
                    font: "Calibri",
                    smallCaps: true,
                })
                ],
        })

    const blankParagraph = new docx.Paragraph({
        text: "",
    });




    const topicParagraph =
        new docx.Paragraph({
        alignment: docx.AlignmentType.CENTER,
            children:
                [new docx.TextRun({
        text: "Topic - " + topic,

                    bold: true,
                    color: "black",
                    size: 28,
                    font: "Calibri",
                    smallCaps: true,
                })
                ],
        })

    const pageBreak = new docx.Paragraph({
        children: [new docx.PageBreak()],
    });


    const rowWorksheet = results.map(function (result) {
        return new docx.TableRow(
            {
        children: [
                    new docx.TableCell(
                        {
        children: [new docx.Paragraph(result.questiontext)],
                            width:
                            {
        size: 40,
                                type: docx.WidthType.PERCENTAGE,
                            }
                        }),
                    new docx.TableCell(
                        {
        children: [],
                            width:
                            {
        size: 60,
                                type: docx.WidthType.PERCENTAGE,
                            }
                        }),
                ],
            })
    })


    const tableblank = new docx.Table(
        {
        margins:
            {
        top: 250,
                bottom: 250,
                right: 200,
                left: 100,
            },
            cantSplit: true,
            rows: rowWorksheet,

        });


    doc.addSection(
        {
        headers: {
        default: new docx.Header({
        children: [
                new docx.Paragraph({
        children: [
                        new docx.TextRun("Downloaded From  "),
                    ],
                }),
            ],
        }),
    },
            footers: {
                default: new docx.Footer({

        children: [
                    new docx.Paragraph({
        children: [
                        new docx.TextRun({
        children: ["Page  ", docx.PageNumber.CURRENT],
                        }),
                        new docx.TextRun({
        children: [" of ", docx.PageNumber.TOTAL_PAGES],
                        }),
                    ],
                })


                     ],
                })

            },
            children: [

                docTitle,
                blankParagraph,
                topicParagraph,
                tableblank,


        ],
    });

    docx.Packer.toBlob(doc)
        .then(blob => {
        console.log(blob);
            saveAs(blob, subject + "_" + topic + "_worksheet.docx");
            console.log("Document created successfully");
        });

}

</script>
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.