:: ======================================== :: 选择文件 :: ======================================== set /p INPUT_FILE="Enter file name (number or full name, Enter for first one): "
if "%INPUT_FILE%"=="" ( set file_num=1 for%%iin (*.md) do ( if!file_num!equ1set INPUT_FILE=%%i set /a file_num+=1 ) echo Auto-selected: !INPUT_FILE! ) else ( echo%INPUT_FILE%|findstr /r "^[0-9]*$" >nul ifnoterrorlevel1 ( set file_num=1 for%%iin (*.md) do ( if!file_num!equ%INPUT_FILE%set INPUT_FILE=%%i set /a file_num+=1 ) echo Selected: !INPUT_FILE! ) else ( ifnotexist "%INPUT_FILE%" ( echo [ERROR] File "%INPUT_FILE%" not found! pause exit /b 1 ) ) )
:: 获取文件名(不含扩展名) set BASENAME=%~n1 if "%BASENAME%"=="" ( for%%iin ("%INPUT_FILE%") doset BASENAME=%%~ni )
:: ======================================== :: 选择输出格式 :: ======================================== echo. echo ======================================== echo Select Output Format echo ======================================== echo [1] docx - Word document echo [2] html - Web page echo ======================================== echo [Enter] default: docx echo ======================================== echo.
set /p FORMAT_CHOICE="Enter option [1/2] (Enter for docx): "
Sub 文档格式统一处理_兼容版() ' 功能: ' 1. 所有文本颜色改为黑色 ' 2. 所有文本字体:先宋体,再新罗马(中文宋体,英文新罗马) ' 3. 表格全框线(不含斜线)- 兼容版 ' 4. 正文首行缩进(排除标题和表格) Dim tbl As Table Dim para As Paragraph Dim doc As Document Dim rng As Range Set doc = ActiveDocument ' 关闭屏幕更新 Application.ScreenUpdating = False ' ==================== 1. 所有文本颜色改为黑色 ==================== Set rng = doc.Range rng.Font.ColorIndex = wdBlack ' ==================== 2. 字体设置 ==================== Set rng = doc.Range With rng.Font .NameFarEast = "宋体" .NameAscii = "Times New Roman" .NameOther = "Times New Roman" End With ' ==================== 3. 表格全框线(兼容版) ==================== For Each tbl In doc.Tables ' 逐个设置边框,避免常量不存在的问题 With tbl .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle .Borders(wdBorderRight).LineStyle = wdLineStyleSingle .Borders(wdBorderTop).LineStyle = wdLineStyleSingle .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle .Borders(wdBorderHorizontal).LineStyle = wdLineStyleSingle .Borders(wdBorderVertical).LineStyle = wdLineStyleSingle ' 禁用斜线 .Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone .Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone End With Next tbl ' ==================== 4. 正文首行缩进 ==================== For Each para In doc.Paragraphs If Not para.Range.Information(wdWithInTable) Then Select Case para.Style.NameLocal Case "标题 1", "标题 2", "标题 3", "标题 4", "标题 5", _ "标题 6", "标题 7", "标题 8", "标题 9", _ "Heading 1", "Heading 2", "Heading 3", "Heading 4", "Heading 5", _ "Heading 6", "Heading 7", "Heading 8", "Heading 9", _ "标题", "Heading", "Subtitle", "副标题", "Title" ' 跳过标题 Case Else para.Range.ParagraphFormat.CharacterUnitFirstLineIndent = 2 End Select End If Next para ' 恢复屏幕更新 Application.ScreenUpdating = True MsgBox "格式处理完成!(兼容版)", vbInformation, "完成" End Sub