linux - xls2csv + 禁用 XLS 中的空格

标签 linux excel bash perl csv

我使用 xls2csv 二进制文件在我的 linux red-hat 机器上将 XLS 文档转换为 CSV,

在某些情况下,XLS 文档在单词前或单词后有空格

XLS文件示例(word3右边有一个空格)

 word1 word2 "word3 "
 word1 word2 "word3 "
 word1 word2 "word3 "

在我运行 xls2csv

之后

作为:

  xls2csv -x "1252spreadsheet.xls" -b WINDOWS-1252 -c "ut8csvfile.csv" -a UTF-8 ) 

我注意到 csv 文档中的 word3 与 XLS 中的 word3 具有相同的空格(“word3”)

请建议如何配置 xls2csv 二进制文件以禁用空格????来自 XLS 文档,所以我将获得没有空格的 CSV?

来自 XLS2CSV 手册页:

 man xls2csv
 XLS2CSV(1)            User Contributed Perl Documentation           XLS2CSV(1)

 NAME
       xls2csv - A script that recodes a spreadsheetâs charset and saves as CSV.

    DESCRIPTION
        This script will recode a spreadsheet into a different character set and output     the recoded data as a csv file.

          The script came about after many headaches from dealing with Excel   spreadsheets from clients that were being
       received in various character sets.

  OPTIONS
           -x     : filename of the source spreadsheet
           -b     : the character set the source spreadsheet is in (before)
           -c     : the filename to save the generated csv file as
           -a     : the character set the csv file should be converted to (after)
           -q     : quiet mode
           -s     : print a list of supported character sets
           -h     : print help message
           -v     : get version information
           -W     : list worksheets in the spreadsheet specified by -x
           -w     : specify the worksheet name to convert (defaults to the first worksheet)
           -n     : specify the worksheet number to convert (you cannot use this option with -w)
           -f     : force the worsheet to be fully parsed. This disables the feature that skips rows when the first cell is blk

最佳答案

IMO,听起来您用错了工具。也许您应该编写一个脚本,使用 Spreadsheet::ParseExcel 读取/解析 xls 文件,然后应用任何需要的字段重新格式化。完成后,使用 Text::CSV_XS 输出 csv 数据。

编辑:我打算将其作为评论发布,但我想它也可以作为答案。

关于linux - xls2csv + 禁用 XLS 中的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25000101/

相关文章:

vba - 将 CSV 合并到一张表中并删除标题

vb.net - 通过 VB.net 为 Excel 使用 "cells"选择连续范围

html - 需要从 excel 导出中去除 HTML 字符,但保留效果

bash - 在 Ubuntu 上,bash 脚本总是返回 0,即使设置了 set -o errexit

bash,查找单词之间有多个空格的字符串中第n个单词的起始位置

c++ - Qt creator 4 找不到QCamera

linux - 如何将一个目录复制或镜像到另一个目录?

linux - 在文件中搜索单词并将其从小写转换为大写

c - 带有 LCD 错误消息的 Bash ping 脚本

linux - 在Linux中建立文件索引