mirror of
https://github.com/unidoc/unioffice.git
synced 2025-05-02 22:17:07 +08:00
meta: add a command to be used for testing
It opens, reads and writes a file out. This is to be used for testing random docx/xlsx files to ensure we don't break them.
This commit is contained in:
parent
483e69c1f6
commit
c6cecf13be
52
cmd/test-open-write/main.go
Normal file
52
cmd/test-open-write/main.go
Normal file
@ -0,0 +1,52 @@
|
||||
// Copyright 2017 Baliance. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by the terms of the Affero GNU General
|
||||
// Public License version 3.0 as published by the Free Software Foundation and
|
||||
// appearing in the file LICENSE included in the packaging of this file. A
|
||||
// commercial license can be purchased by contacting sales@baliance.com.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"baliance.com/gooxml/document"
|
||||
"baliance.com/gooxml/spreadsheet"
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if flag.NArg() == 0 {
|
||||
fmt.Println("usage: test-open-write filename.docx/.xlsx")
|
||||
os.Exit(1)
|
||||
}
|
||||
fn := flag.Arg(0)
|
||||
if strings.HasSuffix(strings.ToLower(fn), ".xlsx") {
|
||||
xlsx, err := spreadsheet.Open(fn)
|
||||
if err != nil {
|
||||
log.Fatalf("error opening %s: %s", fn, err)
|
||||
}
|
||||
if err := xlsx.Validate(); err != nil {
|
||||
log.Printf("validation error: %s", err)
|
||||
}
|
||||
if err := xlsx.SaveToFile("converted.xlsx"); err != nil {
|
||||
log.Fatalf("error saving: %s", err)
|
||||
}
|
||||
} else if strings.HasSuffix(strings.ToLower(fn), ".docx") {
|
||||
docx, err := document.Open(fn)
|
||||
if err != nil {
|
||||
log.Fatalf("error opening %s: %s", fn, err)
|
||||
}
|
||||
if err := docx.Validate(); err != nil {
|
||||
log.Printf("validation error: %s", err)
|
||||
}
|
||||
if err := docx.SaveToFile("converted.docx"); err != nil {
|
||||
log.Fatalf("error saving: %s", err)
|
||||
}
|
||||
}
|
||||
fmt.Println("reading", fn)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user