目前我正在使用bash脚本从sql生成csv文件。然后我将其通过电子邮件发送给其他人。我被要求在通过电子邮件发送之前将自动过滤器(excel概念)添加到文件中。我希望能够在没有人工交互的bash脚本中执行此操作。到目前为止google搜索/ stackoverflowing我还没有找到办法。
答案 0 :(得分:1)
CSV无法应用AutoFilter。 Excel可读的最简单格式是能够应用AutoFilter的Excel 2003 SpreadsheetML。请参阅https://msdn.microsoft.com/en-us/library/bb226687%28v=office.11%29.aspx和https://msdn.microsoft.com/en-us/library/bb226693%28v=office.11%29.aspx
这也是纯文本,因此可以通过bash脚本创建。
AutoFilter的简单示例:
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<Worksheet ss:Name="Sheet1">
<Table>
<Row>
<Cell><Data ss:Type="String">name</Data></Cell>
<Cell><Data ss:Type="String">value</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">a</Data></Cell>
<Cell><Data ss:Type="Number">1</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">a</Data></Cell>
<Cell><Data ss:Type="Number">2</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">b</Data></Cell>
<Cell><Data ss:Type="Number">1</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">b</Data></Cell>
<Cell><Data ss:Type="Number">2</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">c</Data></Cell>
<Cell><Data ss:Type="Number">1</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">c</Data></Cell>
<Cell><Data ss:Type="Number">2</Data></Cell>
</Row>
</Table>
<AutoFilter x:Range="R1C1:R7C2" xmlns="urn:schemas-microsoft-com:office:excel">
</AutoFilter>
</Worksheet>
</Workbook>
另一种可能性是,bash脚本可以调用可以创建真正XLS
或XLSX
文件的软件。
答案 1 :(得分:0)
如果您使用的是Linux系统,则可以通过在终端中运行以下命令来执行相同的操作:
libreoffice -display :0 --headless --convert-to xls --outdir "/path/" "/path/FileName.csv"
在这里,路径表示您的csv文件所在的位置。