Coder Social home page Coder Social logo

Comments (2)

tbaliance avatar tbaliance commented on May 14, 2024 2

Sorry, I haven't added that feature yet. I'll add it to the TODO list, or you're welcome to submit a PR. It should be fairly straight forward, you can see how tables are created in AddTable

from unioffice.

lishuu avatar lishuu commented on May 14, 2024

Hi,
Thanks for your response. I add some code as follow.

  1. document.go
func (d *Document) Tables() []Table {
	ret := []Table{}
	if d.x.Body == nil {
		return nil
	}
	for _,ble := range d.x.Body.EG_BlockLevelElts {
		for _, c := range ble.EG_ContentBlockContent {
			for _, t := range c.Tbl {
				ret = append(ret, Table{d, t})
			}
		}
	}
	return ret
}
  1. table.go
func (t Table) Rows() []Row {
	ret := []Row{}
	for _, rc := range t.x.EG_ContentRowContent {
		for _, ctRow := range rc.Tr {
			ret = append(ret, Row{t.d, ctRow})
		}
	}
	return ret
}
  1. row.go
func (r Row) Cells() []Cell {
	ret := []Cell{}
	for _, cc := range r.x.EG_ContentCellContent {
		for _, ctCell := range cc.Tc {
			ret = append(ret, Cell{r.d,ctCell})
		}
	}
	return ret
}
  1. cell.go
func (c Cell) Paragraphs() []Paragraph {
	ret := []Paragraph{}
	for _, ble := range c.x.EG_BlockLevelElts {
		for _, cbc := range ble.EG_ContentBlockContent {
			for _, p := range cbc.P {
				ret = append(ret, Paragraph{c.d, p})
			}
		}
	}
	return ret
}

At last I can iterate table's contents

	for _, tbl := range doc.Tables() {
		for _, row := range tbl.Rows() {
			for _, cell := range row.Cells() {
				for _, p := range cell.Paragraphs() {
					for _, r := range p.Runs() {
						fmt.Println(r.Text())
					}
				}
			}
		}
	}

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.