SAP UTF-8 文件输出方式 及 GUI_DOWNLOAD 参数说明 .

本文深入探讨了在SAP环境中使用GUI_DOWNLOAD功能模块的方法,包括文件类型、追加、字段分隔符、换行符、数据模式、代码页、替换字符、写入BOM等参数的详细解释和应用实例。

Function Module: GUI_DOWNLOAD

注: 如需要导出 UTF-8 的文件,可使用以下格式即可。

 

call function 'GUI_DOWNLOAD'
    exporting
     filename                        = p_file
     FILETYPE                        = 'DAT'
     CODEPAGE                        = '4110'
     WRITE_BOM                       = 'X'

 

如是使用open dataset 方式输出 UTF-8,则可用认下方式。

 

open dataset gv_file for output in text mode encoding UTF-8 WITH BYTE-ORDER MARK WITH SMART LINEFEED


 

对FUNCTION: GUI_DOWNLOAD中某些参数的用法.

  call function 'GUI_DOWNLOAD'
    exporting
*     BIN_FILESIZE                    =
*     filename                        = p_file
*     FILETYPE                        = 'DAT'
*     APPEND                          = ' '
*     write_field_separator           = 'X'
*     HEADER                          = '00'
*     TRUNC_TRAILING_BLANKS           = ' '
*     WRITE_LF                        = 'X'
*     COL_SELECT                      = ' '
*     COL_SELECT_MASK                 = ' '
*     DAT_MODE                        = ' '
*     CONFIRM_OVERWRITE               = ' '
*     NO_AUTH_CHECK                   = ' '
*     CODEPAGE                        = '4103'
*     IGNORE_CERR                     = ABAP_TRUE
*     REPLACEMENT                     = '#'
*     WRITE_BOM                       = 'X'
*     TRUNC_TRAILING_BLANKS_EOL       = 'X'
*     WK1_N_FORMAT                    = ' '
*     WK1_N_SIZE                      = ' '
*     WK1_T_FORMAT                    = ' '
*     WK1_T_SIZE                      = ' '
*     WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE
*     SHOW_TRANSFER_STATUS            = ABAP_TRUE
*   IMPORTING
*     FILELENGTH                      =
*   tables
*     data_tab                        = it_kna1
*     fieldnames                      = it_filedname[]
*    EXCEPTIONS
*     FILE_WRITE_ERROR                = 1
*     NO_BATCH                        = 2
*     GUI_REFUSE_FILETRANSFER         = 3
*     INVALID_TYPE                    = 4
*     NO_AUTHORITY                    = 5
*     UNKNOWN_ERROR                   = 6
*     HEADER_NOT_ALLOWED              = 7
*     SEPARATOR_NOT_ALLOWED           = 8
*     FILESIZE_NOT_ALLOWED            = 9
*     HEADER_TOO_LONG                 = 10
*     DP_ERROR_CREATE                 = 11
*     DP_ERROR_SEND                   = 12
*     DP_ERROR_WRITE                  = 13
*     UNKNOWN_DP_ERROR                = 14
*     ACCESS_DENIED                   = 15
*     DP_OUT_OF_MEMORY                = 16
*     DISK_FULL                       = 17
*     DP_TIMEOUT                      = 18
*     FILE_NOT_FOUND                  = 19
*     DATAPROVIDER_EXCEPTION          = 20
*     CONTROL_FLUSH_ERROR             = 21
*     OTHERS                          = 22.

1. FILETYPE: GUI_DOWNLOAD FILETYPE

'ASC' :

ASCII format. The table is transferred as text. Conversion exits are performed. The output format additionally depends on the parameters CODEPAGE, TRUNC_TRAILING_BLANKS, and TRUNC_TRAILING_BLANKS_EOL.

 

'IBM' :

ASCII format with IBM codepage conversion (DOS). This format corresponds to the 'ASC' format when using target codepage 1103. This codepage is frequently used for data exchange via floppy disk.

 

'DAT' :

Column-by-column transfer. With this format, the data is transferred as text as with ASC. However, no conversion exits are performed and the columns are separated by tab characters. This format generates files than can be uploaded again using gui_upload or ws_upload.

 

'DBF' :

Data is downloaded in dBase format. Since in this format the data types of the individual columns are stored as well, you can often avoid import problems, for example, into Microsoft Excel, especially when interpreting numeric values.

 

'WK1' :

Data is downloaded in Lotus 1-2-3 format.

 

'BIN' :

Binary format. Data is transferred binarily. There is no formatting and no codepage conversion. The data is interpreted row by row; it is not formatted by columns. Specify the data length in parameter BIN_FILESIZE. The table should consist of a column of type X, because especially in Unicode systems, the conversion of structured into binary data causes errors.

 

Default

'ASC'


2. APPEND
GUI_DOWNLOAD APPEND

By default, existing local files are overwritten by new versions. By setting APPEND to 'X', the downloaded data is appended to an existing file. If the file does not yet exist, it is created.

Value range

'X'   = Data is appended.

SPACE = Data is overwritten if the file already exists.

Default

SPACE


3. WRITE_FIELD_SEPARATOR
GUI_DOWNLOAD WRITE_FIELD_SEPARATOR

In the downloaded file, the columns are separated by tab characters (cl_abap_char_utilities=>horizontal_tab). You should use this setting if you want to upload the data from the file at a later time, because this is the only way of identifying individual columns.

The parameter makes sense only for the FILETYPE values ASC, DAT and IBM; for DAT it is set implicitly.

Value range

'X'   : Write separator.

SPACE : Do not write separator.

Default

SPACE


4. WRITE_LF
GUI_DOWNLOAD WRITE_LF

If this parameter is set, at the end of each row a row separator is inserted by CL_ABAP_CHAR_UTILITIES=>CR_LF. This parameter makes sense only for FILETYPE 'ASC', 'DAT' and 'IBM'. If this parameter is not set, blanks at the end of a row are not removed.

Value range

'X': Row separator is inserted.

SPACE: Row separator is not inserted.

Default

'X'


5. DAT_MODE
GUI_DOWNLOAD DAT_MODE

If parameter DAT_MODE is set, the file is stored in 'DAT' format. No conversion exits are performed. Number and date fields are stored in a standard format which makes it possible, to later import the file using gui_upload.

Value range

'X': DAT_MODE is switched on.

SPACE: DAT_MODE is not switched on.

Default

SPACE


6. CODEPAGE
GUI_DOWNLOAD CODEPAGE

Use parameter CODEPAGE to specify the desired target codepage. If this parameter is not set, the codepage of the SAP GUI is used as the target codepage.

Value range

4-digit number of the SAP codepage. The function module SCP_CODEPAGE_BY_EXTERNAL_NAME returns the SAP codepage number for an external character set name, for example, "iso-8859-1". The function module NLS_GET_FRONTEND_CP returns the appropriate non-Unicode frontend codepage for a language.

You can determine the desired codepage interactively, if the parameter with_encoding of method file_save_dialog is set by cl_gui_frontend_services.

SPACE: Codepage of the SAP GUI

Default

SPACE


7. REPLACEMENT
GUI_DOWNLOAD REPLACEMENT

Specifies the replacement character to be used when during a character set conversion a character cannot be converted.

Value range

An individual character.

Default

'#'


8. WRITE_BOM
GUI_DOWNLOAD WRITE_BOM

If the data is written in a Unicode codepage, at the beginning of the file the respective byte order mark (BOM) is inserted.

Unicode - Little Endian Codepage 4103, binary values 'FFFE'

Unicode - Big Endian Codepage 4102, binary values 'FEFF'

UTF-8 Codepage 4110, binary values 'EFBBBF'

Note: Microsoft Excel only supports Unicode data if they have been written in the format Unicode - Little Endian.

Value range

'X': Write BOM.

SPACE: Do not write BOM.

Default

SPACE


9. FIELDNAMES
GUI_DOWNLOAD FIELDNAMES

Optional table with column names for the individual columns.

  • 'DBF': The column names are entered into the structure definition of the DBF file.
  • 'DAT':  An additional row with the column names is inserted at the beginning of the table.

针对打包后exe文件无法读取Excel的问题,怎么动态获取资源路径,请显示修改后的全部代码 import os import json import re import pandas as pd import numpy as np import win32com.client from PyQt6 import QtCore, QtGui, QtWidgets from PyQt6.QtWidgets import QFileDialog, QMessageBox class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(513, 462) self.centralwidget = QtWidgets.QWidget(parent=MainWindow) self.centralwidget.setObjectName("centralwidget") self.formLayout = QtWidgets.QFormLayout(self.centralwidget) self.formLayout.setObjectName("formLayout") # Initialize labels and line edits self.label = QtWidgets.QLabel(parent=self.centralwidget) font = QtGui.QFont() font.setPointSize(13) self.label.setFont(font) self.label.setObjectName("label") self.formLayout.setWidget(0, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label) self.lineEdit = QtWidgets.QLineEdit(parent=self.centralwidget) self.lineEdit.setObjectName("lineEdit") self.lineEdit.textChanged.connect(self.save_data) # Connect to save data self.formLayout.setWidget(0, QtWidgets.QFormLayout.ItemRole.FieldRole, self.lineEdit) self.label_2 = QtWidgets.QLabel(parent=self.centralwidget) font = QtGui.QFont() font.setPointSize(13) self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.formLayout.setWidget(2, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_2) self.lineEdit_2 = QtWidgets.QLineEdit(parent=self.centralwidget) self.lineEdit_2.setObjectName("lineEdit_2") self.lineEdit_2.textChanged.connect(self.save_data) # Connect to save data self.formLayout.setWidget(2, QtWidgets.QFormLayout.ItemRole.FieldRole, self.lineEdit_2) self.label_3 = QtWidgets.QLabel(parent=self.centralwidget) font = QtGui.QFont() font.setPointSize(13) self.label_3.setFont(font) self.label_3.setObjectName("label_3") self.formLayout.setWidget(4, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_3) self.lineEdit_3 = QtWidgets.QLineEdit(parent=self.centralwidget) self.lineEdit_3.setObjectName("lineEdit_3") self.lineEdit_3.textChanged.connect(self.save_data) # Connect to save data self.formLayout.setWidget(4, QtWidgets.QFormLayout.ItemRole.FieldRole, self.lineEdit_3) self.label_4 = QtWidgets.QLabel(parent=self.centralwidget) font = QtGui.QFont() font.setPointSize(13) self.label_4.setFont(font) self.label_4.setObjectName("label_4") self.formLayout.setWidget(6, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_4) self.lineEdit_4 = QtWidgets.QLineEdit(parent=self.centralwidget) self.lineEdit_4.setObjectName("lineEdit_4") self.lineEdit_4.textChanged.connect(self.save_data) # Connect to save data self.formLayout.setWidget(6, QtWidgets.QFormLayout.ItemRole.FieldRole, self.lineEdit_4) self.label_5 = QtWidgets.QLabel(parent=self.centralwidget) font = QtGui.QFont() font.setPointSize(13) self.label_5.setFont(font) self.label_5.setObjectName("label_5") self.formLayout.setWidget(8, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_5) self.lineEdit_5 = QtWidgets.QLineEdit(parent=self.centralwidget) self.lineEdit_5.setObjectName("lineEdit_5") self.lineEdit_5.textChanged.connect(self.save_data) # Connect to save data self.formLayout.setWidget(8, QtWidgets.QFormLayout.ItemRole.FieldRole, self.lineEdit_5) self.label_6 = QtWidgets.QLabel(parent=self.centralwidget) font = QtGui.QFont() font.setPointSize(13) self.label_6.setFont(font) self.label_6.setObjectName("label_6") self.formLayout.setWidget(10, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_6) self.lineEdit_6 = QtWidgets.QLineEdit(parent=self.centralwidget) self.lineEdit_6.setObjectName("lineEdit_6") self.lineEdit_6.textChanged.connect(self.save_data) # Connect to save data self.formLayout.setWidget(10, QtWidgets.QFormLayout.ItemRole.FieldRole, self.lineEdit_6) self.label_7 = QtWidgets.QLabel(parent=self.centralwidget) font = QtGui.QFont() font.setPointSize(13) self.label_7.setFont(font) self.label_7.setObjectName("label_7") self.formLayout.setWidget(12, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_7) self.lineEdit_7 = QtWidgets.QLineEdit(parent=self.centralwidget) self.lineEdit_7.setObjectName("lineEdit_7") self.lineEdit_7.setReadOnly(True) # Make it read-only to prevent manual input self.lineEdit_7.mousePressEvent = self.open_folder_dialog # Set click event self.formLayout.setWidget(12, QtWidgets.QFormLayout.ItemRole.FieldRole, self.lineEdit_7) self.label_8 = QtWidgets.QLabel(parent=self.centralwidget) font = QtGui.QFont() font.setPointSize(13) self.label_8.setFont(font) self.label_8.setObjectName("label_8") self.formLayout.setWidget(14, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_8) self.lineEdit_8 = QtWidgets.QLineEdit(parent=self.centralwidget) self.lineEdit_8.setObjectName("lineEdit_8") self.lineEdit_8.textChanged.connect(self.save_data) # Connect to save data self.formLayout.setWidget(14, QtWidgets.QFormLayout.ItemRole.FieldRole, self.lineEdit_8) self.pushButton = QtWidgets.QPushButton(parent=self.centralwidget) self.pushButton.setObjectName("pushButton") self.pushButton.setText("执行") self.pushButton.clicked.connect(self.process_data) # Connect to process data self.formLayout.setWidget(16, QtWidgets.QFormLayout.ItemRole.FieldRole, self.pushButton) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(parent=MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 513, 22)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(parent=MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) # Load previous data self.load_data() def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.label.setText(_translate("MainWindow", "付款清单开始日期")) self.label_2.setText(_translate("MainWindow", "付款清单结束日期")) self.label_3.setText(_translate("MainWindow", "ZFIR08_N")) self.label_4.setText(_translate("MainWindow", "ZFIR08_Y")) self.label_5.setText(_translate("MainWindow", "ZFIR08_D")) self.label_6.setText(_translate("MainWindow", "FBL5N_Date")) self.label_7.setText(_translate("MainWindow", "文件地址")) self.label_8.setText(_translate("MainWindow", "输入公司代码")) def open_folder_dialog(self, event): folder = QFileDialog.getExistingDirectory(None, "选择文件夹") if folder: self.lineEdit_7.setText(folder) self.save_data() # Save data when folder is selected def load_data(self): # Load the previous input data from a JSON file if os.path.exists('data.json'): with open('data.json', 'r', encoding='utf-8') as f: data = json.load(f) self.lineEdit.setText(data.get("lineEdit", "")) self.lineEdit_2.setText(data.get("lineEdit_2", "")) self.lineEdit_3.setText(data.get("lineEdit_3", "")) self.lineEdit_4.setText(data.get("lineEdit_4", "")) self.lineEdit_5.setText(data.get("lineEdit_5", "")) self.lineEdit_6.setText(data.get("lineEdit_6", "")) self.lineEdit_7.setText(data.get("lineEdit_7", "")) self.lineEdit_8.setText(data.get("lineEdit_8", "")) def save_data(self): # Save the current input data to a JSON file data = { "lineEdit": self.lineEdit.text(), "lineEdit_2": self.lineEdit_2.text(), "lineEdit_3": self.lineEdit_3.text(), "lineEdit_4": self.lineEdit_4.text(), "lineEdit_5": self.lineEdit_5.text(), "lineEdit_6": self.lineEdit_6.text(), "lineEdit_7": self.lineEdit_7.text(), "lineEdit_8": self.lineEdit_8.text(), } with open('data.json', 'w', encoding='utf-8') as f: json.dump(data, f) def process_data(self): start_date = self.lineEdit.text() end_date = self.lineEdit_2.text() ZFIR08_N = self.lineEdit_3.text() ZFIR08_Y = self.lineEdit_4.text() ZFIR08_D = self.lineEdit_5.text() FBL5N_Date = self.lineEdit_6.text() Company_Code = self.lineEdit_8.text() folder = self.lineEdit_7.text() # 定义正则表达 pattern = r'^\w+_付款清单留存及检核\.xlsx$' # 获取当前目录下的所有文件 files = os.listdir('.') # 找到符合模文件 matching_files = [f for f in files if re.match(pattern, f)] if matching_files: # 如果找到符合条件的文件,读取第一个匹配的文件 df_FK = pd.read_excel(matching_files[0], sheet_name="代发") print(f"成功读取文件: {matching_files[0]}") # 将“过账日期”列从object类型转换为日期类型 df_FK["过账日期"] = pd.to_datetime(df_FK["过账日期"], errors='coerce') # 清洗数据,去掉过账日期为空的行 df_FK = df_FK.dropna(subset=["过账日期"]) # 格化“过账日期”为年月日格 df_FK["过账日期"] = df_FK["过账日期"].dt.strftime('%Y-%m-%d') # 筛选需要的字段并过滤“过账日期”在输入的日期范围内的数据 df_FK = df_FK[["公司代码", "凭证编号", "分配", "金额", "客户编码", "过账日期"]] df_FK = df_FK.query("@start_date <= 过账日期 <= @end_date") # # 导出txt - 修改为使用folder路径 # df_FK[["凭证编号"]].to_csv("./重复检核结果凭证编号.txt", index=False, sep='\t', encoding='utf-8') df_FK[["凭证编号"]].to_csv(f"{folder}/重复检核结果凭证编号.txt", index=False, sep='\t', encoding='utf-8') print("重复检核结果凭证编号已保存为 '重复检核结果凭证编号.TXT'") # SAP下载 SapGuiAuto_1 = win32com.client.GetObject("SAPGUI") application_1 = SapGuiAuto_1.GetScriptingEngine connections_1 = application_1.Children session = connections_1[0].Children(0) session.findById("wnd[0]").maximize() session.findById("wnd[0]/tbar[0]/okcd").text = "ZFIR08" session.findById("wnd[0]").sendVKey(0) session.findById("wnd[0]/usr/ctxtP_BUKRS").text = Company_Code session.findById("wnd[0]/usr/txtS_GJAHR-LOW").text = ZFIR08_N session.findById("wnd[0]/usr/txtS_MONAT1-LOW").text = ZFIR08_Y session.findById("wnd[0]/usr/txtS_MONAT1-HIGH").text = ZFIR08_D session.findById("wnd[0]/usr/txtS_MONAT1-HIGH").setFocus() session.findById("wnd[0]/usr/txtS_MONAT1-HIGH").caretPosition = 0 session.findById("wnd[0]/usr/btn%_S_BELNR_%_APP_%-VALU_PUSH").press() session.findById("wnd[1]/tbar[0]/btn[23]").press() session.findById("wnd[2]/usr/ctxtDY_PATH").text = folder session.findById("wnd[2]/usr/ctxtDY_FILENAME").text = "重复检核结果凭证编号.TXT" session.findById("wnd[2]/usr/ctxtDY_FILENAME").caretPosition = 34 session.findById("wnd[2]/tbar[0]/btn[0]").press() session.findById("wnd[1]/tbar[0]/btn[8]").press() session.findById("wnd[0]/tbar[1]/btn[8]").press() session.findById("wnd[0]/mbar/menu[0]/menu[3]/menu[1]").select() session.findById("wnd[1]/tbar[0]/btn[0]").press() session.findById("wnd[1]/usr/ctxtDY_PATH").text = folder session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = f"{Company_Code}ZFIR08.XLSX" session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 24 session.findById("wnd[1]/tbar[0]/btn[0]").press() # 创建Excel应用程序对象 excel = win32com.client.Dispatch("Excel.Application") excel.Visible = False # 设置Excel应用为不可见 # 关闭所有打开的Excel工作簿 workbooks = excel.Workbooks for wb in workbooks: try: wb.Close(SaveChanges=False) # 关闭工作簿,不保存更改 except Exception as e: print(f"关闭工作簿时出错: {e}") # 退出Excel应用程序 excel.Quit() session.findById("wnd[0]/tbar[0]/btn[3]").press() print(f"{Company_Code}ZFIR08已经下载完") # FBL5N session.findById("wnd[0]/tbar[0]/btn[15]").press() SapGuiAuto_1 = win32com.client.GetObject("SAPGUI") application_1 = SapGuiAuto_1.GetScriptingEngine connections_1 = application_1.Children session = connections_1[0].Children(0) session.findById("wnd[0]").maximize() session.findById("wnd[0]/tbar[0]/okcd").text = "FBL5N" session.findById("wnd[0]").sendVKey(0) session.findById("wnd[0]/tbar[1]/btn[17]").press() session.findById("wnd[1]/usr/txtENAME-LOW").text = "" session.findById("wnd[1]/usr/txtENAME-LOW").setFocus() session.findById("wnd[1]/usr/txtENAME-LOW").caretPosition = 0 session.findById("wnd[1]/tbar[0]/btn[8]").press() QtCore.QThread.sleep(1) # Sleep for a moment to allow loading session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").setCurrentCell(58, "TEXT") session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").firstVisibleRow = 45 session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows = "58" session.findById("wnd[1]/tbar[0]/btn[2]").press() session.findById("wnd[0]/usr/ctxtDD_BUKRS-LOW").text = Company_Code session.findById("wnd[0]/usr/ctxtPA_STIDA").text = FBL5N_Date session.findById("wnd[0]/usr/ctxtPA_STIDA").setFocus() session.findById("wnd[0]/usr/ctxtPA_STIDA").caretPosition = 10 session.findById("wnd[0]/tbar[1]/btn[8]").press() session.findById("wnd[0]/mbar/menu[0]/menu[3]/menu[1]").select() session.findById("wnd[1]/tbar[0]/btn[0]").press() session.findById("wnd[1]/usr/ctxtDY_PATH").text = folder session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = f"{Company_Code}FBL5N.XLSX" session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 2 session.findById("wnd[1]/tbar[0]/btn[0]").press() # 创建Excel应用程序对象 excel = win32com.client.Dispatch("Excel.Application") excel.Visible = False # 设置Excel应用为不可见 # 关闭所有打开的Excel工作簿 workbooks = excel.Workbooks for wb in workbooks: try: wb.Close(SaveChanges=False) # 关闭工作簿,不保存更改 except Exception as e: print(f"关闭工作簿时出错: {e}") # 退出Excel应用程序 excel.Quit() session.findById("wnd[0]/tbar[0]/btn[3]").press() print(f"{Company_Code}FBL5N已经下载完") session.findById("wnd[0]/tbar[0]/btn[15]").press() # 验证文本和行数第一个条件正确 ZFIR08 df_FK["辅助数据"] = df_FK["公司代码"].astype(str) + "_" + df_FK["金额"].astype(str) + "_" + df_FK["客户编码"].astype(str) # # 新增“重复检核结果”列,标识辅助数据中的重复项 df_FK["辅助数据重复检核结果"] = df_FK.duplicated(subset=["辅助数据"], keep=False).replace({True: '重复', False: '唯一'}) # # 验证文凭证编号第二个条件正确 df_ZFIR08 = pd.read_excel(f"./{Company_Code}FIR08.XLSX") df_ZFIR08.rename(columns={'凭证编码': '凭证编号'}, inplace=True) df_ZFIR08['行项目文本'] = df_ZFIR08.groupby('凭证编号')['行项目文本'].ffill() df_ZFIR08['凭证编号'] = df_ZFIR08['凭证编号'].astype(str).str.lstrip('0') df_FK['凭证编号'] = df_FK['凭证编号'].astype(str).str.lstrip('0') df_ZFIR08_凭证编号14 = df_ZFIR08[df_ZFIR08['凭证编号'].str.startswith('14')] df_ZFIR08 = df_ZFIR08[df_ZFIR08["借贷标识"] == "S"] df_ZFIR08 = df_ZFIR08.drop_duplicates(subset=["凭证编号"], keep='last') # 6. 合并两个 DataFrame(14 开头的凭证 + 借贷标识为 "S" 的去重数据) df_combined = pd.concat([df_ZFIR08_凭证编号14, df_ZFIR08], ignore_index=True) df_combined = pd.merge(df_FK, df_combined[["凭证编号", "行项目文本"]], on='凭证编号', how='left') df_combined["重复检核结果"] = df_combined.duplicated(subset=["行项目文本"], keep=False).replace({True: '重复', False: '唯一'}) # FBL5N df_FBL5N = pd.read_excel(f"./{Company_Code}FBL5N.XLSX") df_FBL5N.rename(columns={'客户': '客户编码'}, inplace=True) df_FBL5N = df_FBL5N.drop_duplicates(subset=["客户编码"], keep='last') df_FBL5N['客户编码'] = df_FBL5N['客户编码'].astype(str) # 合并数据 df_FK_5N = pd.merge(df_combined,df_FBL5N[["客户编码", "文本"]], on='客户编码', how='left') # 更推荐使用NumPy的where函数代替apply,效率更高: df_FK_5N['FBL5N数据检验'] = np.where(df_FK_5N['行项目文本'].astype(str) == df_FK_5N['文本'].astype(str), '重复', '唯一') with pd.ExcelWriter(os.path.join(folder, "付款排查检核记录.xlsx")) as writer: df_greater_than_10000 = df_FK[df_FK['金额'] > 10000] df_greater_than_10000.to_excel(writer, index=False, sheet_name='大于10000') df_combined.to_excel(writer, index=False,sheet_name='ZFIR08付款排查表重复和唯一结果') df_FK_5N.to_excel(writer, index=False,sheet_name='FBL5N重复检核结果') # 保存全部检核结果 print("数据已保存为 '付款排查重复检核结果.xlsx'") # 显示完成提示 self.show_message("处理完成", "数据处理已完成,结果已保存。") def show_message(self, title, message): msg_box = QMessageBox() msg_box.setWindowTitle(title) msg_box.setText(message) msg_box.exec() if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec())
06-28
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值