Code Monkey home page Code Monkey logo

unioffice's Introduction

unioffice is a library for creation of Office Open XML documents (.docx, .xlsx and .pptx). Its goal is to be the most compatible and highest performance Go library for creation and editing of docx/xlsx/pptx files.

Build Status GitHub (pre-)release License: UniDoc EULA ApiDocs

https://github.com/unidoc/unioffice/

Status

  • Documents (docx) [Word]
    • Read/Write/Edit
    • Formatting
    • Images
    • Tables
    • Word to PDF (docx to pdf)
  • Spreadsheets (xlsx) [Excel]
    • Read/Write/Edit
    • Cell formatting including conditional formatting
    • Cell validation (drop down combobox, rules, etc.)
    • Retrieve cell values as formatted by Excel (e.g. retrieve a date or number as displayed in Excel)
    • Formula Evaluation (100+ functions supported currently, more will be added as required)
    • Embedded Images
    • All chart types
  • PowerPoint (pptx) [PowerPoint]
    • Creation from templates
    • Textboxes/shapes

Performance

There has been a great deal of interest in performance numbers for spreadsheet creation/reading lately, so here are unioffice numbers for this benchmark which creates a sheet with 30k rows, each with 100 columns.

creating 30000 rows * 100 cells took 3.92506863s
saving took 89ns
reading took 9.522383048s

Creation is fairly fast, saving is very quick due to no reflection usage, and reading is a bit slower. The downside is that the binary is large (33MB) as it contains generated structs, serialization and deserialization code for all of DOCX/XLSX/PPTX.

Installation

go get github.com/unidoc/unioffice/

License key

This software package (unioffice) is a commercial product and requires a license code to operate.

To Get a Metered License API Key in the Free Tier, sign up on https://cloud.unidoc.io

Document Examples

Spreadsheet Examples

Presentation Examples

Raw Types

The OOXML specification is large and creating a friendly API to cover the entire specification is a very time consuming endeavor. This library attempts to provide an easy to use API for common use cases in creating OOXML documents while allowing users to fall back to raw document manipulation should the library's API not cover a specific use case.

The raw XML based types reside in the schema/ directory. These types are accessible from the wrapper types via a X() method that returns the raw type.

For example, the library currently doesn't have an API for setting a document background color. However it's easy to do manually via editing the CT_Background element of the document.

doc := document.New()
doc.X().Background = wordprocessingml.NewCT_Background()
doc.X().Background.ColorAttr = &wordprocessingml.ST_HexColor{}
doc.X().Background.ColorAttr.ST_HexColorRGB = color.RGB(50, 50, 50).AsRGBString()

Contribution guidelines

If you are interested in contributing, please contact us.

Development Notes

The bash script file run_test.sh could be used to run test and update the test result (if required). This script could receive the following parameter:

  • -s: Save a baseline, updates all the test result.
  • -v: Run the test in verbose mode.
  • t or --testname [test name]: Run a specific test name. For example -t AddImage would be running a TestAddImage test.

To run the script in dockerized environment, use the provided Makefile such as:

make docker-test

or

make docker-update-testdata

Go Version Compatibility

Officially we support three latest Go versions, but internally we would test the build with up to five latest Go versions in our CI runner.

Support and consulting

Please email us at [email protected] for any queries.

If you have any specific tasks that need to be done, we offer consulting in certain cases. Please contact us with a brief summary of what you need and we will get back to you with a quote, if appropriate.

License agreement

The use of this software package is governed by the end-user license agreement (EULA) available at: https://unidoc.io/eula/

unioffice's People

Contributors

5andr0 avatar freb avatar gunnsth avatar im-kulikov avatar lunny avatar mec07 avatar nkryuchkov avatar preciselytom avatar sampila avatar srinathh avatar tbaliance avatar unidoc-build avatar universonic avatar wgliang avatar zgordan-vv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unioffice's Issues

Does not compile on Windows

Description

Trying to use document.New() on Windows.

Expected Behavior

It compiles.

Actual Behavior

Getting an error:

go build baliance.com/gooxml/schema/soo/wml: C:\Go\pkg\tool\windows_amd64\compile.exe: fork/exec C:\Go\pkg\tool\windows_amd64\compile.exe: The filename or extension is too long.

missing SetLineSpacing

Description

I have append it into source go.Missing SetLineRuleSpacing too

Expected Behavior

1.5 line = (font size )*1.5
double = (font size)*2
chinese firstIndent 2ch = (font size)*2

Actual Behavior

code:

func (p ParagraphProperties) SetLineSpacing(linespacing measurement.Distance){
p.x.Spacing = wml.NewCT_Spacing()
p.x.Spacing.LineAttr = &wml.ST_SignedTwipsMeasure{}
p.x.Spacing.LineAttr.Int64=gooxml.Int64(int64(linespacing / measurement.Twips))
}

I ran the example code but got a broken file

Description

Hi,
I was running go run main.go under _examples/spreadsheet/bar-chart to generate the bar-chart.xlsx. When I was trying to open bar-chart.xlsx I got Excel could not open bar-chart.xlsx because some content is unreadable.
Here's the broken file.
bar-chart.xlsx

OS: maxOS Sierra(10.12.5)
Go version: go1.9.3 darwin/amd64
Excel version: Office 365, version: 15.32(170309)

Heading Level problem

Hi,
I update the package today and find out a bug with Heading Level.
This is how the toc.docx in _examples directory shows:
hl

And this is how the docx I generate with the code _examples/toc/main.go shows:
hlp

As you see,the title is not at the beginning of the line as before.
I use Office Word 2016.

Only support PNG format?

I try to run image example code with jpeg format photo, but generated docx file cannot display the photo, only displays an empty box with border around.

Does the library only support png format photo?

add superscript and subscript to RunProperties

Description

Add the ability to change the text formatting to superscript and subscript.

Expected Behavior

The text will have super and subscripts.

Actual Behavior

There seems to be no way to do this. Can't find a function call on RunProperties that supports this. I imagine that it would like something like SetBold(bool).

Access to existing headers & footers

Description

My approach with another library has been to create a document to act as a template that included as much of the content and formatting as possible, overwriting what I could and adding content where I had to.

I am am attempting to overwrite the content of an existing header in a document instead of adding a new one from scratch, but there doesn't appear to be a way to access to the headers and footers on the document struct like you can with the Paragraphs method, for instance.

Expected Behavior

The ability to access headers and footers in an existing document.

Actual Behavior

I cannot figure out how to edit existing headers and footers as the headers and footers fields on Document are not exported.

As I understand it, headers and footers are stored differently than other aspects of the XML document, so I'm just wondering if this is a work in progress or if I just missed something simple.

Feature request - set table cell width

Description

Desirable to be able to set column widths in tables in Word documents to either fixed or percentage sizes. Assumption that this can be achieved by a SetWidth property on cells as already available for tables as a whole or cell-spacing, rather than having to introduce something like table.Column().SetWidthAuto().

Expected Behavior

  1. cell.Properties().SetWidthPercent(25.0) - cell is 1/4 of designated table width
  2. cell.Properties().SetWidth(20*measurement.Pixel72) - cell is 20 pixels wide
  3. cell.Properties().SetWidthAuto() - current behaviour

Actual Behavior

New feature - so no existing capability bar the autosize option. Requested feature is desirable to prevent an overly large first column from forcing line break on all rightward columns. Arguably this should have been part of the spec for FR #109 (Apologies)

spreadsheet: SaveToFile broken

Description

can not open an output file by loading an existing file
(Excel for Mac ver 15.29.1)

// empty.xlsx was created in this way (Excel -> New -> Save)
wb, _ := spreadsheet.Open("empty.xlsx")
// it's broken
wb.SaveToFile("empty_out.xlsx")

empty.xlsx

table SetWidth is not valid

In my project,

table.Properties().SetWidth(5 * measurement.Centimeter)

but the export has no width. when I run _examples as same no effect.

User interface

I was thinking that with all the work you have done it may be easy to build a web GUI that can display the documents and even edit them.

Gopherjs can be used to run the golang in the web browser.
For display I don't know how easy it will be to display a document but I don't think it has to be an exact representation.

Quill and other libraries would also help

It's Office Open XML not OpenOffice

Description

Your Readme describes this as a library for OpenOffice, but it's actually a library for Office Open XML. Most people would associate "OpenOffice" with OpenOffice.org or it's fork, LibreOffice. Both of those suites can read these files, but have a different native file format.

Expected Behavior

It should say "Office Open XML"

Actual Behavior

It says "OpenOffice"

image can not display

Description

Using AddDrawingInline() to insert image, but not show.

Expected Behavior

Actual Behavior

img

doc := document.New()
table := doc.AddTable()
row := table.AddRow()
row.AddCell().AddParagraph().AddRun().AddText("Pic")
image, err := common.ImageFromFile("tmp.jpg")
if err != nil {
	panic(err)
}
imageRef, err := doc.AddImage(image)
if err != nil {
	panic(err)
}
_, err = row.AddCell().AddParagraph().AddRun().AddDrawingInline(imageRef)
if err != nil {
	panic(err)
}
err = doc.SaveToFile("test.doc")
if err != nil {
	fmt.Println(err)
}

Please include a reproducible code snippet or document attachment that
demonstrates the issue.

Feature request - add hyperlink functionality to Word documents

Description

xlsx output format appear to support a hyperlink property on individual cells, (SetHyperlink). This FR is to request that functionality to be extended to docx output.

Expected Behavior

From inspection of the spreadsheet setup it would look like the natural place to add this functionality would be as a property to the run object, that way hyperlinks can appear the middle of text blocks, or in table cells. As in the following simple example

para = doc.AddParagraph
run1 = para.AddRun().AddText("If you like the Go language then start at ")
run2 = para.AddRun
run2.SetHyperlink("https://golang.org")
run2.AddText("The Go Programming Language")
run3 = para.AddRun().AddText(", but put a lot of time aside to learn!")

Actual Behavior

New functionality.

Feature request - table alignment, row height and cell vertical justification

Description

Would like implementation of more of the "Table Properties" dialog from Word. Specifically, the Table Alignment feature from the Table tab via the Alignment radio button trio; the Size from the Row tab; and the Vertical Alignment radio button trio from the Cell tab.

Expected Behavior

  1. table.Properties().SetAlignment(ST_JcLeft) etc, same as current paragraph properties
  2. row.Properties().SetHeight in same manner as table.Properties().SetWidth...
  3. cell.Properties.SetVerticalAlignment(ST_JcvTop/ST_JcvCenter/ST_JcvBottom)

Actual Behavior

New features for this excellent Go library.

Failure parsing Word document saved from Google Docs, reproducible

Bug provocation.docx

I created this file by opening Google Drive, selecting New, then Google Docs, writing the content (some text and a table), then File > Download as... > Microsoft Word (.docx).

Both document.Open() and document.Read() fail loading the file with this error:

error decoding word/document.xml: parsing 9029.0 as int: strconv.ParseInt: parsing "9029.0": invalid syntax

Indeed, the file contains, inside word/document.xml:

    <w:tbl>
      <w:tblPr>
        <w:tblStyle w:val="Table1"/>
        <w:tblW w:w="9029.0" w:type="dxa"/>

This seems to be the width of the table in the document. I investigated whether dotted-decimal values are legal in w:tblW. Apparently there are three kinds of legal values here:

  1. Integer
  2. Dotted-decimal value with percentage sign
  3. Dotted-decimal value with unit

I conclude that this is a bug in Google Docs, but I also note that Microsoft Word can open the input file and render it properly, while gooxml does not.

I suggest that gooxml works around this by parsing decimal numbers as floats and discarding the fractional part (especially if it is zero). Is this feasible to do, or does the XML decoding process dictate that integers are parsed as integers?

Adding internal links

I'm looking to add internal links in a document. I see the functionality for adding HyperLinks, but that appears to only be for external URLs. I'm looking for the functionality of creating a hyperlink to a "Place in this document" as is available from within word.

My use case is adding links to appendices into the body of my document (e.g. "see "). The text containing the link would most likely be a run that points to a heading.

document table: merging cells and styles

I just started working with tables and there appear to be a few API calls missing for tables.

First, I can't seem to merge cells. I did see some options using .X(), but I thought I'd check to see if this is something you were planning on implementing first.

Second, I'm currently using table styles for formatting my tables. This supports things like bolding the first row or otherwise formatting it differently, and apply styling only to the first column as well. When using Word this is helpful for keeping all of your tables uniformly formatted, but I don't think this is really necessary for this library since all formatting is explicit and could be abstracted to a function if needed. I'm more just curious if this is on the roadmap as it might affect my approach.

fails to handle images

Description

I am takes a basic google doc and exporting it as word and then doing a basic find replace and then uploading it back into google docs.

Expected Behavior

doc opens in google docs

Actual Behavior

doc will not open in google docs

i am manually downloading it from google docs as a word doc which is the default for google docs.
After it spits out the Test-out.docx, i manual drag it into google drive.


// Copyright 2017 Baliance. All rights reserved.

package main

import (
[Test.docx](https://github.com/baliance/gooxml/files/1342384/Test.docx)

	"fmt"
	"log"

	"baliance.com/gooxml/document"
)

func main() {
	doc, err := document.Open("Test.docx")
	if err != nil {
		log.Fatalf("error opening document: %s", err)
	}

	paragraphs := []document.Paragraph{}
	for _, p := range doc.Paragraphs() {
		paragraphs = append(paragraphs, p)
	}

	// This sample document uses structured document tags, which are not common
	// except for in document templates.  Normally you can just iterate over the
	// document's paragraphs.
	for _, sdt := range doc.StructuredDocumentTags() {
		for _, p := range sdt.Paragraphs() {
			paragraphs = append(paragraphs, p)
		}
	}

	for _, p := range paragraphs {
		for _, r := range p.Runs() {
			switch r.Text() {
			case "Test":
				// ClearContent clears both text and line breaks within a run,
				// so we need to add the line break back
				r.ClearContent()
				r.AddText("Test-BG ")
				r.AddBreak()
			case "This file is used to test the translation.":
				r.ClearContent()
				r.AddText("This file is used to test the translation-BG.")

			default:
				fmt.Println("not modifying", r.Text())
			}
		}
	}

	doc.SaveToFile("Test-out.docx")
}


Test.docx

recompile the example and cannot open the generate .docx

experimental environment:
1.OS:windows 7 x64、VScode
2.Go version 1.9
first,i use "go get baliance.com/gooxml",after that,i use "go build baliance.com/gooxml/..."but the compiler error:"The filename or extension is too long." so i rename the"schemas.openxmlformats.org"
to "s" and change all the "schemas.openxmlformats.org" to "s" of the path in all files. finally,it compiles successfully. i test the file in "_examples/document/tables/main.go"
------go run main.go---
------success----(maybe success,no error and generate the" tables.docx" file)------
------cannot open the tables.docx------
so i test other examples,they all generate the .docx but cannot open with "MS Office "

cheers,looking for your replay.

insert image to header can not display

Description

I use AddDrawingInline(iref) to insert image into the header. But it result can not display the image.

default

Expected Behavior

Actual Behavior

The code:

  img,err:=common.ImageFromFile("header.png")
  if err!=nil{
    log.Fatalf("unable to create image: %s",err)
  }
  iref,err:=doc.AddImage(img)
  if err!=nil{
    log.Fatalf("unable to to add image to document: %s",err)
  }

  version="DX-SDP-B40 V1.3"
  hdr=doc.AddHeader()
  para=hdr.AddParagraph()
  para.AddRun().AddDrawingInline(iref)
  para.AddRun().AddText(version)

  // add page break
  para=doc.AddParagraph()
  section=para.Properties().AddSection(wml.ST_SectionMarkNextPage)
  section.SetHeader(hdr,wml.ST_HdrFtrDefault)
  section.SetFooter(ftr,wml.ST_HdrFtrDefault)

Support adding/replacing MERGEFIELDs

I'm trying to understand if/how 'MERGEFIELDS' are supported within gooxml, or if it is the kind of thing I would need to drop into .X() to handle?

I did see that there are doc.FormFields(), r.AddField(), etc functions, but as best I could tell, these didn't seem to do what I want. I also came across the 'KnownFields', which seems to correlate with this, but couldn't tell if it was associated to some deeper support/code:

Essentially, is there a way to create, read, edit/update, etc these elements in a gooxml native way currently? And if not, do you have any suggestions of the best way to interact with them?

Below is a snippet from a document that uses these fields:

<w:p w14:paraId="1566BC4D" w14:textId="3B6A9F12" w:rsidR="006D368D" w:rsidRPr="00497636" w:rsidRDefault="000E0283">
        <w:pPr>
            <w:rPr>
                <w:lang w:val="en-AU"/>
            </w:rPr>
        </w:pPr>
        <w:r>
            <w:rPr>
                <w:lang w:val="en-AU"/>
            </w:rPr>
            <w:t>Merge Field:</w:t>
        </w:r>
        <w:r w:rsidR="006D368D">
            <w:rPr>
                <w:lang w:val="en-AU"/>
            </w:rPr>
            <w:t xml:space="preserve">
            </w:t>
        </w:r>
        <w:r w:rsidRPr="00497636">
            <w:rPr>
                <w:lang w:val="en-AU"/>
            </w:rPr>
            <w:fldChar w:fldCharType="begin"/>
        </w:r>
        <w:r w:rsidRPr="00497636">
            <w:rPr>
                <w:lang w:val="en-AU"/>
            </w:rPr>
            <w:instrText xml:space="preserve"> MERGEFIELD  $Foo.Bar  \* MERGEFORMAT </w:instrText>
        </w:r>
        <w:r w:rsidRPr="00497636">
            <w:rPr>
                <w:lang w:val="en-AU"/>
            </w:rPr>
            <w:fldChar w:fldCharType="separate"/>
        </w:r>
        <w:r w:rsidRPr="00497636">
            <w:rPr>
                <w:lang w:val="en-AU"/>
            </w:rPr>
            <w:t>«$Foo.Bar»</w:t>
        </w:r>
        <w:r w:rsidRPr="00497636">
            <w:rPr>
                <w:lang w:val="en-AU"/>
            </w:rPr>
            <w:fldChar w:fldCharType="end"/>
        </w:r>
    </w:p>

Refs:

Using run.AddField(document.FieldNumberOfPages) for footer produces "document contains fields that may refer to other files" prompt

Hi, I'm trying to add page numbers to my document in the footer using the sample example provided. The document was created successfully but there's a prompt of 'This document contains fields that may refer to other files. Do you want to update the fields in this document?'

The content of the document is correct though even though I click No for the prompt

Here's my code for the footer

doc := document.New()
ftr := doc.AddFooter()
para := ftr.AddParagraph()
run := para.AddRun()
run.AddText("Test")
run.AddTab()
run.AddTab()
run.AddField(document.FieldCurrentPage)
run.AddText(" of ")
run.AddField(document.FieldNumberOfPages)
doc.BodySection().SetFooter(ftr, wml.ST_HdrFtrDefault)

Enhancement request: more complex table examples

Description

Could you please update/extend the table example to show more complex tables, e.g. cell highlight use, left/right/centre alignment. I'm particularly interested in control of horizontal alignment - and centering headings seems to be a non-trivial task to configure.

Expected Behavior

n/a - documentation update

Actual Behavior

n/a - documentation update

Please include a reproducible code snippet or document attachment that
demonstrates the issue.

Support for document charts

Is there any support or planned support for adding charts or editing data associated with an existing chart?

I know that when a chart is created a spreadsheet gets embedded into the word/embeddings folder of the docx file. I also know that if you update this spreadsheet, the chart in the document doesn't get updated until you "edit data" from within word, unless you also change the data in word/charts/chart1.xml.

Being able to edit the embedded spreadsheet would probably be sufficient for my needs, but adding and editing charts would be fantastic. Any thoughts?

Unable to figure out how to set page margins on document

Description

I am unable to figure out how to set page margins on document. I would like to set margins of the generated document to 0.5 inch

I managed to follow the rabbit hole of XML down to doc.X().Body.SectPr.PgMar.TopAttr but then there's a pointer to an int64 which i'm not able to set. When I try to retrieve the object, I get a null pointer error.

Bug in paragraph Indentation level functions

I think I discovered an issue with the paragraph indentation that I added to a previous issue. I'm not sure if closed issues are are monitored, so I'm creating this.

Description

The SetNumberingDefinition and SetNumberingDefinitionByID methods on Paragraph set the PPr.NumPr.NumId property but the value that they set it to is the ID of the abstractNum. I believe they should be setting the value to the ID of a CT_Num.NumIdAttr which references an abstractNum.

Expected Behavior/Actual Behaviour

In document.xml, paragraphs look like this (second indented item):

<w:p w14:paraId="1D8F95A7" w14:textId="294F4857" w:rsidP="00BD6BD9" w:rsidR="00BD6BD9" w:rsidRDefault="00BD6BD9">
	<w:pPr>
		<w:pStyle w:val="ListOrdered"/>
		<w:numPr>
			<w:ilvl w:val="1"/>
			<w:numId w:val="2"/>
		</w:numPr>
	</w:pPr>
	<w:r>
		<w:t>List Item Text Here</w:t>
	</w:r>
</w:p>

In numbering.xml, there are num's and abstractNum's. Mine looks like this:

<w:abstractNum w15:restartNumberingAfterBreak="0" w:abstractNumId="0">
	...
</w:abstractNum>
<w:abstractNum w15:restartNumberingAfterBreak="0" w:abstractNumId="1">
	...
</w:abstractNum>
<w:num w:numId="1">
	<w:abstractNumId w:val="0"/>
</w:num>
<w:num w:numId="2">
	<w:abstractNumId w:val="1"/>
</w:num>

The numId value in the paragraph looks like it points to a <w:num>, not an abstractNum.

The helper methods on the paragraph, SetNumberingDefinition and SetNumberingDefinitionByID both essentially operate on a NumberingDefinition which is a CT_AbstractNum. This sets the NumId on the NumPr of the paragraph properties PPr.NumPr.NumId, but they set it equal to the id of the abstractNum that is passed in.

I believe the PPr.NumPr.NumId should point to a CT_Num.NumIdAttrwhich is an entry in doc.Numbering.X().Num. CT_Num then contains the reference to the AbstractNumId that you want to use.

I don't think the function signatures for the paragraph helpers needs to change since any lookups or creations would take place against the abstractNum, but the CT_Num would probably need to be looked up or created based on the abstractNum so that the CT_Num could then be referenced.

I noticed in my XML there are two abstractNums with ids 0 and 1, but the paragraph references use IDs 1 and 2 which match the <w:num> tags. The naming also seems to line up.

Let me know if I have something wrong.

Lost header and footer when I add page break

Description

Hi,
When I add page break the header and footer are gone.
run this example

	for i := 0; i < 5; i++ {
		para = doc.AddParagraph()
		run = para.AddRun()
		run.AddText(lorem)
		
		p1 := doc.AddParagraph()
		p1.Properties().AddSection(wml.ST_SectionMarkNextPage)
	}

I use Office Word 2016 in windows10.
What can i do to keep header?

Please include a reproducible code snippet or document attachment that
demonstrates the issue.

SSL error for baliance.com

Description

Followed https://github.com/baliance/gooxml#installation.

Expected Behavior

The package was fetched and added to my gopath.

Actual Behavior

$ go get baliance.com/gooxml/
                              
package baliance.com/gooxml: unrecognized import path "baliance.com/gooxml" (https fetch: Get https://baliance.com/gooxml?go-get=1: remote error: tls: internal error)

Failure to parse DOCX in "use-template" example (and other simple LibreOffice created DOCX files)

Description

Running the "use-template" example in the repository results in an error parsing the DOCX template included as an example (template.docx). Similarly, creating a new DOCX in LibreOffice with a single line of text also results in a parse error.

Expected Behavior

Running the "use-template" example (or any other script using document.OpenTemplate() or document.Open() should result in a DOCX created in a standard way using an application like LibreOffice being parsed correctly.

Actual Behavior

The following error is displayed:

error opening Windows Word 2016 document: error decoding docProps/core.xml: xml: invalid tag in field Attrs of type gooxml.any: ",any,attr"

To reproduce the problem, run the following example:
https://github.com/baliance/gooxml/blob/master/_examples/document/use-template/main.go

A DOCX exhibiting this behaviour is available here:
https://github.com/baliance/gooxml/blob/master/_examples/document/use-template/template.docx

spreadsheet: sheet ordering sometimes incorrect

Description

I opened an workbook and the sheet titles didn't match the sheet contents. The ordering in workbook.xml was very odd.

Expected Behavior

Sheets are in proper order.

Actual Behavior

Sheet titles didn't match contents.

Support for inline images

I need to insert an inline image. I see convenience functions for anchored images but not for inline images.

I took a stab at adapting the AddDrawingAnchored method on Run, but the image is showing blank.

My stab:

func AddDrawingInline(r document.Run, img common.ImageRef) error {
	ic := wml.NewEG_RunInnerContent()
	r.X().EG_RunInnerContent = append(r.X().EG_RunInnerContent, ic)

	ic.Drawing = wml.NewCT_Drawing()

	inline := wml.NewWdInline()
	ic.Drawing.Inline = append(ic.Drawing.Inline, inline)

	inline.Graphic = dml.NewGraphic()
	inline.Graphic.GraphicData = dml.NewCT_GraphicalObjectData()
	inline.Graphic.GraphicData.UriAttr = "http://schemas.openxmlformats.org/drawingml/2006/picture"
	inline.Extent.CxAttr = int64(float64(img.Size().X*measurement.Pixel72) / measurement.EMU)
	inline.Extent.CyAttr = int64(float64(img.Size().Y*measurement.Pixel72) / measurement.EMU)

	randID := 0x7FFFFFFF & rand.Uint32()
	inline.DocPr.IdAttr = randID
	p := pic.NewPic()
	p.NvPicPr.CNvPr.IdAttr = randID

	// find the reference to the actual image file in the document relationships
	// so we can embed via the relationship ID
	imgID := img.RelID()
	if imgID == "" {
		return errors.New("couldn't find reference to image within document relations")
	}

	inline.Graphic.GraphicData.Any = append(inline.Graphic.GraphicData.Any, p)

	return nil
}

Is this something you would consider adding? For my current use case, I'm trying to rely on the paragraph position and formatting to handle image location and an inline image seems to work best from inside Word.

How can i iterate tables in docx?

Description

How can i iterate tables in docx?

Expected Behavior

I can't find any function support this requirement, such as doc.Tables() ?

Thanks!

Actual Behavior

Please include a reproducible code snippet or document attachment that
demonstrates the issue.

.doc file

Description

HI, I try resolve the .doc file,the system report an error: error opening document: parsing zip: zip: not a valid zip file

Expected Behavior

I hope it's ok. The .docx file is well done. my english is poor,I hope you can help me.

Actual Behavior

Please include a reproducible code snippet or document attachment that
demonstrates the issue.

Some Bugs In Windows

Description

Hi,author.
First of all,I love this lib,and my english is not good.If I used the wrong words, please forgive me.
When I watching your example, I was so exciting.But after I run your example's code.The worry is appear.Open the generate file,the windows tell me, can open this file.

Expected Behavior

Actual Behavior

Please include a reproducible code snippet or document attachment that
demonstrates the issue.

unsupported relationship type

Description

When running _examples/documents/edit-document/main.go , I got these outputs.

Expected Behavior

Yesterday it worked, but today it doesn't.

Actual Behavior

2018/09/06 11:19:02 unsupported relationship type: http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties tgt: docProps/custom.xml
2018/09/06 11:19:02 unsupported relationship type: http://schemas.openxmlformats.org/officeDocument/2006/relationships/glossaryDocument tgt: word/glossary/document.xml
not modifying Sincerely,
not modifying To get started right away, just tap any placeholder
not modifying text (such as this) and start typing.
not modifying Wondering what to include in your cover letter? It’s a good idea to include key points about why you’re a great fit for the company and the best choice for the specific job. Of course, don’t forget to ask for the inter
not modifying view—but keep it brief! A cover letter shouldn’t read like a novel, no matter how great a plot you’ve got.

Please include a reproducible code snippet or document attachment that
demonstrates the issue.

Helper function for paragraph Indentation level

Any interest in adding a convenience function for setting paragraph indentation level?

Its really not too bad using .X(), but thought I'd raise it in case you're interested in which cases people need to use .X.

Here is what I did and seems to work fine:

numpr := wml.NewCT_NumPr()
lvl := wml.NewCT_DecimalNumber()
lvl.ValAttr = int64(listLevel) // listLevel was int
numpr.Ilvl = lvl
numpr.NumId = lvl
para.X().PPr.NumPr = numpr

AddTable the cell's paragraph runs font don't work

Description

when i use doc.AddTable() and .AddRow().AddCell().AddParagraph()
then Run.Properties().SetFontFamily("Courier") it don't work

Expected Behavior

Actual Behavior

Please include a reproducible code snippet or document attachment that
demonstrates the issue.

               table := doc.AddTable()

		// 4 inches wide
		table.Properties().SetWidthPercent(100)
		table.Properties().SetAlignment(wml.ST_JcTableCenter)
		borders := table.Properties().Borders()
		// thin borders
		borders.SetAll(wml.ST_BorderSingle, color.Auto, measurement.Zero)
		//第一行
		row := table.AddRow()
		cell := row.AddCell()
		cell.Properties().SetVerticalMerge(wml.ST_MergeRestart)

		p := cell.AddParagraph()
		p.Properties().SetAlignment(wml.ST_JcCenter)

		r := p.AddRun()

		r.Properties().SetFontFamily("Courier")  //don't work

		r.Properties().SetSize(15)   //work 
		r.Properties().SetColor(color.Red) //work
		r.AddText("账龄")

		cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)

``` @tbaliance 

document table fixed columns width

Hi,
I create a docx file,and add some tables in it. When I open it with Office Word,the table columns' don't show the width I specified in my code.
I find out this is because Office Word has an Automatically resize to fit contents option in every single table.The docx file would show properly if I disable this option in the table's properties in Office Word.
So,I suggust if there is a way to disable such option or fix the columns width as I wish?

how to insert table somewhere?

Description

i want to insert a table after somewhere of Paragraph,how to do?

Expected Behavior

Actual Behavior

Please include a reproducible code snippet or document attachment that
demonstrates the issue.

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.