docc

package module
v0.0.0-...-736b354 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2022 License: MIT Imports: 8 Imported by: 0

README

docc

Simple ".docx" converter implemented by Go. Convert ".docx" to plain text.

Note

This repository is an alpha version. Some disruptive changes could be applied.

License

MIT

Features

  • Less dependency.
  • No need for Microsoft Office.
  • Only on limited environment, also ".doc" could be converted.
    • Windows in which MS Office has been installed.

Usage

As a package

This is a simple example to read all paragraphs.

package main

import "github.com/tenkoh/go-docc"

func main(){
    fp := filepath.Clean("./target.docx")
    r, err := NewReader(fp)
    if err != nil {
        panic(err)
    }
    defer r.Close()
    ps, _ := r.ReadAll()
    // do something with ps:[]string
}

If you want read the document by a paragraph, the below example is useful.

package main

import "github.com/tenkoh/go-docc"

func main(){
    fp := filepath.Clean("./target.docx")
    r, err := NewReader(fp)
    if err != nil {
        panic(err)
    }
    defer r.Close()
    
    for {
        p, err := r.Read()
        if err == io.EOF {
            return
        } else if err != nil {
            panic(err)
        }
        // do something with p:string
    }
}

Before compiling, you shall execute go mod tidy or go get github.com/tenkoh/go-doccto get this package.

As a binary

go install is available.

go install github.com/tenkoh/go-docc/cmd/docc@latest

Then, docc command could be used. This is a simple example.

docc target.docx > plain.txt

Contribution

Your contribution is really welcomed!

Author

tenkoh

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotSupportFormat = errors.New("the file is not supported")
)

Functions

This section is empty.

Types

type FileReader

type FileReader struct {
	// contains filtered or unexported fields
}

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func NewReader

func NewReader(docxPath string) (*Reader, error)

NewReader generetes a Reader struct. After reading, the Reader struct shall be Close().

func NewReaderFromBytes

func NewReaderFromBytes(byteValues []byte) (*Reader, error)

NewReader generetes a Reader struct. After reading, the Reader struct shall be Close().

func (*Reader) Close

func (r *Reader) Close() error

func (*Reader) ReadAllFiles

func (r *Reader) ReadAllFiles() (headerValue, contentValue, footerValue, footnotesValue string, err error)

ReadAllFiles reads all header, footer, footnote and content related files in the zip archive and returns it's raw contents

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL