c语言 导出xls 文本,文本文件转成xls文件

#!/bin/bash

help() {

echo "

转换文本文件为xls文件

usage: file2xls [-F] [-t FS] file1 file2 ...

-F 强制所有字段为文本格式,不强制,0000会变成0

-t 指定分隔符,默认为\",\"

"

}

convert() {

awk -F "$FS" -v F_set="$F_set" '

BEGIN {

if (F_set==1) F_str=" style=mso-number-format:\"\\@\""

print ""

print "

"

print ""

print ""

print "

"

print "

}

{

for(i=1;i<=NF;i++) {

if (i==1)  print "

"

printf("

%s\n",F_str,$i)

if (i==NF) printf("

\n")

}

}

END {

print "

"

print ""

print ""

}

' $1

}

#main

[[ $# -eq 0 || "$1"x = "-h"x || "$1"x = "--help"x || "$1"x = "-H"x ]] && help && exit

if [ "$1"x = "-F"x ];then

F_set=1

if [ "$2"x = "-t"x ];then

FS="$3"

Start_count=4

else

FS=","

Start_count=2

fi

else

F_set=0

if [ "$1"x = "-t"x ];then

FS="$2"

Start_count=3

else

FS=","

Start_count=1

fi

fi

Count=0

for File in $*

do

Count=$(expr $Count + 1)

if [ $Count -ge $Start_count ];then

printf "%s\t...\t" "$File"

if [ -e $File ];then

convert $File >${File}.xls

printf "%s\n" "[      done ]"

else

printf "%s\n" "[ not found ]"

fi

fi

done

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值