gofastmsbin

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 29 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-fast-msbin

Extracts the binary Office formats (Word .doc, Excel .xls and PowerPoint .ppt, as Office 97 to 2003 wrote them) into the shared go-fast document model, gofastcore.Document. Standard library and go-fast modules only.

Status: v0.2.3. The three formats are read, encrypted files with their password. SECURITY.md says what a hostile file cannot do and lists the limits; IMPLEMENTATION_PLAN.md has what each phase of the work found and measured; CHANGELOG.md what the release holds.

Format Extensions Source.Format State
Excel 97-2003 (BIFF8), Excel 5/95 (BIFF5) .xls, .xlt, .xla xls read
Word 97-2003 .doc, .dot doc read
Word 6/95 .doc doc text, headings, tables, footnotes; no lists, hidden text or tracked changes
PowerPoint 97-2003 .ppt, .pps, .pot ppt read

What is read:

  • Workbooks: one sheet part per sheet, in the workbook's order, named as the sheet is. Cells are given as they are shown, through their number formats, with dates in ISO 8601; the cells of a sheet make table blocks with their place (Loc.Range), found as go-fast-ooxml finds them, so that a workbook saved in either format gives the same tables. Merged cells, comments (note, comment) and, with Options.Spans, hyperlinks are read; with Options.Cells the type of each value and the stored value where the text does not show it in full. Text in a symbol font is translated, run by run. Declared: hidden for a hidden sheet, hidden rows and columns, and a value its format shows as nothing. Sheets are read in parallel; the result does not depend on how many at a time. Beyond cells: formulas as text (Options.Cells), drop-down lists (note, choices), text boxes, pictures (image), charts (a caption and a table with role chart, as go-fast-ooxml gives them), pivot tables (role pivot). The stored part has the defined names and the formulas of macro sheets. Links to other workbooks are input.external_reference. Not read: the records of a pivot cache whose source is gone, and the text boxes of Excel 5/95.
  • Word documents: one body part. Headings, list items with their labels, quotations and code, by go-fast-ooxml's rules; tables with merged cells and header rows; footnotes and endnotes with their numbers; comments; tracked deletions as notes; the results of fields as text and their codes as notes; links; headers and footers once each; bookmarks as anchors; text boxes at their anchors; pictures; document variables in the stored part. With Options.Spans: bold, italic, underline, strike-through, super- and subscript. Declared: hidden for hidden text and hidden shapes.
  • Presentations: one slide part per slide, in the order of the show, with the size of a slide in points and the place of every block on it (Loc.BBox). The title is a heading and the part's name; the body's paragraphs are list items with their level and their bullet or number, as the slide's master and the paragraph say; text boxes are paragraphs; a table is a table; pictures are image blocks; speaker's notes and comments are note blocks. What a master puts on every slide that follows it (its own text and pictures, and the date, the footer and the number of the slide where the presentation says they are shown) is given with each slide, as header and footer. The order is go-fast-ooxml's: the title, then from the top down and from the left across. A Microsoft Graph chart is read with the slide that shows it, from its datasheet, as a chart's table. With Options.Spans, links. Declared: hidden for a slide left out of the show and for a hidden shape. The presentation is what its last edit left of it; slides are read in parallel. A file saved for PowerPoint 95 and 97 both is read from the PowerPoint 97 copy it holds. Not read: sound and video, and tables that are embedded Word or Excel objects (read as embedded files).
  • Equations of the Equation Editor and of MathType, in Word documents and presentations, in UnicodeMath, the linear form go-fast-ooxml writes the equations of the newer formats in: x=(−b±√(b^2−4ac))/(2a), ∑_(i=1)^n▒(x_i), ■(a&b@c&d). Every character of the equation is kept, in order. In a Word document an equation is text of its paragraph, and a paragraph that is an equation and nothing else is a formula block with notation unicodemath; on a slide an equation is a formula block where its picture stands. An equation that is read is not listed among the embedded files; one that cannot be read stays a picture and an embedded file. A character Unicode has nothing for is U+FFFD, with text.unmapped_glyphs. Not read: equations in workbooks and in Word 6/95 documents (embedded files, as before).
  • Properties (Metadata), from the two property-set streams: title, subject, author, keywords, dates, application; comments, template, last author, revision, category, manager, company and the program's version in Extra, under the keys go-fast-ooxml uses; the properties the author defined as custom.<name>. Text is decoded from the code page the stream names.
  • Macros: a VBA project is input.active_content, and the source of each module is a code block in the stored part (stored macro, language vba). Nothing is run.
  • Embedded files (Children, through Options.Child): a file wrapped by the object packager, an Office Open XML package, the content another program stored, and a document held as a storage of the file (a workbook in a Word document), which is written out as a compound file of its own. A linked object is input.external_reference; nothing is fetched. Without Options.Child the files are listed, with their names, kinds and sizes. A presentation keeps its embedded files compressed, and one that is only listed is expanded no further than it takes to say what it is: its size is then the size it states, which for a file whose compressed data breaks off is more than could be expanded.
  • Encrypted files, with Options.Password: XOR obfuscation, the RC4 encryption of Office 97 and RC4 with a CryptoAPI key, for the three formats. The password is checked against what the file keeps for that before anything is decrypted: without one the error wraps ErrPasswordRequired, with a wrong one ErrWrongPassword. A workbook encrypted with the password Excel uses when none was set (a protected workbook with no password to open it) is read without being given one. The document's Metadata.Encrypted is set, whoever's password opened the file, and it has the warning input.decrypted, which names the scheme and says which password that was. These schemes are weak: they are read because files kept in them exist. Each is checked against files other programs wrote, but for the XOR obfuscation of Word documents, of which none was found: there, LibreOffice opens what this project's test writer obfuscates, with the same password. The properties of an encrypted presentation, which are kept encrypted in a stream of their own, are read from it. Not read: the properties of a workbook or Word document that encrypts them in the same way (none was found to check a reader against); such a file has the properties its plain streams hold.
  • Damaged containers: a wrong byte-order mark, a directory whose chain of sectors breaks and lost short streams are read past, with input.repaired.

The format is decided from the file, never from its name: all three are compound files, told apart by the streams they hold. Excel 2 to 4, Word 2 and older and PowerPoint 95 and older are not read; neither is a file of another format under one of these names (RTF, HTML, a zip package). Each is refused with a message that says which it is.

Known limitations

  • The text of earlier saves is not read. A Word document saved with "fast save" and a presentation saved several times can still hold, in bytes the document as it stands no longer points to, text that was later deleted or replaced. The library reads the document as its last save left it and gives none of that text, and nothing in the output says whether a file holds any. This was decided, not overlooked: it will be looked at again if someone needs it.
  • What each format's entry above lists as "Not read". Where the library can tell that a file holds such content it says so with input.unread_content (see below).

Warnings

Every warning has one of the codes all go-fast libraries share (go-fast-core's README, "Warnings"); this library has none of its own. Besides the ones about parts, limits and embedded documents it raises:

Code Here
input.repaired The compound file, or a stream of it, is damaged and was read as far as it could be; a presentation's chain of edits was found by search
input.stream_damaged A stream other than the main one could not be read to its end, and what was read of it is used: the properties (the message names the stream), a VBA project, an embedded object, a chart
input.unread_content Content of a kind that is not read; the message says what and how many: dialog sheets, formulas that cannot be turned back into text, the text boxes of Excel 5/95, the sounds and videos of a presentation, the drop-down lists of a Word form (their entries; what is chosen is text). Not counted: a pivot cache whose source is gone, and form drop-downs in Word 6/95 documents
input.decrypted The file was encrypted and has been decrypted; Metadata.Encrypted is set. The message names the scheme and which password opened it
input.active_content A VBA project, macro sheets, or an action that starts a program; nothing is run
input.external_reference A linked object or file; nothing is fetched
text.unmapped_glyphs Characters that Unicode, the code page or a symbol font has nothing for
text.control_characters_removed Control characters with no meaning as text were removed; the message says how many
text.tracked_changes A Word document has tracked changes
structure.heading_level_clamped Headings deeper than six levels
table.region_split Areas of a sheet too thinly filled to be tables are given as cells

Using it

doc, err := gofastmsbin.ExtractFile(ctx, "report.doc", nil)          // a whole file

f, err := gofastmsbin.Open("ledger.xls", &gofastcore.Options{Password: "sesame"})
defer f.Close()
for _, sheet := range f.Sheets() { ... }                             // listed without being read
for part, err := range f.Parts(ctx) { ... }                          // a sheet or a slide at a time

Extract and ExtractFile give a gofastcore.Document. Open gives a File: its Metadata, its parts one at a time (Parts, Part) or as a Document, its embedded files (Children), and for a workbook its Sheets. Extractor.MaxCells bounds the cells kept from a workbook. Detect says which of the three formats a compound file is (doc, xls, ppt, or nothing) from its directory alone, for a program that has to choose a library for one: an Outlook message is a compound file too. The exported declarations are held to testdata/api.txt by a test.

The command prints JSON (the document, a line for each file when there are several), Markdown or text:

go install github.com/AOShei/go-fast-msbin/cmd/gofastmsbin@latest
gofastmsbin report.doc                    # JSON
gofastmsbin -format markdown slides.ppt
gofastmsbin -password sesame -cells ledger.xls
gofastmsbin -quiet archive/               # every .doc, .xls and .ppt file below a directory

It reads the files embedded in a document too: those of the binary formats with this library, and Office Open XML files (.docx, .xlsx, .pptx) with go-fast-ooxml, told apart by their first bytes. The library itself imports the standard library and go-fast-core only; a program that uses it decides what reads embedded files, through Options.Child.

Layout

Path Content
extract.go, file.go The public entry points: Extract, ExtractFile, Extractor; Open and File, for a part at a time
cmd/gofastmsbin The command: JSON, Markdown or text for files and directories; embedded Office Open XML files read with go-fast-ooxml
internal/xls The Excel reader: records, shared strings, cell formats, sheets, formulas, lists, shapes, charts
internal/doc The Word reader: pieces, properties, styles, lists, tables, notes, fields, text boxes, pictures; Word 6/95
internal/ppt The PowerPoint reader: edits and the persist directory, masters and their text styles, slides, shapes, text, notes, comments
internal/ptg Compiled formulas back to text
internal/officeart, internal/media The drawing layer the three formats share: shapes, their properties, pictures
internal/chart A chart's data as a caption and a table
internal/grid The cells of a sheet into table blocks, as go-fast-ooxml does it
internal/crypt The three schemes of encryption: a password checked, and the keys it gives
internal/oleps Property sets: the document's properties
internal/stored The stored part that the source of VBA modules goes to
internal/embed Embedded objects, handed on as files
internal/mtef Equations of the Equation Editor and MathType (MTEF 2, 3 and 5), written in UnicodeMath
internal/unit, internal/warn What the readers of the three formats share: the stream they read from, a part's result, the wording of bounds and repeated warnings
internal/detect What a file is: format, generation, encryption
go-fast-core's cfb, charset, clean, symbol, label, hidden, vba, numfmt What the go-fast libraries share, imported: compound files (the container of all three formats), code pages, the text conventions of the shared model, symbol fonts, list labels, what is declared about the display of text, the source of VBA modules, number formats
internal/msbintest Test harness: writers of property sets, workbooks, Word documents and presentations, and of the three schemes of encryption; the corpus manifest
testdata/oracle_shared.py, oracle_xls.py, oracle_lo.py, oracle_crypt.py What olefile and olevba read of each corpus file, what xlrd reads of each workbook and what LibreOffice shows of it, for the tests that compare the library with them; and LibreOffice opening, with a password, what the test writer encrypts
testdata/corpus.json, testdata/fetch.py Manifest of 2,528 real files from the test suites of Apache POI, Apache Tika and LibreOffice, from data.gov.uk and from Govdocs1, and the script that downloads them. The files are not in the repository. One file in five is held out: scored, never looked at
bench The baselines of the tools in use today (baseline.md) and the script that measures them

Running the tests

go test ./...
python3 testdata/fetch.py && go test -run TestCorpus -v .   # the corpus, and what it is made of
python -I testdata/oracle_shared.py testdata testdata/corpus/oracle-shared.jsonl   # needs olefile and oletools
go test -run TestSharedAgainstOracles -v .
python -I testdata/oracle_xls.py testdata testdata/corpus/oracle-xls           # needs xlrd
python3 testdata/oracle_lo.py testdata testdata/corpus/oracle-lo-xls          # needs LibreOffice; contained
python3 testdata/oracle_lo.py testdata testdata/corpus/twins-xls --twin       # each workbook as .xlsx
python3 testdata/oracle_lo.py testdata testdata/corpus/twins-doc --twin --format doc
python3 testdata/oracle_lo.py testdata testdata/corpus/oracle-lo-doc --text --format doc
go test -run 'TestDocTwins|TestDocTextAgainstLibreOffice' -v .
python3 testdata/oracle_lo.py testdata testdata/corpus/twins-ppt --twin --format ppt
go test -run 'TestPptTwins|TestEquationTwins' -v .
go test -run 'TestCellsAgainstXlrd|TestShownAgainstLibreOffice|TestTwins|TestFormulasAgainstTwins' -v .
go test -run '^$' -bench Large .                                               # needs bench/baseline.py generate
go test -run '^$' -bench Corpus .                                              # every file of a format, as a batch
go test -run 'TestSoak|TestAllocationBudgets' -v .                             # the whole corpus four ways; what the large files allocate
go test -run TestWorkbookRegions -v .                                          # every workbook read both ways: its stream in memory, a sheet at a time
go run ./cmd/gofastmsbin file.doc
GOFAST_MSBIN_LIBREOFFICE=1 go test -run TestEncryptedWordAgainstLibreOffice . # LibreOffice opens what the test writer encrypts; contained

Tests that need the corpus or the Python comparison tools skip themselves when those are absent.

Licence

MIT. The corpus files keep their own licences, recorded per file in testdata/corpus.json.

Documentation

Overview

Package gofastmsbin extracts the binary Office formats into the shared go-fast document model, gofastcore.Document: Word documents (.doc), Excel workbooks (.xls) and PowerPoint presentations (.ppt) as Office 97 to 2003 wrote them, with their templates and shows, and the workbooks of Excel 5 and 95 and the documents of Word 6 and 95. Their gofastcore.Source.Format is doc, xls and ppt.

Extract and ExtractFile read a whole file into a Document: a body part for a Word document, a sheet part for each sheet of a workbook with its cells as tables, a slide part for each slide of a presentation. Open gives a File, from which the parts are read one at a time (Parts, Part) or as a Document; a workbook's sheets and a presentation's slides are read in parallel, and the result does not depend on how many at a time.

The properties of the file are its Metadata. The source of its VBA modules, its defined names and the like are in a part of kind stored, the last. The files embedded in it are its Children, read by the extractor given as Options.Child.

An encrypted file is opened with Options.Password.

What the file declares of the display of its content (a hidden sheet, row, slide or shape; hidden text) is reported on the block or the part, and nothing is judged: content is given whether or not it is shown.

The format is decided from the file, never from its name: all three are compound files, told apart by the streams they hold. A file of an older generation (Excel 2 to 4, Word 2, PowerPoint 95) or of another format is refused with an error that says what it is.

The library has no dependencies beyond the standard library and go-fast-core. The gofastmsbin command also uses go-fast-ooxml, to read the Office Open XML files embedded in a document.

Index

Examples

Constants

View Source
const (
	// DefaultMaxInputBytes bounds the size of the file.
	DefaultMaxInputBytes = 1 << 30
	// DefaultMaxDecodedBytes bounds the bytes the file is expanded to
	// beyond its own size, over the document and the files embedded in
	// it: macro code and pictures the file keeps compressed, and embedded
	// files written out to be read.
	DefaultMaxDecodedBytes = 2 << 30
	// DefaultMaxCells bounds the cells kept from a workbook, over all its
	// sheets. Each cell kept costs memory in the result whatever the size
	// of the file, so this is what bounds the memory a workbook can ask
	// for.
	DefaultMaxCells = 20_000_000
)

Defaults for the limits of gofastcore.Options.Limits, used where a limit is zero. A negative limit means no limit.

Variables

This section is empty.

Functions

func Detect added in v0.1.3

func Detect(r io.ReaderAt, size int64) string

Detect reports which of the three formats r is, as Extractor.Formats names them: "doc", "xls" or "ppt". It gives "" for input that is not a compound file, for a compound file that is none of the three (an Outlook message, an object another program stored), and for one whose directory cannot be read.

It decides as Extract does, from the names of the streams in the compound file's root storage, and reads the file's header and directory only, never the content of a stream. So it names the format of every compound file Extract takes for one of the three, among them those Extract then refuses: a generation that is not read, an encryption that is not read, a file damaged outside its directory. A file of an old generation that is no compound file (Excel 2 to 4, Word 2) gives "".

It is for a program that reads several kinds of compound file and has to choose a library for one.

func Extract

func Extract(ctx context.Context, r io.ReaderAt, size int64, opts *gofastcore.Options) (*gofastcore.Document, error)

Extract reads a file with default settings. It is (&Extractor{}).Extract.

Example

A whole file as one document.

data := msbintest.BookFile(msbintest.Workbook(nil, msbintest.Sheet{Name: "Prices", Records: [][]byte{
	msbintest.Label(0, 0, 0, "Item"), msbintest.Label(0, 1, 0, "Price"),
	msbintest.Label(1, 0, 0, "Tea"), msbintest.Number(1, 1, 0, 2.5),
}}))
f, err := gofastmsbin.OpenBytes(data, nil)
if err != nil {
	fmt.Println(err)
	return
}
defer f.Close()
doc, err := f.Document(context.Background())
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println(doc.Source.Format, len(doc.Parts), doc.Parts[0].Name)
for _, row := range doc.Parts[0].Blocks[0].Table.Rows {
	fmt.Println(row)
}
Output:
xls 1 Prices
[Item Price]
[Tea 2.5]
Example (Password)

An encrypted file is opened with its password.

stream := msbintest.Workbook(nil, msbintest.Sheet{Name: "Private", Records: [][]byte{msbintest.Label(0, 0, 0, "for your eyes only")}})
data := msbintest.BookFile(msbintest.EncryptWorkbook(stream, msbintest.CryptRC4, "sesame"))
_, err := gofastmsbin.Extract(context.Background(), bytes.NewReader(data), int64(len(data)), nil)
fmt.Println(err)
doc, err := gofastmsbin.Extract(context.Background(), bytes.NewReader(data), int64(len(data)), &gofastcore.Options{Password: "sesame"})
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println(doc.Parts[0].Blocks[0].Table.Rows[0][0])
fmt.Println(doc.Warnings[0].Code)
Output:
gofastmsbin: Excel 97-2003 (BIFF8) file, encrypted (RC4): no password given: gofastcore: password required
for your eyes only
input.decrypted

func ExtractFile

func ExtractFile(ctx context.Context, path string, opts *gofastcore.Options) (*gofastcore.Document, error)

ExtractFile opens the named file and extracts it with default settings.

Types

type Extractor

type Extractor struct {
	// MaxCells bounds the cells kept from a workbook, over all its
	// sheets. A sheet that reaches it is cut off there, with a
	// limit.exceeded warning. Zero means DefaultMaxCells; negative means
	// no limit.
	MaxCells int64
}

Extractor extracts Word, Excel and PowerPoint files in the binary formats of Office 97 to 2003. The zero value is ready to use and safe for concurrent use. Its fields are the settings only this library has; everything else is in gofastcore.Options.

func (*Extractor) Extract

func (e *Extractor) Extract(ctx context.Context, r io.ReaderAt, size int64, opts *gofastcore.Options) (*gofastcore.Document, error)

Extract reads size bytes from r and returns the document.

The format is decided from the file itself, never from a name: a Word document, a workbook or a presentation of the binary formats.

An encrypted file is opened with Options.Password; a workbook encrypted with the password Excel uses when none was set is opened without one. The document then has Metadata.Encrypted set and the warning input.decrypted.

An error wraps one of the gofastcore errors:

  • ErrLimitExceeded: the input is larger than Limits.MaxInputBytes, or its compound file has more entries than are read.
  • ErrMalformed: a compound file too damaged to say what it holds.
  • ErrUnsupported: a file that is none of the three formats; one of a generation that is not read (Excel 2 to 4, Word 2, PowerPoint 95 and older); a file encrypted in a way that is not read.
  • ErrPasswordRequired, ErrWrongPassword: the file is encrypted, and no password was given, or the one given does not open it.
  • ErrNoPartsSelected: Options.Parts selects none of the document's parts.

It is OpenReaderAt followed by Document.

func (*Extractor) ExtractFile

func (e *Extractor) ExtractFile(ctx context.Context, path string, opts *gofastcore.Options) (*gofastcore.Document, error)

ExtractFile opens the named file and extracts it. The file's base name is recorded as the source name unless opts.Name is set.

func (*Extractor) Formats

func (e *Extractor) Formats() []string

Formats lists the formats this library extracts, as they appear in gofastcore.Source.Format.

func (*Extractor) Open

func (e *Extractor) Open(path string, opts *gofastcore.Options) (*File, error)

Open opens the named file. The file's base name is recorded as the source name unless opts.Name is set. Close the File when done with it.

func (*Extractor) OpenBytes

func (e *Extractor) OpenBytes(data []byte, opts *gofastcore.Options) (*File, error)

OpenBytes opens a file held in memory. The bytes must not change while the File is in use.

func (*Extractor) OpenReaderAt

func (e *Extractor) OpenReaderAt(r io.ReaderAt, size int64, opts *gofastcore.Options) (*File, error)

OpenReaderAt opens a file of the given size read through r, which must stay readable until the File is closed. The errors are those of Extract.

type File

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

File is a Word, Excel or PowerPoint file opened for reading a part at a time: a Word document's one body, a workbook's sheets, a presentation's slides. Opening a file identifies it and reads its properties and what its parts share; the parts are read when they are asked for, so a caller that handles one part and lets it go holds little at a time however large the file is.

The parts are the same as those in the document that Extract returns, each complete: its warnings are on it, and what the file declares about the display of its text is set (Part.Finish has been called).

A File is safe for concurrent use. A limit of Options.Limits counts over one pass: one call of Document, Part or Children, or one run through Parts. Passes that run at the same time share it.

func Open

func Open(path string, opts *gofastcore.Options) (*File, error)

Open opens the named file with default settings. It is (&Extractor{}).Open.

func OpenBytes

func OpenBytes(data []byte, opts *gofastcore.Options) (*File, error)

OpenBytes opens a file held in memory with default settings.

func OpenReaderAt

func OpenReaderAt(r io.ReaderAt, size int64, opts *gofastcore.Options) (*File, error)

OpenReaderAt opens a file of the given size read through r, with default settings.

func (*File) Children

func (f *File) Children(ctx context.Context) ([]*gofastcore.Document, error)

Children extracts the files embedded in the document (a workbook in a Word document, a document in a document) through Options.Child, and returns them as in gofastcore.Document.Children. With no Options.Child each is listed, not extracted. They have what the parts read last left of the text the document may hold (Limits.MaxTextBytes), as in Document.

func (*File) Close

func (f *File) Close() error

Close closes the file if Open opened it. The File must not be used afterwards.

func (*File) Document

func (f *File) Document(ctx context.Context) (*gofastcore.Document, error)

Document reads the parts Options.Parts selects and returns the document, the same one Extract returns.

func (*File) Format

func (f *File) Format() string

Format returns the kind of file: "doc", "xls" or "ppt". A template is the format it is a template of.

func (*File) Metadata

func (f *File) Metadata() gofastcore.Metadata

Metadata returns the document's properties.

func (*File) NumParts

func (f *File) NumParts() int

NumParts returns the number of parts: 1 for a Word document, the number of sheets of a workbook, the number of slides of a presentation. A workbook or presentation with none has one part, which says so. A document that stores what it shows nowhere (defined names, macro code) has one more, last, of kind gofastcore.PartStored; it comes with the whole document, not with a range of parts.

func (*File) Part

func (f *File) Part(ctx context.Context, number int) (gofastcore.Part, error)

Part reads the part with the given number, from 1, whether or not Options.Parts selects it.

func (*File) Parts

func (f *File) Parts(ctx context.Context) iter.Seq2[gofastcore.Part, error]

Parts returns an iterator over the parts Options.Parts selects, in order. Each part is read when the loop reaches it, a few ahead with more than one worker, and is the caller's to keep or let go. The bytes of a picture that several parts show (Options.Images) come with the first of them.

The iterator yields an error, with an empty part, and stops: when no part is selected (gofastcore.ErrNoPartsSelected), when ctx is cancelled, or when the file can no longer be read. A part that is damaged or cut short by a limit is not an error: it is yielded with a warning that says so.

What the parts say about the document as a whole is in Warnings and Children once they have been read.

Example

A part at a time: the sheets of a workbook or the slides of a presentation are read as they are asked for, and nothing is kept of the ones that were read.

var sheets []msbintest.Sheet
for _, name := range []string{"January", "February", "March"} {
	sheets = append(sheets, msbintest.Sheet{Name: name, Records: [][]byte{msbintest.Label(0, 0, 0, "Sales in "+name)}})
}
f, err := gofastmsbin.OpenBytes(msbintest.BookFile(msbintest.Workbook(nil, sheets...)), &gofastcore.Options{Workers: 1})
if err != nil {
	fmt.Println(err)
	return
}
defer f.Close()
for _, sheet := range f.Sheets() {
	fmt.Println(sheet.Number, sheet.Name)
}
for part, err := range f.Parts(context.Background()) {
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(part.Number, part.Blocks[0].Table.Rows[0][0])
}
Output:
1 January
2 February
3 March
1 Sales in January
2 Sales in February
3 Sales in March

func (*File) Sheets

func (f *File) Sheets() []Sheet

Sheets lists the sheets of a workbook in order, without reading them. It is empty for other formats.

func (*File) Source

func (f *File) Source() gofastcore.Source

Source returns what is known of where the document came from, as in gofastcore.Document.Source.

func (*File) Warnings

func (f *File) Warnings() []gofastcore.Warning

Warnings returns the warnings about the document as a whole, as in gofastcore.Document.Warnings: those known when the file was opened, and those that the parts read so far give rise to (content of a kind that is not read, damaged supporting parts, references to things outside the file). It is complete once every part has been read.

type Sheet

type Sheet struct {
	// Number is the sheet's part number, from 1.
	Number int
	// Name is the sheet's name.
	Name string
	// Hidden says the workbook marks the sheet hidden.
	Hidden bool
}

Sheet is a sheet of a workbook as the workbook lists it.

Directories

Path Synopsis
cmd
gofastmsbin command
Command gofastmsbin extracts Word, Excel and PowerPoint files in the binary formats of Office 97 to 2003 (.doc, .xls, .ppt) into the shared document model of the go-fast libraries and prints them as JSON, Markdown or plain text.
Command gofastmsbin extracts Word, Excel and PowerPoint files in the binary formats of Office 97 to 2003 (.doc, .xls, .ppt) into the shared document model of the go-fast libraries and prints them as JSON, Markdown or plain text.
internal
chart
Package chart turns the data of a chart into blocks, as go-fast-ooxml does: the names of its series, its categories and its values, given as a table, with the chart's title as a caption before it and its type and the titles of its axes as attributes (gofastcore.RoleChart).
Package chart turns the data of a chart into blocks, as go-fast-ooxml does: the names of its series, its categories and its values, given as a table, with the chart's title as a caption before it and its type and the titles of its axes as attributes (gofastcore.RoleChart).
crypt
Package crypt opens the encryption of the binary Office formats ([MS-OFFCRYPTO] 2.3): XOR obfuscation, the RC4 encryption of Office 97, and RC4 with a key made by the CryptoAPI.
Package crypt opens the encryption of the binary Office formats ([MS-OFFCRYPTO] 2.3): XOR obfuscation, the RC4 encryption of Office 97, and RC4 with a key made by the CryptoAPI.
detect
Package detect says what a file is: which of the three formats, written by which generation of the program, and whether it is encrypted.
Package detect says what a file is: which of the three formats, written by which generation of the program, and whether it is encrypted.
doc
Package doc reads Word documents in the binary format of Word 97 to 2003 ([MS-DOC]): the WordDocument stream, which holds the text and the pages of properties, and the table stream beside it, which holds everything that says what the text is.
Package doc reads Word documents in the binary format of Word 97 to 2003 ([MS-DOC]): the WordDocument stream, which holds the text and the pages of properties, and the table stream beside it, which holds everything that says what the text is.
embed
Package embed finds the objects a file of the three formats embeds as storages of its compound file, and hands each on as a file of its own.
Package embed finds the objects a file of the three formats embeds as storages of its compound file, and hands each on as a file of its own.
grid
Package grid turns the cells of a sheet into table blocks.
Package grid turns the cells of a sheet into table blocks.
media
Package media makes the image blocks of pictures the three formats keep through the drawing layer.
Package media makes the image blocks of pictures the three formats keep through the drawing layer.
mtef
Package mtef reads the equations of the Equation Editor and of MathType, which the binary Office formats keep as embedded objects: a stream "Equation Native" that holds the equation in MTEF, a sequence of records for lines, characters, templates (a fraction, a root, a sum), piles and matrices.
Package mtef reads the equations of the Equation Editor and of MathType, which the binary Office formats keep as embedded objects: a stream "Equation Native" that holds the equation in MTEF, a sequence of records for lines, characters, templates (a fraction, a root, a sum), piles and matrices.
officeart
Package officeart reads the drawing layer that Word, Excel and PowerPoint files of the binary formats share ([MS-ODRAW]): shapes with their properties and where they are anchored, and the pictures kept for them.
Package officeart reads the drawing layer that Word, Excel and PowerPoint files of the binary formats share ([MS-ODRAW]): shapes with their properties and where they are anchored, and the pictures kept for them.
oleps
Package oleps reads property sets ([MS-OLEPS]): the streams "\x05SummaryInformation" and "\x05DocumentSummaryInformation", in which a Word, Excel or PowerPoint file keeps its title, its author, its dates and the properties its author defined.
Package oleps reads property sets ([MS-OLEPS]): the streams "\x05SummaryInformation" and "\x05DocumentSummaryInformation", in which a Word, Excel or PowerPoint file keeps its title, its author, its dates and the properties its author defined.
ppt
Package ppt reads PowerPoint presentations in the binary format of PowerPoint 97 to 2003 ([MS-PPT]): the PowerPoint Document stream, a tree of records, of which the presentation as it now stands is found through the edits the Current User stream leads to.
Package ppt reads PowerPoint presentations in the binary format of PowerPoint 97 to 2003 ([MS-PPT]): the PowerPoint Document stream, a tree of records, of which the presentation as it now stands is found through the edits the Current User stream leads to.
ptg
stored
Package stored reads what a file of any of the three formats keeps for the file as a whole and shows on no page: the code of its VBA projects.
Package stored reads what a file of any of the three formats keeps for the file as a whole and shows on no page: the code of its VBA projects.
unit
Package unit is what the readers of the three formats have in common when a document is read a part at a time: a Word document's one body, a workbook's sheets, a presentation's slides.
Package unit is what the readers of the three formats have in common when a document is read a part at a time: a Word document's one body, a workbook's sheets, a presentation's slides.
warn
Package warn holds what the readers share in saying what a fixed bound left out, and the messages of warnings several of them raise.
Package warn holds what the readers share in saying what a fixed bound left out, and the messages of warnings several of them raise.
xls
Package xls reads Excel workbooks in the binary format of Excel 97 to 2003 (BIFF8, [MS-XLS]) and of Excel 5 and 95 (BIFF5): the Workbook stream, or the Book stream of the older format, a run of records.
Package xls reads Excel workbooks in the binary format of Excel 97 to 2003 (BIFF8, [MS-XLS]) and of Excel 5 and 95 (BIFF5): the Workbook stream, or the Book stream of the older format, a run of records.

Jump to

Keyboard shortcuts

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