本次搭建使用Python实现,零开发基础也能按步骤完成,所有资源都提供直接可访问的下载地址,无需额外搜索。
下载Python 3.10稳定版本,安装包地址:https://www.python.org/downloads/release/python-31011/,下载对应你系统的安装包,安装过程中必须勾选「Add Python to PATH」选项,否则后续运行会报错,完成安装后打开命令提示符,输入python --version,输出版本号即说明安装成功。
打开命令提示符,直接复制执行以下命令,完成所有依赖安装:
``` pip install flask pandas python-docx openpyxl pytesseract pillow ```
如果需要OCR识别扫描件功能,额外安装Tesseract OCR工具,安装包地址:https://github.com/tesseract-ocr/tesseract/releases/download/5.3.3/tesseract-ocr-w64-setup-5.3.3.20231005.exe,安装完成后需要将默认安装目录C:\Program Files\Tesseract-OCR添加到系统环境变量PATH中。

在电脑任意位置新建名为archives的根文件夹,在根文件夹内手动新建以下文件和文件夹,结构如下:
archives/ 项目根目录archives/templates/ 存放前端操作页面archives/data/ 存放业务数据archives/data/input/ 待处理档案目录archives/data/output/ 已归档档案目录archives/data/temp/ 临时缓存目录archives/app.py 程序主文件archives/templates/index.html 前端操作页面文件注意:input、output、temp三个子文件夹必须手动创建,否则程序运行会报错。
打开app.py文件,直接复制粘贴以下完整代码,无需修改即可使用:
```
from flask import Flask, render_template, request
import pandas as pd
import os
import pytesseract
from PIL import Image
app = Flask(__name__)
app.config['UPLOAD_FOLDER_INPUT'] = './data/input'
app.config['UPLOAD_FOLDER_OUTPUT'] = './data/output'
app.config['UPLOAD_FOLDER_TEMP'] = './data/temp'
限制上传文件大小16M,可自行修改数值调整大小
app.config['MAX_CONTENT_LENGTH'] = 16 1024 1024
初始化档案索引表,首次运行自动生成
if not os.path.exists('./data/archive_index.xlsx'):
df = pd.DataFrame(columns=['档案编号', '档案名称', '年度', '状态', '归档时间', '存储路径'])
df.to_excel('./data/archive_index.xlsx', index=False)
@app.route('/')
def index():
读取所有档案信息渲染页面
df = pd.read_excel('./data/archive_index.xlsx')
archives = df.to_dict('records')
return render_template('index.html', archives=archives)
@app.route('/add', methods=['POST'])
def add_archive():
新增档案信息
archive_no = request.form.get('archive_no')
archive_name = request.form.get('archive_name')
year = request.form.get('year')
df = pd.read_excel('./data/archive_index.xlsx')
new_row = pd.DataFrame([[archive_no, archive_name, year, '待处理', '', f'data/input/{archive_no}']],
columns=['档案编号', '档案名称', '年度', '状态', '归档时间', '存储路径'])
df = pd.concat([df, new_row], ignore_index=True)
df.to_excel('./data/archive_index.xlsx', index=False)
return 'success'
@app.route('/ocr', methods=['POST'])
def do_ocr():
OCR识别扫描图像文字
file = request.files.get('image')
img = Image.open(file)
text = pytesseract.image_to_string(img, lang='chi_sim')
return text
@app.route('/finish', methods=['POST'])
def finish_archive():
质检通过后归档档案
archive_no = request.form.get('archive_no')
df = pd.read_excel('./data/archive_index.xlsx')
from datetime import datetime
df.loc[df['档案编号'] == archive_no, '状态'] = '已归档'
df.loc[df['档案编号'] == archive_no, '归档时间'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
df.loc[df['档案编号'] == archive_no, '存储路径'] = f'data/output/{archive_no}'
df.to_excel('./data/archive_index.xlsx', index=False)
return 'success'
if __name__ == '__main__':
app.run(debug=True, host='127.0.0.1', port=5000)
```
打开templates文件夹下的index.html文件,复制粘贴以下完整代码:
```档案数字化流程管理 档案数字化数据流程管理```新增待处理档案
现有档案列表
{% for archive in archives %} 档案编号 档案名称 年度 状态 操作 {% endfor %} {{ archive['档案编号'] }} {{ archive['档案名称'] }} {{ archive['年度'] }} {{ archive['状态'] }} {% if archive['状态'] == '待处理' %} {% else %} {{ archive['归档时间'] }} {% endif %}
cd 你的项目根目录完整路径,例如项目存放在D盘根目录的archives文件夹,就输入cd D:\archivespython app.py,看到控制台输出 Running on http://127.0.0.1:5000即说明启动成功http://127.0.0.1:5000即可进入操作界面操作流程完全符合标准档案数字化规范:
python -m pip install 缺失的模块名重新安装依赖即可port=5001,重启程序即可
档案整理行业认证,这玩意儿到底是不是你的职场“硬通货”?