2015-07-21 56 views
2

目前我正在使用bash脚本从sql生成一个csv文件。然后我将它发送给其他人。我被要求在发送电子邮件之前将自动过滤器(一种excel概念)添加到文件中。我希望能够在没有人际交互的bash脚本中执行此操作。到目前为止googling/stackoverflowing我还没有找到一种方法来做到这一点。将csv转换为excel工作表,并在linux中使用过滤器

回答

1

CSV无法应用AutoFilter。 Excel可以读取的最简单的格式是能够应用AutoFilter的Excel 2003 SpreadsheetML。请参阅https://msdn.microsoft.com/en-us/library/bb226687%28v=office.11%29.aspxhttps://msdn.microsoft.com/en-us/library/bb226693%28v=office.11%29.aspx

这也是纯文本,因此它可以由bash脚本创建。

与自动筛选简单的例子:

<?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脚本可以调用它可以创造真正XLSXLSX文件的软件。