Skip to content

Commit

Permalink
Merge branch 'release/v1'
Browse files Browse the repository at this point in the history
  • Loading branch information
cxwithyxy committed Jun 26, 2019
2 parents 3a183ba + 1842a0c commit 5eac9b5
Show file tree
Hide file tree
Showing 25 changed files with 754 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.pyc
aaa/
.vscode/launch.json
venv/
.vscode/
build/
dist/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "mylib/PythonSingleton"]
path = mylib/PythonSingleton
url = https://github.com/cxwithyxy/PythonSingleton.git
28 changes: 28 additions & 0 deletions CLIS/CLISCMDBASE.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#coding=utf-8

import mylib.PythonSingleton.Singleton as SLT

class base(SLT.Singleton):

parser = None
name = None

def __Singleton_Init__(self, parser = None):
self.parser = parser
parser.add_argument("-" + self.name)

def get_argu(self):
argu = vars(self.parser.parse_args())
return argu[self.name]

def is_match(self):
if self.get_argu() == None:
return False
return True

def handle_run(self):
if self.is_match():
self.run()

def run(self):
raise "function \"run\" mast be rewritten"
Empty file added CLIS/__init__.py
Empty file.
43 changes: 43 additions & 0 deletions CLIS/create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#coding=utf-8

import CLIS.CLISCMDBASE
import pathlib
import mylib.path
import requests
import mylib.projIni as PJI
import CLIS.spread as spread


class base(CLIS.CLISCMDBASE.base):

name = "create"

xlsm_download_url = "https://raw.githubusercontent.com/cxwithyxy/Excel_JS_Runtime/master/release/base.xlsm"

def run(self):
self.make_path(self.get_argu())
self.down_xlsm()
self.make_ini_file(self.get_argu())
self.spread_xlsm(self.get_argu())

def make_path(self, proj_name):
mylib.path.mkdir(proj_name)
mylib.path.mkdir(
mylib.path.join_path(proj_name, "src")
)

def down_xlsm(self):
r = requests.get(self.xlsm_download_url, stream=True)
f = open(mylib.path.join_path(self.get_argu(), self.get_argu() + ".xlsm"), "wb")
for chunk in r.iter_content(chunk_size=512):
if chunk:
f.write(chunk)

def make_ini_file(self, proj_name):
PJI.projIni().set_base_path(proj_name + "/")
PJI.projIni().init_config_file(proj_name)

def spread_xlsm(self, proj_name):
spread.base().spread_xlsm(
str(mylib.path.join_path(proj_name, proj_name + ".xlsm"))
)
23 changes: 23 additions & 0 deletions CLIS/pack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#coding=utf-8

import CLIS.CLISCMDBASE
import mylib.xlsmHub as XH
import mylib.projIni as PJI

class base(CLIS.CLISCMDBASE.base):

name = "pack"

def run(self):
argu = self.get_argu()
if argu == "here":
self.pack_xlsm()
return

def pack_xlsm(self):
xlsm_path = PJI.projIni().get_xlsm_full_path()
XH.XlsmHub().set_xlsm_path(xlsm_path)
XH.XlsmHub().open()
XH.XlsmHub().input_js_file()
XH.XlsmHub().flash_sheet()
# XH.XlsmHub().close()
38 changes: 38 additions & 0 deletions CLIS/spread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#coding=utf-8

import CLIS.CLISCMDBASE
import mylib.projIni as PJI
import mylib.xlsmHub as XH
import CLIS.create as create
import mylib.path

class base(CLIS.CLISCMDBASE.base):

name = "spread"

def run(self):
argu = self.get_argu()
if argu == "here":
self.spread_here()
return
self.spread_exist_xlsm(argu)

def spread_exist_xlsm(self, xlsm_path):
if not mylib.path.is_exist(xlsm_path):
print(xlsm_path + u" 文件不存在")
exit()
proj_name = mylib.path.get_file_name_without_suffixs(xlsm_path)
create.base().make_path(proj_name)
mylib.path.move_path(xlsm_path, proj_name + "/" + xlsm_path)
create.base().make_ini_file(proj_name)
create.base().spread_xlsm(proj_name)

def spread_here(self):
xlsm_path = PJI.projIni().get_xlsm_full_path()
self.spread_xlsm(xlsm_path)

def spread_xlsm(self, xlsm_path):
XH.XlsmHub().set_xlsm_path(xlsm_path)
XH.XlsmHub().open()
XH.XlsmHub().output_js_file()
XH.XlsmHub().close()
40 changes: 40 additions & 0 deletions CLIS/watch_pack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#coding=utf-8

import CLIS.CLISCMDBASE
import mylib.xlsmHub as XH
import mylib.projIni as PJI
import win32.win32api as win32api
import win32.win32event as win32event
import mylib.path as mypath
import _thread
import time
import CLIS.pack as CLIS_PACK

class base(CLIS.CLISCMDBASE.base):

name = "watch_pack"
can_pack = False

def run(self):
argu = self.get_argu()
if argu == "here":
_thread.start_new_thread(self.file_change, ())
_thread.start_new_thread(self.wait_for_pack_xlsm, ())
while(True):
time.sleep(5)
return

def file_change(self):
handler = win32api.FindFirstChangeNotification(mypath.abs_path(""), True, 0x00000010)
while(True):
kee = win32api.FindNextChangeNotification(handler)
win32event.WaitForSingleObject(handler, -1)
self.can_pack = True

def wait_for_pack_xlsm(self):
while(True):
if(self.can_pack):
time.sleep(1)
CLIS_PACK.base().pack_xlsm()
self.can_pack = False

20 changes: 20 additions & 0 deletions Excel_JS_Runtime_CLI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#coding=utf-8

import argparse
import queue
import sys
import CLIS.create
import CLIS.spread
import CLIS.pack
import CLIS.watch_pack

parser = argparse.ArgumentParser()
myQueue = queue.Queue()

myQueue.put(CLIS.create.base(parser).handle_run)
myQueue.put(CLIS.spread.base(parser).handle_run)
myQueue.put(CLIS.pack.base(parser).handle_run)
myQueue.put(CLIS.watch_pack.base(parser).handle_run)

while not myQueue.empty():
myQueue.get()()
36 changes: 36 additions & 0 deletions Excel_JS_Runtime_CLI.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- mode: python -*-

block_cipher = None


a = Analysis(['Excel_JS_Runtime_CLI.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='Excel_JS_Runtime_CLI',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=False,
name='Excel_JS_Runtime_CLI')
62 changes: 61 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,62 @@
# Excel_JS_Runtime_CLI
CLI for Excel_JS_Runtime

这是一个命令行工具,便于基于 [Excel_JS_Runtime](https://github.com/cxwithyxy/Excel_JS_Runtime) 的 Excel 的 JavaScript 开发



## 如何安装

1. [下载已经被压缩成7z压缩包的 Excel_JS_Runtime_CLI](https://github.com/cxwithyxy/Excel_JS_Runtime_CLI/releases)
2. 用解压工具(winrar、7z、bandizip等)把这个 Excel_JS_Runtime_CLI.7z 解压到你想要放的地方
3. 然后 设置环境变量 PATH 到你解压出来的 Excel_JS_Runtime_CLI 根目录中



## 如何使用(工作流)

请先打开cmd

1. 构建工作文件夹(见命令说明)
2. cd 进工作文件夹
3. 激活动态打包(见命令说明)
4. 操作(修改、新增、删除)工作文件夹中js文件,Excel_JS_Runtime_CLI 会自动把 [js 文件](doc/how_to_write_js.md)写入 xlsm 中
5. 此时可以对xlsm增加数据,就是 excel 的正常操作,同时你也可以在 [xlsm 中调用](doc/how_to_call_js.md)你写的 js

继续循环第4、5步,直到你满意,就可以 ctrl+s 保存这个xlsm,然后把 xlsm 发给你同事朋友,就算他们没有安装Excel_JS_Runtime_CLI,打开xlsm之后,你编写的js代码也会一样在他们电脑上运行



## 命令

[命令说明](doc/how_to_use.md)



## 开发 Excel_JS_Runtime_CLI

#### 代码下载和开发依赖安装

1. 首先要有python 3.x 和 git
2. git clone 下来
3. cd 到 Excel_JS_Runtime_CLI 根目录
4. 通过 virtualenv 生成 python 环境
5. 切换到 python 环境中
6. 安装依赖 pip install -r requirements.txt -i https:*//mirrors.aliyun.com/pypi/simple/*

#### 运行

```bat
python Excel_JS_Runtime_CLI.py
```

#### 打包

```
pyinstaller Excel_JS_Runtime_CLI.spec
```



## 开发 Excel_JS_Runtime

请移步到 [Excel_JS_Runtime 仓库](https://github.com/cxwithyxy/Excel_JS_Runtime)
29 changes: 29 additions & 0 deletions doc/how_to_call_js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 如何在 Excel 中调用写好的 js

Excel_JS_Runtime_CLI 能够把 js文件 导入 Excel 文件中, 但只有 xlsm 格式的 Excel文件才能运行 js 代码



## 基础调用

把你的js保存好,命名为 a.js

### 调用 js 文件

在 excel 的单元格中输入

```
=runJS("a.js")
```

然后单元格就会显示 a.js 运行后的结果,结果取决于返回值。

#### 传入一些值给 js 文件

在 excel 的单元格中输入

```
=runJS("a.js",3,2)
```

3 和 2 便是传入值了,在 a.js 中可以对着两个值进行处理,并返回处理后的结果。
50 changes: 50 additions & 0 deletions doc/how_to_use.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## 如何使用



#### 新建:构建工作文件夹

```bash
Excel_JS_Runtime_CLI -create myfristproject
```

工作文件会包含以下文件:

1. myfristproject.xlsm
2. src 文件夹(其中包含所有的 javascript 文件)
3. Excel_JS_Runtime_CLI.ini



#### 展开:把 xlsm 文件展开到文件夹

```
Excel_JS_Runtime_CLI -spread here
```

当cd到工作文件夹中时,可以使用该命令 -spread here 把当前文件夹中的xlsm文件的 js 文件保存到 src文件夹中

```
Excel_JS_Runtime_CLI -spread myfirstproject.xlsm
```

把 xlsm 文件 变成 工作文件夹



#### 打包:把 javascript 打包到 xlsm 文件中

```
Excel_JS_Runtime_CLI -pack here
```

当cd到工作文件夹中时,可以使用该命令 -pack here 把当前文件夹中的 src 文件夹中的 js 文件保存到 xlsm 文件



#### 动态打包:每次 javascript 保存时,自动打包进 xlsm 文件中

```
Excel_JS_Runtime_CLI -watch_pack here
```

Loading

0 comments on commit 5eac9b5

Please sign in to comment.