回复 2# Batcher
是先lvm文本合并读取有效列数值,删除无效行生成的csv文件,所以可以从头开始帮忙看看脚本有没问题,感谢(文件一直上传失败~尴尬)- @echo off
- setlocal enabledelayedexpansion
-
- REM 读取多层目录下的.lvm文件数据并提取电压输出值
- for /f "delims=" %%a in ('dir /a-d/s/b *.lvm') do (
- set n=0&set/a m+=1
- for /f "tokens=3" %%b in ('type "%%a"') do (
- set/a n+=1&set str!m!!n!=%%b
- )
- )
- (for /l %%a in (1 1 !n!) do (
- for /l %%b in (1 1 !m!) do (
- set/p=!str%%b%%a! <nul
- )
- echo.
- ))>new.lvm
-
- REM 删除前几行无效数据
- @for %%i in (*.lvm) do @more +7 "%%i">$&move $ "%%i"
-
- REM 读取new.lvm文件内容并按行解析
- for /f "tokens=*" %%a in (new.lvm) do (
- set "line=%%a"
- set "validLine="
- set "validElements=0"
-
- REM 将一行数据按空格或其他空白内容分隔成数组
- for %%b in (!line!) do (
- set "element=%%b"
-
- REM 检查数组元素是否为有效数字或小数点
- echo !element! | findstr /r "[0-9]*\.[0-9]*" >nul
- if !errorlevel! equ 0 (
- REM 找到有效元素,将其连接到validLine变量
- if defined validLine (
- set "validLine=!validLine!,!element!"
- ) else (
- set "validLine=!element!"
- )
- set /a validElements+=1
- )
- )
- REM 将满足要求的有效行写入new.csv文件
- if !validElements! geq 1 (
- echo !validLine! >>new.csv
- echo 数据提取中...
-
- ren new.csv new.xlsx
- )
- )
- endlocal
-
- echo 提取数据完成,将于1s后关闭窗口!
- ping 127.1 -n 2 >nul
-
- REM excel一列转多列多行的公式:=OFFSET($C$1,(COLUMN(C1)-3)*81+(ROW(C1)-1),)&""
复制代码
|