unidoc / unioffice

Pure go library for creating and processing Office Word (.docx), Excel (.xlsx) and Powerpoint (.pptx) documents
https://unidoc.io/unioffice/
Other
4.37k stars 473 forks source link

Cannot insert table correctly #483

Closed dreddsa5dies closed 1 year ago

dreddsa5dies commented 1 year ago

Description

Cannot insert table correctly. I looked issue, but not work for me.

Expected Behavior

Insert table after the paragraph

Actual Behavior

the table inserts after all paragraph

para := doc.InsertParagraphAfter(p)

    for _, docum := range docs {
        para = doc.InsertParagraphAfter(para)
        run := para.AddRun()
        run.Properties().SetBold(true)
        run.AddText("Name " + docum.Name)

        para = doc.InsertParagraphAfter(para)
        _ = para.AddRun()

        for _, mAndT := range docum.Data {
            para = doc.InsertParagraphAfter(para)
            run := para.AddRun()
            run.AddText("Operation " + mAndT.Name)

            para = doc.InsertParagraphAfter(para)
            _ = para.AddRun()

            // table
            table := doc.InsertTableAfter(para)
            table.Properties().SetWidthPercent(100) //nolint:gomnd
            borders := table.Properties().Borders()
            borders.SetAll(wml.ST_BorderSingle, color.Auto, measurement.Point)

            row := table.AddRow()
            row.AddCell().AddParagraph().AddRun().AddText("Tag")
            row.AddCell().AddParagraph().AddRun().AddText("Description")

            for _, tag := range mAndT.Tags {
                row = table.AddRow()
                row.AddCell().AddParagraph().AddRun().AddText(tag)
                row.AddCell().AddParagraph().AddRun().AddText(mAndT.Tags[tag])
            }
        }
    }
github-actions[bot] commented 1 year ago

Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized, other issues go into our backlog where they are assessed and fitted into the roadmap when suitable. If you need to get this done, consider buying a license which also enables you to use it in your commercial products. More information can be found on https://unidoc.io/

sampila commented 1 year ago

Hi @dreddsa5dies,

Could you share a runnable code snippet?

Thanks.

dreddsa5dies commented 1 year ago

Hi! Thank you for your promptness. The code is presented above.

        para := doc.InsertParagraphAfter(p)
    for _, docum := range docs {
        para = doc.InsertParagraphAfter(para)
        run := para.AddRun()
        run.Properties().SetBold(true)
        run.AddText("Name " + docum.Name)

        para = doc.InsertParagraphAfter(para)
        _ = para.AddRun()

        for _, mAndT := range docum.Data {
            para = doc.InsertParagraphAfter(para)
            run := para.AddRun()
            run.AddText("Operation " + mAndT.Name)

                         // ----------------> I want table here

            para = doc.InsertParagraphAfter(para)
            _ = para.AddRun()

            // table
            table := doc.InsertTableAfter(para)
            table.Properties().SetWidthPercent(100) //nolint:gomnd
            borders := table.Properties().Borders()
            borders.SetAll(wml.ST_BorderSingle, color.Auto, measurement.Point)

            row := table.AddRow()
            row.AddCell().AddParagraph().AddRun().AddText("Tag")
            row.AddCell().AddParagraph().AddRun().AddText("Description")

            for _, tag := range mAndT.Tags {
                row = table.AddRow()
                row.AddCell().AddParagraph().AddRun().AddText(tag)
                row.AddCell().AddParagraph().AddRun().AddText(mAndT.Tags[tag])
            }
        }
    }