通常システム開発

請求書を作成する(python)プロンプト

Pythonを用いた見積書作成自動化

与えられた内容に基づいてPythonコードを修正し、自動的にdocx形式の見積書を生成する。

このプロンプトでは、提供されたPythonコードを指定された見積書の内容に合わせてカスタマイズし、Word形式(.docx)で見積書を出力することが求められています。具体的には、文書のマージン設定、タイトル、日付、宛名、会社情報、見積項目のテーブルなどの要素を編集し、要求された形式で見積書を作成し保存する作業が必要です。

プロンプト本文

#実行命令
{pythonコード}は見積書をdocx形式で作成するコードです。
このコードを{見積書の内容}にしたがって適切に書き換え、
Word形式(.docx)で保存し、ファイルを出力してください。

見積書の内容="
見積事項:


見積提出者の会社情報:

"

pythonコード ="
from docx import Document
from docx.shared import Pt, Inches
from docx.enum.text import WD_ALIGN_PARAGRAPH
from datetime import datetime
from docx.oxml import OxmlElement
from docx.oxml.ns import qn

# Create a new Word document
doc = Document()

# Set document margins (1 inch all around)
for section in doc.sections:
section.top_margin = Inches(1)
section.bottom_margin = Inches(1)
section.left_margin = Inches(1)
section.right_margin = Inches(1)

# Title
doc.add_heading('見積書', level=1).alignment = WD_ALIGN_PARAGRAPH.CENTER

# Date
date_paragraph = doc.add_paragraph()
date_paragraph.alignment = WD_ALIGN_PARAGRAPH.RIGHT
date_run = date_paragraph.add_run('発行日: ' + datetime.now().strftime('%Y年%m月%d日'))
date_run.font.size = Pt(11)

# Addressee
client_paragraph = doc.add_paragraph()
client_run = client_paragraph.add_run('適切な会社名を設定してください 御中')
client_run.font.size = Pt(11)
client_run.font.underline = True

# Introductory text
intro_paragraph = doc.add_paragraph()
intro_run = intro_paragraph.add_run('下記の通りお見積り申し上げます。')
intro_run.font.size = Pt(11)

# Company information (right aligned)
company_info = "適切な会社情報を設定してください"
company_paragraph = doc.add_paragraph(company_info)
company_paragraph.alignment = WD_ALIGN_PARAGRAPH.RIGHT

# Add a table for the quotation items
table = doc.add_table(rows=1, cols=4)
table.style = 'Table Grid'

# Table headers with background color
hdr_cells = table.rows[0].cells
hdr_texts = ['品番・品名', '数量', '単価', '金額']
for cell, text in zip(hdr_cells, hdr_texts):
cell.text = text
cell.paragraphs[0].runs[0].font.bold = True
cell.paragraphs[0].runs[0].font.size = Pt(11)
# Set cell background color
shading_elm = OxmlElement('w:shd')
shading_elm.set(qn('w:fill'), 'D3D3D3')
cell._tc.get_or_add_tcPr().append(shading_elm)

# Quotation items
items = [
適切な請求内容を設定してください
]

total = sum(item[3] for item in items)
tax = total * 0.1
grand_total = total + tax

for name, qty, price, amount in items:
row_cells = table.add_row().cells
row_cells[0].text = name
row_cells[1].text = str(qty)
row_cells[2].text = "{:,}".format(price)
row_cells[3].text = "{:,}".format(amount)
for cell in row_cells:
cell.paragraphs[0].runs[0].font.size = Pt(11)

# Add total, tax, and grand total rows
for label, value in [("小計", total), ("消費税(10%)", tax), ("合計金額", grand_total)]:
row_cells = table.add_row().cells
row_cells[2].text = label
row_cells[3].text = "{:,}".format(int(value))
for cell in row_cells[2:]:
cell.paragraphs[0].runs[0].font.size = Pt(11)

# Save the document
file_path = "/mnt/data/見積書_クライアント名.docx"
doc.save(file_path)

file_path
"

#補足:
- 指示の復唱はしないてください。
- 自己評価はしないでください。
- 余計な前置き、結論やまとめは書かないください。
削除キー: