Files
dsProject/dsRag/mtef-go-3/main.go
2025-08-14 15:45:08 +08:00

96 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"github.com/urfave/cli"
"github.com/zhexiao/mtef-go/docx"
"github.com/zhexiao/mtef-go/eqn"
"os"
"time"
)
func main() {
var filepath, docxDocument, outputFile string
app := cli.NewApp()
app.Name = "Mtef"
app.Usage = "Convert MSDocx Mathtype Ole object to Latex code"
app.Version = "2.0"
app.EnableBashCompletion = true
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "filepath, f",
Usage: "Mathtype Ole object filepath",
Destination: &filepath,
},
cli.StringFlag{
Name: "wordDocx, w",
Usage: "Office word docx documents",
Destination: &docxDocument,
},
cli.StringFlag{
Name: "output, o",
Usage: "Output file path",
Destination: &outputFile,
},
}
app.Action = func(c *cli.Context) error {
var result string
var err error
if filepath != "" {
if _, err = os.Stat(filepath); os.IsNotExist(err) {
fmt.Println("File not exist!!!!")
return nil
}
result = eqn.Convert(filepath)
} else if docxDocument != "" {
if _, err = os.Stat(docxDocument); os.IsNotExist(err) {
fmt.Println("File not exist!!!!")
return nil
}
dw := docx.DocxWord{
Filename: docxDocument,
Target: fmt.Sprintf("/tmp/%v", time.Now().UnixNano()),
}
result, err = dw.ParseDocx()
if err != nil {
return err
}
}
if outputFile != "" {
err = os.WriteFile(outputFile, []byte(result), 0644)
if err != nil {
return fmt.Errorf("failed to write output: %v", err)
}
fmt.Printf("Output saved to %s\n", outputFile)
} else {
fmt.Println(result)
}
return nil
}
err := app.Run(os.Args)
if err != nil {
/**
Error: CreateFile \tmp\1751286455911963600\word\embeddings: The system cannot find the file specified.
2025/06/30 20:27:35 CreateFile \tmp\1751286455911963600\word\embeddings: The system cannot find the file specified.
panic: CreateFile \tmp\1751286455911963600\word\embeddings: The system cannot find the file specified.
goroutine 1 [running]:
log.Panic({0xc0000e3df8?, 0xc000076068?, 0xc0000e3dc8?})
C:/Program Files/Go/src/log/log.go:432 +0x5a
main.main()
D:/dsWork/dsProject/dsRag/mtef-go-3/main.go:96 +0x4b2
*/
// 如果出现这面这样的错误可以认为是需要解析的文件并不包含ole对象提示即可不用抛出错误
// 包含这样的内容就输出没有找到The system cannot find the file specified.
fmt.Println("No embedded objects found.")
}
}