docc

package module
v0.0.0-...-7afb402 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 11 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/bax/go-docc"
	"filepath"
)

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

See docc_test.go for other examples.

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

As a binary

go install is available.

go install github.com/bax/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

bax

Documentation

Index

Constants

View Source
const (
	MSOFFICE_PATH = "C:/Program Files (x86)/Microsoft Office"
)

Variables

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

Functions

This section is empty.

Types

type Document

type Document struct {
	XMLName xml.Name `xml:"document"`
	Body    struct {
		P []struct {
			R []struct {
				T struct {
					Text  string `xml:",chardata"`
					Space string `xml:"space,attr"`
				} `xml:"t"`
			} `xml:"r"`
		} `xml:"p"`
	} `xml:"body"`
}

type Paragraph

type Paragraph struct {
	R []struct {
		T struct {
			Text  string `xml:",chardata"`
			Space string `xml:"space,attr"`
		} `xml:"t"`
	} `xml:"r"`
}

type Reader

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

func NewFromReader

func NewFromReader(in io.Reader) (*Reader, error)

NewFromReader generates a Reader struct from io.Reader.

func NewReader

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

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

func (*Reader) Close

func (r *Reader) Close() error

func (*Reader) Read

func (r *Reader) Read() (string, error)

Read reads the .docx file by a paragraph. When no paragraphs are remained to read, io.EOF error is returned.

func (*Reader) ReadAll

func (r *Reader) ReadAll() ([]string, error)

ReadAll reads the whole .docx file.

Jump to

Keyboard shortcuts

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