Git Product home page Git Product logo

Comments (8)

sampila avatar sampila commented on September 21, 2024 1

Hi @BenHall-1,
We released UniOffice v1.24.0 that support table placeholder, example

// Copyright UniDoc ehf. All rights reserved.
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/unidoc/unioffice/common/license"
	"github.com/unidoc/unioffice/measurement"
	"github.com/unidoc/unioffice/presentation"
	"github.com/unidoc/unioffice/schema/soo/dml"
	"github.com/unidoc/unioffice/schema/soo/pml"
)

func init() {
	// Make sure to load your metered License API key prior to using the library.
	// If you need a key, you can sign up and create a free one at https://cloud.unidoc.io
	err := license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`))
	if err != nil {
		panic(err)
	}
}

func main() {
	ppt, err := presentation.Open("placeholder.pptx")
	if err != nil {
		panic(err)
	}
	defer ppt.Close()

	slides := ppt.Slides()
	for _, slide := range slides {
		placeholders := slide.PlaceHolders()
		for _, ph := range placeholders {
			// Add table into placeholder that having type table placeholder.
			if ph.Type() == pml.ST_PlaceholderTypeTbl {
				tbl := ph.AddTable()

				for ci := 0; ci < 4; ci++ {
					col := tbl.AddCol()
					col.SetWidth(measurement.Millimeter * 52)
				}
				for ri := 0; ri < 3; ri++ {
					row := tbl.AddRow()
					row.SetHeight(measurement.Inch)
					for ci, cell := range row.Cells() {
						cell.TxBody = dml.NewCT_TextBody()

						para := dml.NewCT_TextParagraph()
						cell.TxBody.P = append(cell.TxBody.P, para)

						egtr := dml.NewEG_TextRun()
						para.EG_TextRun = append(para.EG_TextRun, egtr)
						egtr.R = dml.NewCT_RegularTextRun()
						egtr.R.T = fmt.Sprintf("Cell %d:%d", ri, ci)
					}
				}

				style := dml.NewCT_TableStyle()
				style.WholeTbl = dml.NewCT_TablePartStyle()
				tcStyle := dml.NewCT_TableStyleCellStyle()
				tcStyle.Fill = dml.NewCT_FillProperties()
				tcStyle.Fill.SolidFill = dml.NewCT_SolidColorFillProperties()
				tcStyle.Fill.SolidFill.SrgbClr = dml.NewCT_SRgbColor()
				tcStyle.Fill.SolidFill.SrgbClr.ValAttr = "FF9900"
				style.WholeTbl.TcStyle = tcStyle
				tbl.SetStyle(style)

				tbl.SetOffsetX(measurement.Inch)
				tbl.SetOffsetY(measurement.Millimeter * 20)

				// Remove placeholder after the table being added.
				err := ph.Remove()
				if err != nil {
					log.Fatal(err)
				}
			}
		}
	}

	ppt.SaveToFile("result.pptx")
}

from unioffice.

github-actions avatar github-actions commented on September 21, 2024

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/

from unioffice.

sampila avatar sampila commented on September 21, 2024

Hi @BenHall-1,

Can you share the code, current PPTX result and desired PPTX result?

Best regards,
Alip

from unioffice.

BenHall-1 avatar BenHall-1 commented on September 21, 2024

Hey @sampila, sure.

func Table(slide presentation.Slide, tableIndex uint32, data XXX) *common.Table {
	p, _ := slide.GetPlaceholderByIndex(tableIndex)
	
	tbl := slide.AddTable()

	for _ = range data.XXX.Cols {
		c := tbl.AddCol()
		c.SetWidth(1.0 * measurement.Inch)
	}

	headerRow := tbl.AddRow()
	headerRow.SetHeight(measurement.Inch)
	for i, cell := range headerRow.Cells() {
		cell.TxBody = dml.NewCT_TextBody()

		para := dml.NewCT_TextParagraph()
		cell.TxBody.P = append(cell.TxBody.P, para)

		egtr := dml.NewEG_TextRun()
		para.EG_TextRun = append(para.EG_TextRun, egtr)
		egtr.R = dml.NewCT_RegularTextRun()
		egtr.R.T = data.XXX.Cols[i]
	}
	return tbl
}

It currently returns
not_working_1.pptx

However I'd expect a result of
expected_result.pptx
but I cannot work out how to get it to go onto the placeholder

from unioffice.

sampila avatar sampila commented on September 21, 2024

Hi @BenHall-1,

Thank you sharing the code and PPTX file, we will check and give you an update later.

from unioffice.

BenHall-1 avatar BenHall-1 commented on September 21, 2024

Hi @sampila, any update on this?

from unioffice.

sampila avatar sampila commented on September 21, 2024

Hi @BenHall-1,

Regarding this the current UniOffice only supports paragraphs inside placeholders. For positioning the table inside the slide, you can probably use the 'table.SetOffsetX' and 'table.SetOffSetY'.

See Examples: https://github.com/unidoc/unioffice-examples/blob/f47e46c076d1fc7fab6dbec68824a400c257ca54/presentation/tables/main.go#L59
API: https://apidocs.unidoc.io/unioffice/v1.20.0/github.com/unidoc/unioffice/common/#Table

Best regards,
Alip

from unioffice.

sampila avatar sampila commented on September 21, 2024

Closing this issue

from unioffice.

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.