LoginSignup
3
1

More than 1 year has passed since last update.

【Python-docx】超面倒臭い、NDA作成を10秒で処理した話!

Last updated at Posted at 2021-07-15

NDA(Non Disclosure Agreement)作成の話です。
21世紀のビジネスマンには、避けて通れない話題です。
私も、朝から晩まで、潜在顧客とのNDA締結作業をしております。
(営業交渉よりも、NDA締結の方に時間が掛っております。)

このNDAですが、会社ごとにフォーマットが違います。
ただ、ネットに転がっているサンプルとしては、例えば、下記です。
https://legaltemplates.net/form/non-disclosure-agreement/

0715x.jpg

1.何が問題か? なぜ時間が掛るのか?

例えば、「日付」、「Disclosing Party」、「Receiving Party」を記載するのに、
いちいち、ワードを開いて記入しないといけません。
このワードに記入する作業ですが、実際に何通もNDAを書いているととても面倒です。
下記に課題があります。
・同一フォーマットを使うにしても、複数のNDAを書く場合は、どのWordファイルにどの客先名を書いたかが分からなくなる。
・ そもそも、Wordを開いて日付を一枚ずつに書いていくのも、実はかなり面倒。(やってみれば分かりますが、Word編集は、テキストファイル編集程、簡単ではない。)
・ 顧客送付前に、ZIP暗号化しないといけないが、どの顧客ファイルにどの暗号を利用したか?の管理が大変。(大抵、訳が分からなくなる。)

2.改善案

と言う訳で、Python-docxで一瞬で処理します。
下記の様に、NDAとプログラムを一緒に入れておきます。
0715y.jpg

そして、実行。

C:\Users\user_XXX\Desktop\CODE>python sample_replace1.py

はい。これだけです。

コードはこちら。
客先名(Sample LTD)と弊社名(Test Japan co.)は、コード内で記載しております。
勿論、別ファイルにして、そこから、For文で順番に拾って、「代入」して、連続作成する事も可能です。

sample_replace1.py
import docx
import datetime
import docx
from docx.oxml.ns import qn
import os
# pass_gen.py
import string
import secrets
import pyminizip


doc = docx.Document("non-disclosure-agreement.docx")
num = 0

dt=datetime.datetime.now()


x=dt.strftime('%B')

DP="Sample.LTD" #顧客名称
RP="Test Japan co." #弊社名称



for para in doc.paragraphs:
    num = num + 1

    f=para.text
    f=f.replace("ABC",f'{DP}')#雛形に記載のABCを置き換え。
    f=f.replace("XYZ",f'{RP}') #雛形に記載のXYZを置き換え。

    #NDAの締結目的を置き換え。
    f=f.replace("as of ____________________, 20______ (the “Effective Date”) by and between:", f'as {dt.day}th day of {x},{dt.year} ')
    f=f.replace("relationship relating to: __________________________________________(the “Transaction”). ", f'relationship relating to: ____Establishing Sales Strategy____ (the “Transaction”).')

    para.text=f

    para.runs[0].font.size = docx.shared.Pt(9)
    print(num, para.text)

doc.save(f'{DP}_non-disclosure-agreement.docx')

filename=f'{DP}_non-disclosure-agreement.docx'

print(filename)
doc = docx.Document(filename)
font = doc.styles['Normal'].font
font.name = u'Times New Roman' #Times New Romanを指定。何でもOKです。

doc.save(f'{DP}_non-disclosure-agreement.docx')


print(f'this {dt.day}th day of {x},{dt.year}')


def pass_gen(size=12):#暗号化処理
    chars = string.ascii_uppercase + string.ascii_lowercase + string.digits
    # 記号を含める場合
    # chars += '%&$#()'

    return ''.join(secrets.choice(chars) for x in range(size))

fileExt=r".docx"
print([_ for _ in os.listdir() if _.endswith(fileExt)])

x=[_ for _ in os.listdir() if _.endswith(fileExt)]


y=[]
for i in range(len(x)):
#   print(pass_gen(10))
    z=pass_gen(10)
    print(z)
    y.append(z)
    i=i+1

print(y)

for j in range(len(x)):
    pyminizip.compress(x[j], "",  "zipped_"+x[j]+".zip", y[j], 0)
    continue
    j=j+1

f=open('pw_list.txt','w',encoding='UTF-8')
for j in range(len(x)):
#   f.write("Name:"+x[j]+"/"+"pw:"+y[j]+" ")
    f.write("Name: "+x[j]+" / "+"pw: "+y[j]+"\n")
    j=j+1
    f.close

3.
結果はこうです。
0715z.jpg

Sample.LTDは、”sFddqf7HQT”でZIP暗号化されたことが分かる。

<pw_list.txt> の中身

Name: non-disclosure-agreement.docx / pw: 9RxCkFuPvR
Name: Sample.LTD_non-disclosure-agreement.docx / pw: sFddqf7HQT
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1