Skip to content

Commit 2dc114b

Browse files
author
洪國樑
committed
Reborn
0 parents  commit 2dc114b

16 files changed

Lines changed: 611 additions & 0 deletions

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
node_modules
3+
/build
4+
/.svelte-kit
5+
/package
6+
.vscode/
7+
wxGlade-1.0.2/
8+
__pycache__/
9+
dist/
10+
*.build/

.gitlab-ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
stages:
2+
- build
3+
- test
4+
- deploy
5+
6+
default:
7+
tags:
8+
- windows
9+
before_script:
10+
- choco install python --yes --version 3.9.6
11+
- $env:Path = "C:\Python39\;C:\Python39\Scripts\;" + $env:Path
12+
- python -m pip install --upgrade pip
13+
14+
build-job:
15+
stage: build
16+
script:
17+
- echo "running scripts in the build job"
18+
19+
test-job1:
20+
stage: test
21+
script:
22+
- echo "running scripts in the test job 1"
23+
24+
test-job2:
25+
stage: test
26+
script:
27+
- echo "running scripts in the test job 2"
28+
29+
deploy-job:
30+
stage: deploy
31+
script:
32+
- echo "running scripts in the deploy job"

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.9.6

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# ExcelMerger
2+
3+
ExcelMerger merges Excel files:
4+
5+
- Merges multiple sheets into one sheet.
6+
- Merges multiple workbooks into one workbook

app/__init__.py

Whitespace-only changes.

app/__main__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import wx
2+
3+
class HelloFrame(wx.Frame):
4+
5+
def __init__(self, *args, **kw):
6+
super(HelloFrame, self).__init__(*args, **kw)
7+
8+
pnl: wx.Panel = wx.Panel(self)
9+
st: wx.StaticText = wx.StaticText(pnl, label="Hello World!")
10+
font: wx.Font = st.GetFont()
11+
font.PointSize += 10
12+
font: wx.Font = font.Bold()
13+
st.SetFont(font)
14+
15+
sizer: wx.BoxSizer = wx.BoxSizer(wx.VERTICAL)
16+
sizer.Add(st, wx.SizerFlags().Border(wx.TOP|wx.LEFT, 25))
17+
pnl.SetSizer(sizer)
18+
19+
if __name__ == '__main__':
20+
app: wx.App = wx.App()
21+
frm: HelloFrame = HelloFrame(None, title='Hello World', size=(400,400))
22+
frm.Show()
23+
app.MainLoop()

app/merger.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from sys import argv
2+
from pathlib import Path
3+
from glob import glob
4+
from collections import OrderedDict
5+
6+
import xlwings as xw
7+
8+
def merge_sheets(wb: xw.Book) -> None:
9+
sheets: list[xw.Sheet] = wb.sheets
10+
main_sheet: xw.Sheet = sheets[0]
11+
main_sheet_last_row: int = main_sheet.used_range.last_cell.row
12+
13+
while len(sheets) > 1:
14+
second_sheet: xw.Sheet = sheets[1]
15+
second_sheet_last_row: int = second_sheet.used_range.last_cell.row
16+
second_sheet_last_column: int = second_sheet.used_range.last_cell.column
17+
second_sheet.range((2, 1), (second_sheet_last_row, second_sheet_last_column)).copy(destination=main_sheet.range((main_sheet_last_row + 1, 1)))
18+
second_sheet.delete()
19+
main_sheet_last_row: int = main_sheet.used_range.last_cell.row
20+
21+
def main() -> None:
22+
23+
argvs: list[str] = argv[1:]
24+
extracted_argvs: list[str] = []
25+
26+
# Check files quantity
27+
if len(argvs) < 1: raise FileNotFoundError
28+
29+
# Extract wildcard to path strings
30+
for path in argvs:
31+
p: Path = Path(path).absolute()
32+
if p.stem == '*':
33+
glob_paths: list[str] = glob(str(p))
34+
for extracted_path in glob_paths:
35+
extracted_argvs.append(extracted_path)
36+
else:
37+
extracted_argvs.append(path)
38+
39+
40+
# Check files existence
41+
for path in extracted_argvs:
42+
if not (Path(path).is_file() and Path(path).exists()): raise FileNotFoundError
43+
44+
# Convert to absolute path
45+
absolute_paths: list[Path] = [Path(path).resolve() for path in extracted_argvs]
46+
# absolute_paths: list[Path] = list(map(lambda path: Path(path).resolve(), extracted_argvs))
47+
48+
# Deduplicate
49+
absolute_paths = list(OrderedDict.fromkeys(absolute_paths))
50+
51+
# print(absolute_paths)
52+
53+
main_file_path: Path = absolute_paths[0]
54+
55+
# Check files suffix
56+
allowed_suffix: tuple[str] = ('.xlsx', '.xls')
57+
for path in absolute_paths:
58+
if not path.suffix.lower() in allowed_suffix: raise FileNotFoundError
59+
60+
with xw.App(add_book=False, visible=False) as app:
61+
main_wb: xw.Book = app.books.open(main_file_path)
62+
main_wb_sheet: xw.Sheet = main_wb.sheets[0]
63+
64+
if len(main_wb.sheets) > 1: merge_sheets(main_wb)
65+
66+
if len(absolute_paths) > 1:
67+
for path in absolute_paths[1:]:
68+
second_wb: xw.Book = app.books.open(path)
69+
if len(second_wb.sheets) > 1: merge_sheets(second_wb)
70+
71+
second_wb_sheet: xw.Sheet = second_wb.sheets[0]
72+
second_wb_sheet.copy(after=main_wb_sheet)
73+
74+
merge_sheets(main_wb)
75+
76+
main_wb_sheet.name = main_wb_sheet.name + '.all'
77+
main_wb.save(main_file_path.with_suffix('.all.xlsx'))
78+
# breakpoint()
79+
80+
if __name__ == '__main__':
81+
main()

app/wxglade_out.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: UTF-8 -*-
3+
#
4+
# generated by wxGlade 1.0.2 on Wed Sep 1 21:24:13 2021
5+
#
6+
7+
import wx
8+
9+
# begin wxGlade: dependencies
10+
# end wxGlade
11+
12+
# begin wxGlade: extracode
13+
# end wxGlade
14+
15+
16+
class MyFrame(wx.Frame):
17+
def __init__(self, *args, **kwds):
18+
# begin wxGlade: MyFrame.__init__
19+
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE | wx.STAY_ON_TOP
20+
wx.Frame.__init__(self, *args, **kwds)
21+
self.SetSize((400, 400))
22+
self.SetTitle("frame")
23+
24+
bitmap_1 = wx.StaticBitmap(self, wx.ID_ANY, wx.Bitmap("C:/Users/leonh/Pictures/20200630_135543-COLLAGE.jpg", wx.BITMAP_TYPE_ANY))
25+
self.Layout()
26+
# end wxGlade
27+
28+
# end of class MyFrame
29+
30+
class MyApp(wx.App):
31+
def OnInit(self):
32+
self.frame = MyFrame(None, wx.ID_ANY, "")
33+
self.SetTopWindow(self.frame)
34+
self.frame.Show()
35+
return True
36+
37+
# end of class MyApp
38+
39+
if __name__ == "__main__":
40+
app = MyApp(0)
41+
app.MainLoop()

build-merger.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import PyInstaller.__main__
2+
3+
PyInstaller.__main__.run([
4+
'./app/merger.py',
5+
'--onefile',
6+
])

merger.spec

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
3+
4+
block_cipher = None
5+
6+
7+
a = Analysis(['app\\merger.py'],
8+
pathex=['C:\\Users\\leonh\\Projects\\excelmerger'],
9+
binaries=[],
10+
datas=[],
11+
hiddenimports=[],
12+
hookspath=[],
13+
hooksconfig={},
14+
runtime_hooks=[],
15+
excludes=[],
16+
win_no_prefer_redirects=False,
17+
win_private_assemblies=False,
18+
cipher=block_cipher,
19+
noarchive=False)
20+
pyz = PYZ(a.pure, a.zipped_data,
21+
cipher=block_cipher)
22+
23+
exe = EXE(pyz,
24+
a.scripts,
25+
a.binaries,
26+
a.zipfiles,
27+
a.datas,
28+
[],
29+
name='merger',
30+
debug=False,
31+
bootloader_ignore_signals=False,
32+
strip=False,
33+
upx=True,
34+
upx_exclude=[],
35+
runtime_tmpdir=None,
36+
console=True,
37+
disable_windowed_traceback=False,
38+
target_arch=None,
39+
codesign_identity=None,
40+
entitlements_file=None )

0 commit comments

Comments
 (0)