注意:每个单元格不能出现字符【|、$、;】

1. bat文件里面写死文件名

@echo off && setlocal enabledelayedexpansion

SET mdfile=MD-CSV.md
SET csvfile=csv-md.csv :: 当前目录下创建文件
cd. >%csvfile% set /a index=0 set "nativesplit=|"
set "splitstr=$"
set "tmpsplit=,"
set end=0
set one=0
set "stepstr="
set "splitstrempty=$ "
set inforsum=30
set inforindex=0
set "teststring="
set "enter=;" for /f "delims=" %%a in (%mdfile%) do (
set "tmpstr="
set /a index+=1
set data1=%%a if !index! NEQ 2 (
if "!data1:~-1!"==" " (
set "data1=!data1:~0,-1!"
) set "data1=!data1:~1,-1!" set "teststring=!teststring!!enter!!data1!"
)
) set "teststring=!teststring:|=$!" :splitend
echo !teststring!| findstr !splitstrempty! >nul && (
set "teststring=!teststring:%splitstrempty%=%splitstr%!"
set /a inforindex+=1
if !inforindex! == !inforsum! (
set inforindex=0
goto splitstart
)
goto splitend
) || (
set inforindex=0
goto splitstart
) :splitstart
set "splitstrempty= $"
echo !teststring!| findstr !splitstrempty! >nul && (
set "teststring=!teststring:%splitstrempty%=%splitstr%!"
set /a inforindex+=1
if !inforindex! == !inforsum! (
set inforindex=0
goto headsplit
)
goto splitstart
) || (
set inforindex=0
goto headsplit
) :headsplit
set "teststring=!teststring:$=,!"
set teststring=!teststring:~1,-1!
echo !teststring! :stringLOOP
if "!teststring!" EQU "" (
goto END
) :: 注意:切割符号
for /f "delims=;" %%a in ("!teststring!") do (
set substring=%%a
)
if "!substring:~-1!"==" " (
set "substring=!substring:~0,-1!"
)
if "!substring:~-1!"==" " (
set "substring=!substring:~0,-1!"
)
if "!substring:~0,1!"==" " (
set "substring=!substring:~1!"
)
echo !substring!>>%csvfile% :striploop
set stripchar=!teststring:~0,1!
set teststring=!teststring:~1! :: 如果为空字符串,就结束
if "!teststring!" EQU "" (
goto END
) if "!stripchar!" NEQ "!enter!" (
set "substring="
goto striploop
) goto stringloop
) :END pause

2. 拖入文件

生成的csv文件格式为MD2CSV-MD文件名.csv

@echo off && setlocal enabledelayedexpansion

set nativemdfile=%~1
set mdfile=%~n1
SET "csvfile=MD2CSV-!mdfile!.csv" :: 当前目录下创建文件
cd. >%csvfile% set /a index=0 set "nativesplit=|"
set "splitstr=$"
set "tmpsplit=,"
set end=0
set one=0
set "stepstr="
set "splitstrempty=$ "
set inforsum=30
set inforindex=0
set "teststring="
set "enter=;" for /f "delims=" %%a in (%nativemdfile%) do (
set "tmpstr="
set /a index+=1
set data1=%%a if !index! NEQ 2 (
if "!data1:~-1!"==" " (
set "data1=!data1:~0,-1!"
) set "data1=!data1:~1,-1!" set "teststring=!teststring!!enter!!data1!"
)
) set "teststring=!teststring:|=$!" :splitend
echo !teststring!| findstr !splitstrempty! >nul && (
set "teststring=!teststring:%splitstrempty%=%splitstr%!"
set /a inforindex+=1
if !inforindex! == !inforsum! (
set inforindex=0
goto splitstart
)
goto splitend
) || (
set inforindex=0
goto splitstart
) :splitstart
set "splitstrempty= $"
echo !teststring!| findstr !splitstrempty! >nul && (
set "teststring=!teststring:%splitstrempty%=%splitstr%!"
set /a inforindex+=1
if !inforindex! == !inforsum! (
set inforindex=0
goto headsplit
)
goto splitstart
) || (
set inforindex=0
goto headsplit
) :headsplit
set "teststring=!teststring:$=,!"
set teststring=!teststring:~1,-1! :stringLOOP
if "!teststring!" EQU "" (
goto END
) :: 注意:切割符号
for /f "delims=;" %%a in ("!teststring!") do (
set substring=%%a
)
if "!substring:~-1!"==" " (
set "substring=!substring:~0,-1!"
)
if "!substring:~-1!"==" " (
set "substring=!substring:~0,-1!"
)
if "!substring:~0,1!"==" " (
set "substring=!substring:~1!"
)
echo !substring!>>%csvfile% :striploop
set stripchar=!teststring:~0,1!
set teststring=!teststring:~1! :: 如果为空字符串,就结束
if "!teststring!" EQU "" (
goto END
) if "!stripchar!" NEQ "!enter!" (
set "substring="
goto striploop
) goto stringloop
) :END pause

最新文章

  1. ABP学习日记1
  2. Sql Server FOR XML PATH
  3. EntityFrameWork 使用时碰到的小问题
  4. socket编程listen函数限制连接数的解决方案
  5. 【原】Jqxgrid在Java服务器端分页
  6. HBase性能调优
  7. Android --通知栏Notification
  8. 句柄(handle)
  9. ssh 私匙登录, 文件rswrst权限
  10. PHP学习笔记(七)
  11. webView的一些经验总结
  12. alv行可编辑时带出描述
  13. SharePoint RBS 安装(集成Office Web Apps)
  14. Web Worker Best Practices
  15. PHP二维数组按照键值排序
  16. ccf-20171203 Crontab问题
  17. Flink(一)Flink的入门简介
  18. BZOJ1068 [SCOI2007]压缩 区间动态规划 字符串
  19. 004-docker命令-容器生命周期管理、容器操作
  20. 基于duxshop遍历无限级分销用户的纵向递归

热门文章

  1. CSS 网页字体最佳实践
  2. 一、shell编程与变量
  3. java标识符 identifier
  4. Python调用腾讯云API,实现人脸年龄变化
  5. 方法重载、方法重写、四种权限修饰、JavaBean、代码块
  6. Moriis神级遍历!
  7. WPF开发随笔收录-DataAnnotations实现数据校验(MVVM架构下)
  8. 【黑马pink老师的H5/CSS课程】(一)基本介绍
  9. NC15052 求最值
  10. Map集合概述和Map常用子类