Skip to content

Commit

Permalink
添加一键注册功能,更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
821869798 committed Sep 6, 2023
1 parent 12ac8ac commit 375081c
Show file tree
Hide file tree
Showing 32 changed files with 808 additions and 313 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
go-version: '1.20'

- run: go build -o bin/${{ github.event.repository.name }}_linux_x64 .
- run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/${{ github.event.repository.name }}_linux_x64 .
- run: CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/${{ github.event.repository.name }}_win_x64.exe
- run: CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build -o bin/${{ github.event.repository.name }}_win_arm64.exe .
- run: CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o bin/${{ github.event.repository.name }}_darwin_x64 .
Expand Down
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,33 @@ excel merge diff tools,excel对比合并工具,把excel转成csv格式,然

### 支持功能

- 支持xlsx、xlsm、xls
- 支持xlsx、xlsm、xls,支持多Sheet
- 支持excel对比 diff
- 支持excel合并 merge
- 支持作为TortoiseSVN和TortoiseGit以及其他能够自定义对比工具的版本控制软件,如果对比的不是excel文件,会直接调用对比工具。

## 使用方法

### windows

双击打开执行文件,允许权限(用于读取和修改注册表)

1. 选择基础的对比工具之后回车确定,如果有安装Beyond Comapre会识别出来

![select_comapre](doc/img/select_comapre.png)

2. 选择需要注册的scm版本工具,空格选择,回车确定,默认全选

![select_register](doc/img/select_register.png)

3. 注册完成,任意键关闭

![complete_register](E:\program\my\go\excel_merge\doc\img\complete_register.png)

4. 就可以正常使用了,比较示例如下,合并同理:

![diff](E:\program\my\go\excel_merge\doc\img\diff.png)

## TODO

- excel合并优化,考虑更多情况,保留更多格式数据
- excel合并保留更多格式数据
58 changes: 54 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package config

import (
"excel_merge/util"
"fmt"
"github.com/821869798/fankit/fanpath"
"github.com/BurntSushi/toml"
"os"
"regexp"
"runtime"
"strings"
)

type RawGlobalConfig struct {
Expand All @@ -13,13 +18,58 @@ type RawGlobalConfig struct {
MergeArgs string `toml:"merge_arg"`
}

var GlobalConfig *RawGlobalConfig
var (
GlobalConfig *RawGlobalConfig
ConfigFilePath string
)

func ParseConfig(configFile string) error {
configFile = util.AbsOrRelExecutePath(configFile)
ConfigFilePath = fanpath.AbsOrRelExecutePath(configFile)
GlobalConfig = new(RawGlobalConfig)
if _, err := toml.DecodeFile(configFile, GlobalConfig); err != nil {
if _, err := toml.DecodeFile(ConfigFilePath, GlobalConfig); err != nil {
return err
}
return nil
}

func WriteConfig(configFile string) error {
if configFile == "" {
configFile = ConfigFilePath
}
f, err := os.Create(configFile)
if err != nil {
return err
}
if err := toml.NewEncoder(f).Encode(GlobalConfig); err != nil {
return err
}
return nil
}

func UpdateCompareTool(newFilePath string) error {
content, err := os.ReadFile(ConfigFilePath)
if err != nil {
return err
}

// 定义正则表达式
pattern := `compare_exe\s*=\s*"(.*?)"`
regex := regexp.MustCompile(pattern)

if runtime.GOOS == "windows" {
// windows系统下,将路径中的反斜杠替换为双反斜杠
newFilePath = strings.ReplaceAll(newFilePath, "\\", "\\\\")
}
// 使用正则表达式替换字符串
newContent := regex.ReplaceAllString(string(content), fmt.Sprintf("compare_exe = \"%s\"", newFilePath))

// 将替换后的内容写入文件
err = os.WriteFile(ConfigFilePath, []byte(newContent), 0644)
if err != nil {
return err
}
return nil

// 选择需要注册的版本软件工具

}
2 changes: 1 addition & 1 deletion convert/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"bufio"
"bytes"
"encoding/csv"
"excel_merge/define"
"fmt"
"github.com/821869798/excel_merge/define"
"io"
"os"
"strings"
Expand Down
2 changes: 1 addition & 1 deletion convert/csv.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package convert

import (
"excel_merge/define"
"github.com/821869798/excel_merge/define"
)

type ConvertCSV struct {
Expand Down
2 changes: 1 addition & 1 deletion convert/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package convert

import (
"errors"
"excel_merge/define"
"fmt"
"github.com/821869798/excel_merge/define"
)

func RunConvert(mode string, excelData *define.ExcelData, filePath string) error {
Expand Down
2 changes: 1 addition & 1 deletion convert/register.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package convert

import (
"excel_merge/define"
"github.com/821869798/excel_merge/define"
)

var convertModes map[string]define.IConvert
Expand Down
10 changes: 10 additions & 0 deletions define/system.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package define

type SystemType int

const (
SystemTypeNone = iota
SystemTypeWindows
SystemTypeLinux
SystemTypeMac
)
17 changes: 9 additions & 8 deletions diff/diff.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package diff

import (
"excel_merge/config"
"excel_merge/convert"
"excel_merge/define"
"excel_merge/source"
"excel_merge/util"
"fmt"
"github.com/821869798/excel_merge/config"
"github.com/821869798/excel_merge/convert"
"github.com/821869798/excel_merge/define"
"github.com/821869798/excel_merge/source"
"github.com/821869798/fankit/fanpath"
"github.com/821869798/fankit/fanstr"
"github.com/gookit/slog"
"os"
"os/exec"
Expand All @@ -28,8 +29,8 @@ func Run(fileList []string) {
defer os.Remove(file2)
}

diffArg := util.FormatFieldName(config.GlobalConfig.DiffArgs, "left", file1, "right", file2)
cmd := exec.Command(util.AbsOrRelExecutePath(config.GlobalConfig.CompareTools), diffArg...)
diffArg := fanstr.FormatFieldName(config.GlobalConfig.DiffArgs, "left", file1, "right", file2)
cmd := exec.Command(fanpath.AbsOrRelExecutePath(config.GlobalConfig.CompareTools), diffArg...)
output, err := cmd.CombinedOutput()
exitCode := cmd.ProcessState.ExitCode()
if nil != err && !define.IsCompareExitCodeSafe(config.GlobalConfig.CompareTools, exitCode) {
Expand Down Expand Up @@ -62,7 +63,7 @@ func convertFile(file string) string {
return ""
}

err = util.CreateDirIfNoExist(filepath.Dir(outputFile))
err = fanpath.CreateDirIfNoExist(filepath.Dir(outputFile))
if err != nil {
slog.Panicf("[diff] %v", err)
return ""
Expand Down
7 changes: 4 additions & 3 deletions diff/diff_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package diff

import (
"excel_merge/util"
"github.com/821869798/fankit/fanpath"
"github.com/821869798/fankit/fanstr"
"os"
"strings"
"testing"
Expand All @@ -25,8 +26,8 @@ func TestFunc1(t *testing.T) {
file := "my file.txt"
err := "file not found"

result := util.FormatFieldName("File {file} had error {error}", "file", file, "error", err)
result := fanstr.FormatFieldName("File {file} had error {error}", "file", file, "error", err)
t.Logf(strings.Join(result, "|"))

t.Logf(util.GetFileNameWithoutExt("qwe.txt"))
t.Logf(fanpath.GetFileNameWithoutExt("qwe.txt"))
}
Binary file added doc/img/complete_register.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/img/diff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/img/select_comapre.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/img/select_register.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 29 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,27 +1,54 @@
module excel_merge
module github.com/821869798/excel_merge

go 1.20

require (
github.com/821869798/fankit v0.0.2
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/BurntSushi/toml v1.3.2
github.com/gookit/slog v0.5.4
github.com/ncruces/zenity v0.10.10
github.com/xuri/excelize/v2 v2.7.1
golang.org/x/sys v0.10.0
)

require (
github.com/akavel/rsrc v0.10.2 // indirect
github.com/dchest/jsmin v0.0.0-20220218165748-59f39799265f // indirect
github.com/getlantern/byteexec v0.0.0-20220903141943-7db46f110fbc // indirect
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 // indirect
github.com/getlantern/elevate v0.0.0-20220903142053-479ab992b264 // indirect
github.com/getlantern/errors v1.0.1 // indirect
github.com/getlantern/filepersist v0.0.0-20210901195658-ed29a1cb0b7c // indirect
github.com/getlantern/golog v0.0.0-20211223150227-d4d95a44d873 // indirect
github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 // indirect
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 // indirect
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/gookit/goutil v0.6.12 // indirect
github.com/gookit/gsr v0.1.0 // indirect
github.com/josephspurrier/goversioninfo v1.4.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/randall77/makefat v0.0.0-20210315173500-7ddd0e42c844 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.3 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 // indirect
github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.1 // indirect
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/image v0.10.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
)
Loading

0 comments on commit 375081c

Please sign in to comment.