- 添加对话表结构

- 调整部分类的命名空间
- 引入 EnumUtility 用于string与enum的转换
This commit is contained in:
SepComet 2026-02-09 10:23:25 +08:00
parent 67e6b33677
commit 5973c1a4a7
77 changed files with 397 additions and 157 deletions

8
.gitignore vendored
View File

@ -85,3 +85,11 @@ crashlytics-build.properties
/Assets/RawResources /Assets/RawResources
/.vscode /.vscode
# Excel temporary lock files
~$*.xls
~$*.xlsx
~$*.xlsm
~$*.xlsb
/数据表/__pycache__

View File

@ -0,0 +1,7 @@
# 对话标识表 筛选用数据
# Id Title UIMode ChapterId
# int string DialogUIMode int
# 对话编号 策划备注 对话标识 对话形式 章节编号
1001 第一章介绍 Chapter1_Intro Mask 1.001
1002 第一章主流程 Chapter1_Main BottomBox 1.002
1003 第一章玩法开始前闲聊 Chapter1_SmallTalk1 BubbleBox 1.003

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 788b17ff3aef4cd4fb6c808826c875e5
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,13 @@
# 对话内容表 筛选用数据
# Id SpeakerId Expression SpeakerName Direction Text Emphasis ChapterId DialogId
# int int ExpressionType string int string EmphasisType int int
# 对话行编号 策划备注 说话人Id 表情 显示人名 说话朝向 说话内容 演出效果 章节Id 对话Id
100100001 Id规则为 Null Null Null 0 相传。 1.00100001 1001.00001
100100002 第1位数为章节Id Null Null Null 0 Mask。 1.00100002 1001.00002
100100003 第2-4位数为对话Id Null Null Null 0 很好。 1.00100003 1001.00003
100200001 第5-9位数为对话行Id Xu Normal 徐晟壹 0 你好,王。 1.00200001 1002.00001
100200002 Wang Normal 王可嘉 1 你好,徐。 1.00200002 1002.00002
100200003 Master Normal 李诫 1 你们好。 1.00200003 1002.00003
100300001 Npc1 Null Null 0 这人谁啊? 1.00300001 1003.00001
100300002 Npc2 Null Null 0 不知道啊? 1.00300002 1003.00002
100300003 Npc1 Null Null 0 不知道你在这干嘛。 1.00300003 1003.00003

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 378604b840f56ae49831978cf0e0a6ea
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -5,4 +5,3 @@
1 菜单场景 Menu 1 1 菜单场景 Menu 1
2 战斗场景 Main 2 2 战斗场景 Main 2
3 压力测试场景 StressTest 0 3 压力测试场景 StressTest 0
4 玩法A测试场景 GameplayA 0

View File

@ -6,4 +6,3 @@
100 主菜单 MenuForm Default False True 100 主菜单 MenuForm Default False True
101 设置 SettingForm Default False True 101 设置 SettingForm Default False True
102 关于 AboutForm Default False True 102 关于 AboutForm Default False True
103 <09><><EFBFBD><EFBFBD><EFBFBD>淨A MVC<56><43><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD> CombineForm Default False True

View File

@ -9,7 +9,7 @@ using System;
using System.IO; using System.IO;
using UnityEngine; using UnityEngine;
namespace StarForce namespace DataTable
{ {
public static class BinaryReaderExtension public static class BinaryReaderExtension
{ {

View File

@ -0,0 +1,39 @@
using CustomUtility;
using Definition.Enum;
using UnityGameFramework.Runtime;
namespace DataTable
{
public class DRDialog : DataRowBase
{
private int m_Id;
/// <summary>
/// 获取对话编号。
/// </summary>
public override int Id => m_Id;
/// <summary>
/// 获取对话标识。
/// </summary>
public string Title { get; private set; }
/// <summary>
/// 获取对话形式。
/// </summary>
public DialogUIMode UIMode { get; private set; }
public override bool ParseDataRow(string dataRowString, object userData)
{
string[] fields = dataRowString.Split('\t');
int index = 1;
m_Id = int.Parse(fields[index++]);
index++;
Title = fields[index++];
UIMode = EnumUtility<DialogUIMode>.Get(fields[index++]);
return true;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fb12692f2a7e6174eae3b0d28c769e55
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,64 @@
using CustomUtility;
using Definition.Enum;
using UnityGameFramework.Runtime;
namespace DataTable
{
public class DRDialogLine : DataRowBase
{
private int m_Id;
/// <summary>
/// 获取对话行编号
/// </summary>
public override int Id { get; }
/// <summary>
/// 获取说话人 Id。
/// </summary>
public string SpeakerId { get; private set; }
/// <summary>
/// 获取说话人表情。
/// </summary>
public ExpressionType Expression { get; private set; }
/// <summary>
/// 获取说话人显示名。
/// </summary>
public string SpeakerName { get; private set; }
/// <summary>
/// 获取说话人朝向。
/// </summary>
public int Direction { get; private set; }
/// <summary>
/// 获取对话内容。
/// </summary>
public string Text { get; private set; }
/// <summary>
/// 获取对话效果。
/// </summary>
public EmphasisType Emphasis { get; private set; }
public override bool ParseDataRow(string dataRowString, object userData)
{
string[] fields = dataRowString.Split('\t');
int index = 0;
index++;
m_Id = int.Parse(fields[index++]);
index++;
SpeakerId = fields[index++];
Expression = EnumUtility<ExpressionType>.Get(fields[index++]);
SpeakerName = fields[index++];
Direction = int.Parse(fields[index++]);
Text = fields[index++];
Emphasis = EnumUtility<EmphasisType>.Get(fields[index++]);
return true;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fc6d3e8e61ab627488e22bb5fc28f95d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -16,7 +16,7 @@ using System.Text;
using UnityEngine; using UnityEngine;
using UnityGameFramework.Runtime; using UnityGameFramework.Runtime;
namespace StarForce namespace DataTable
{ {
/// <summary> /// <summary>
/// 实体表。 /// 实体表。
@ -28,13 +28,7 @@ namespace StarForce
/// <summary> /// <summary>
/// 获取实体编号。 /// 获取实体编号。
/// </summary> /// </summary>
public override int Id public override int Id => m_Id;
{
get
{
return m_Id;
}
}
/// <summary> /// <summary>
/// 获取资源名称。 /// 获取资源名称。

View File

@ -16,7 +16,7 @@ using System.Text;
using UnityEngine; using UnityEngine;
using UnityGameFramework.Runtime; using UnityGameFramework.Runtime;
namespace StarForce namespace DataTable
{ {
/// <summary> /// <summary>
/// 音乐配置表。 /// 音乐配置表。

View File

@ -1,22 +1,8 @@
//------------------------------------------------------------ using System.IO;
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
// 此文件由工具自动生成,请勿直接修改。
// 生成时间2021-06-16 21:54:35.610
//------------------------------------------------------------
using GameFramework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text; using System.Text;
using UnityEngine;
using UnityGameFramework.Runtime; using UnityGameFramework.Runtime;
namespace StarForce namespace DataTable
{ {
/// <summary> /// <summary>
/// 场景配置表。 /// 场景配置表。

View File

@ -1,22 +1,8 @@
//------------------------------------------------------------ using System.IO;
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
// 此文件由工具自动生成,请勿直接修改。
// 生成时间2021-06-16 21:54:35.625
//------------------------------------------------------------
using GameFramework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text; using System.Text;
using UnityEngine;
using UnityGameFramework.Runtime; using UnityGameFramework.Runtime;
namespace StarForce namespace DataTable
{ {
/// <summary> /// <summary>
/// 声音配置表。 /// 声音配置表。

View File

@ -1,14 +1,4 @@
//------------------------------------------------------------ using GameFramework;
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
// 此文件由工具自动生成,请勿直接修改。
// 生成时间2021-06-16 21:54:35.652
//------------------------------------------------------------
using GameFramework;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -16,7 +6,7 @@ using System.Text;
using UnityEngine; using UnityEngine;
using UnityGameFramework.Runtime; using UnityGameFramework.Runtime;
namespace StarForce namespace DataTable
{ {
/// <summary> /// <summary>
/// 界面配置表。 /// 界面配置表。

View File

@ -1,14 +1,4 @@
//------------------------------------------------------------ using GameFramework;
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
// 此文件由工具自动生成,请勿直接修改。
// 生成时间2021-06-16 21:54:35.666
//------------------------------------------------------------
using GameFramework;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -16,7 +6,7 @@ using System.Text;
using UnityEngine; using UnityEngine;
using UnityGameFramework.Runtime; using UnityGameFramework.Runtime;
namespace StarForce namespace DataTable
{ {
/// <summary> /// <summary>
/// 声音配置表。 /// 声音配置表。

View File

@ -1,16 +1,10 @@
//------------------------------------------------------------ using GameFramework.DataTable;
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using GameFramework.DataTable;
using System; using System;
using Definition;
using UnityEngine; using UnityEngine;
using UnityGameFramework.Runtime; using UnityGameFramework.Runtime;
namespace StarForce namespace DataTable
{ {
public static class DataTableExtension public static class DataTableExtension
{ {

View File

@ -5,6 +5,7 @@
// Feedback: mailto:ellan@gameframework.cn // Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------ //------------------------------------------------------------
using Definition;
using GameFramework.Debugger; using GameFramework.Debugger;
using GameFramework.Localization; using GameFramework.Localization;
using UnityEngine; using UnityEngine;

View File

@ -5,7 +5,7 @@
// Feedback: mailto:ellan@gameframework.cn // Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------ //------------------------------------------------------------
namespace StarForce namespace Definition
{ {
public static partial class Constant public static partial class Constant
{ {

View File

@ -7,7 +7,7 @@
using UnityEngine; using UnityEngine;
namespace StarForce namespace Definition
{ {
public static partial class Constant public static partial class Constant
{ {

View File

@ -5,7 +5,7 @@
// Feedback: mailto:ellan@gameframework.cn // Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------ //------------------------------------------------------------
namespace StarForce namespace Definition
{ {
public static partial class Constant public static partial class Constant
{ {

View File

@ -0,0 +1,22 @@
namespace Definition.Enum
{
public enum DialogUIMode
{
None = 0,
/// <summary>
/// 黑屏白字
/// </summary>
Mask = 1,
/// <summary>
/// 底部对话框
/// </summary>
BottomBox = 2,
/// <summary>
/// 对话气泡
/// </summary>
BubbleBox = 3
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7a10763d137f413d828c534b0233f2a6
timeCreated: 1770600423

View File

@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Definition.Enum
{
public enum EmphasisType
{
None,
Shake,
Blink,
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 96908bdc885697e4d9cb0f6627d13230
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Definition.Enum
{
public enum ExpressionType
{
None,
Normal,
Shock,
Happy,
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 174e046d822a14d49843dc415067f13c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -7,6 +7,8 @@
using GameFramework.DataTable; using GameFramework.DataTable;
using System; using System;
using CustomUtility;
using DataTable;
using Entity; using Entity;
using Entity.EntityData; using Entity.EntityData;
using UnityGameFramework.Runtime; using UnityGameFramework.Runtime;

View File

@ -1,10 +1,6 @@
//------------------------------------------------------------ using CustomUtility;
// Game Framework using DataTable;
// Copyright © 2013-2021 Jiang Yin. All rights reserved. using Definition;
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using GameFramework.DataTable; using GameFramework.DataTable;
using GameFramework.Event; using GameFramework.Event;
using Scene; using Scene;

View File

@ -1,12 +1,6 @@
//------------------------------------------------------------ using GameFramework.Localization;
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using GameFramework.Localization;
using System; using System;
using Definition;
using StarForce; using StarForce;
using UnityGameFramework.Runtime; using UnityGameFramework.Runtime;
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>; using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;

View File

@ -1,15 +1,10 @@
//------------------------------------------------------------ using GameFramework;
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using GameFramework;
using GameFramework.Event; using GameFramework.Event;
using GameFramework.Resource; using GameFramework.Resource;
using System.Collections.Generic; using System.Collections.Generic;
using StarForce; using CustomUtility;
using DataTable;
using Definition;
using TMPro; using TMPro;
using UI; using UI;
using UnityEngine; using UnityEngine;
@ -28,6 +23,8 @@ namespace Procedure
"Sound", "Sound",
"UIForm", "UIForm",
"UISound", "UISound",
"Dialog",
"DialogLine"
}; };
private Dictionary<string, bool> _loadedFlag = new Dictionary<string, bool>(); private Dictionary<string, bool> _loadedFlag = new Dictionary<string, bool>();

View File

@ -5,6 +5,9 @@
// Feedback: mailto:ellan@gameframework.cn // Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------ //------------------------------------------------------------
using CustomUtility;
using DataTable;
using Definition;
using Entity; using Entity;
using GameFramework; using GameFramework;
using GameFramework.DataTable; using GameFramework.DataTable;

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8cb383e8977814343a630c164eed6c51
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,13 +1,9 @@
//------------------------------------------------------------ using GameFramework.DataTable;
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using GameFramework.DataTable;
using GameFramework.UI; using GameFramework.UI;
using System.Collections; using System.Collections;
using CustomUtility;
using DataTable;
using Definition;
using Procedure; using Procedure;
using StarForce; using StarForce;
using UnityEngine; using UnityEngine;

View File

@ -7,7 +7,7 @@
using GameFramework; using GameFramework;
namespace StarForce namespace CustomUtility
{ {
public static class AssetUtility public static class AssetUtility
{ {

View File

@ -0,0 +1,27 @@
using System.Collections.Generic;
using UnityGameFramework.Runtime;
namespace CustomUtility
{
public static class EnumUtility<T> where T : struct, System.Enum
{
private static readonly Dictionary<string, T> _enumCache = new();
public static T Get(string value)
{
if (!_enumCache.TryGetValue(value, out T result))
{
if (System.Enum.TryParse(value, true, out result))
{
_enumCache[value] = result;
}
else
{
Log.Error($"Enum 解析失败:类型:{typeof(T).Name} 不包含值 {value}");
}
}
return result;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d0591e8f95955014f8c2f8d9ba3c9247
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -9,7 +9,7 @@ using GameFramework;
using LitJson; using LitJson;
using System; using System;
namespace StarForce namespace CustomUtility
{ {
/// <summary> /// <summary>
/// LitJSON 函数集辅助器。 /// LitJSON 函数集辅助器。

View File

@ -1,13 +1,6 @@
//------------------------------------------------------------ using System;
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using System; namespace CustomUtility
namespace StarForce
{ {
public static class WebUtility public static class WebUtility
{ {

View File

@ -812,11 +812,23 @@ PlayerSettings:
webGLMemoryGeometricGrowthCap: 96 webGLMemoryGeometricGrowthCap: 96
webGLPowerPreference: 2 webGLPowerPreference: 2
scriptingDefineSymbols: scriptingDefineSymbols:
Android: ENABLE_DEBUG_AND_ABOVE_LOG Android: ENABLE_DEBUG_AND_ABOVE_LOG;DOTWEEN
Standalone: ENABLE_DEBUG_AND_ABOVE_LOG EmbeddedLinux: DOTWEEN
WebGL: ENABLE_DEBUG_AND_ABOVE_LOG GameCoreScarlett: DOTWEEN
Windows Store Apps: ENABLE_DEBUG_AND_ABOVE_LOG GameCoreXboxOne: DOTWEEN
iPhone: ENABLE_DEBUG_AND_ABOVE_LOG LinuxHeadlessSimulation: DOTWEEN
Nintendo Switch: DOTWEEN
PS4: DOTWEEN
PS5: DOTWEEN
QNX: DOTWEEN
Stadia: DOTWEEN
Standalone: ENABLE_DEBUG_AND_ABOVE_LOG;DOTWEEN
VisionOS: DOTWEEN
WebGL: ENABLE_DEBUG_AND_ABOVE_LOG;DOTWEEN
Windows Store Apps: ENABLE_DEBUG_AND_ABOVE_LOG;DOTWEEN
XboxOne: DOTWEEN
iPhone: ENABLE_DEBUG_AND_ABOVE_LOG;DOTWEEN
tvOS: DOTWEEN
additionalCompilerArguments: {} additionalCompilerArguments: {}
platformArchitecture: {} platformArchitecture: {}
scriptingBackend: {} scriptingBackend: {}

7
数据表/Dialog.txt Normal file
View File

@ -0,0 +1,7 @@
# 对话标识表 筛选用数据
# Id Title UIMode ChapterId
# int string DialogUIMode int
# 对话编号 策划备注 对话标识 对话形式 章节编号
1001 第一章介绍 Chapter1_Intro Mask 1.001
1002 第一章主流程 Chapter1_Main BottomBox 1.002
1003 第一章玩法开始前闲聊 Chapter1_SmallTalk1 BubbleBox 1.003

BIN
数据表/Dialog.xlsx Normal file

Binary file not shown.

13
数据表/DialogLine.txt Normal file
View File

@ -0,0 +1,13 @@
# 对话内容表 筛选用数据
# Id SpeakerId Expression SpeakerName Direction Text Emphasis ChapterId DialogId
# int int ExpressionType string int string EmphasisType int int
# 对话行编号 策划备注 说话人Id 表情 显示人名 说话朝向 说话内容 演出效果 章节Id 对话Id
100100001 Id规则为 Null Null Null 0 相传。 1.00100001 1001.00001
100100002 第1位数为章节Id Null Null Null 0 Mask。 1.00100002 1001.00002
100100003 第2-4位数为对话Id Null Null Null 0 很好。 1.00100003 1001.00003
100200001 第5-9位数为对话行Id Xu Normal 徐晟壹 0 你好,王。 1.00200001 1002.00001
100200002 Wang Normal 王可嘉 1 你好,徐。 1.00200002 1002.00002
100200003 Master Normal 李诫 1 你们好。 1.00200003 1002.00003
100300001 Npc1 Null Null 0 这人谁啊? 1.00300001 1003.00001
100300002 Npc2 Null Null 0 不知道啊? 1.00300002 1003.00002
100300003 Npc1 Null Null 0 不知道你在这干嘛。 1.00300003 1003.00003

BIN
数据表/DialogLine.xlsx Normal file

Binary file not shown.

View File

@ -5,4 +5,3 @@
1 菜单场景 Menu 1 1 菜单场景 Menu 1
2 战斗场景 Main 2 2 战斗场景 Main 2
3 压力测试场景 StressTest 0 3 压力测试场景 StressTest 0
4 玩法A测试场景 GameplayA 0

View File

@ -6,4 +6,3 @@
100 主菜单 MenuForm Default False True 100 主菜单 MenuForm Default False True
101 设置 SettingForm Default False True 101 设置 SettingForm Default False True
102 关于 AboutForm Default False True 102 关于 AboutForm Default False True
103 核心玩法A MVC测试界面 CoreGameplayAMvcForm Default False True

View File

@ -1,5 +0,0 @@
# 武器表
# Id Attack AttackInterval BulletId BulletSpeed BulletSoundId
# int int float int float int
# 武器编号 策划备注 攻击力 攻击间隔 子弹编号 子弹速度 子弹声音编号
30000 玩家武器 100 0.2 50000 20 10000

Binary file not shown.

View File

@ -1,9 +1,11 @@
import pandas as pd import os
import os
import shutil import shutil
import pandas as pd
def convert_excel_to_txt(folder_path='.'): def convert_excel_to_txt(folder_path='.'):
# 计数器,用于最后汇总 # 计数器,用于最后统计
count = 0 count = 0
target_dir = os.path.join(os.path.dirname(__file__), '../Assets/GameMain/DataTables') target_dir = os.path.join(os.path.dirname(__file__), '../Assets/GameMain/DataTables')
target_dir = os.path.abspath(target_dir) target_dir = os.path.abspath(target_dir)
@ -11,13 +13,19 @@ def convert_excel_to_txt(folder_path='.'):
# 确保目标目录存在 # 确保目标目录存在
os.makedirs(target_dir, exist_ok=True) os.makedirs(target_dir, exist_ok=True)
for file_name in os.listdir(folder_path): for root, _, files in os.walk(folder_path):
if file_name.endswith(('.xlsx', '.xls')): for file_name in files:
file_path = os.path.join(folder_path, file_name) if not file_name.lower().endswith(('.xlsx', '.xls')):
base_name = os.path.splitext(file_path)[0] continue
output_file = base_name.replace(os.path.basename(base_name), os.path.basename(base_name)) + '.txt' # 跳过 Excel 临时锁文件
if file_name.startswith('~$'):
continue
print(f"正在处理: {file_name}...") file_path = os.path.join(root, file_name)
base_name = os.path.splitext(file_path)[0]
output_file = base_name + '.txt'
print(f"正在处理: {file_path}...")
try: try:
df = pd.read_excel(file_path, header=None) df = pd.read_excel(file_path, header=None)
@ -33,13 +41,13 @@ def convert_excel_to_txt(folder_path='.'):
count += 1 count += 1
except Exception as e: except Exception as e:
print(f"处理 {file_name} 时出错: {e}") print(f"处理 {file_path} 时出错: {e}")
print(f"\n任务完成!共转换了 {count} 个文件。") print(f"\n任务完成!共转换了 {count} 个文件。")
if __name__ == "__main__": if __name__ == "__main__":
convert_excel_to_txt('.') convert_excel_to_txt('.')
# --- 关键修改:在这里添加暂停 ---
print("\n" + "=" * 30) print("\n" + "=" * 30)
input("按回车键(Enter)退出程序...") input("按回车键(Enter)退出程序...")