在Talend中将数据库表导出到Excel

在本节中,我们将展示一个示例,说明如何在Talend中使用tFileOutputExcel将数据库表导出到Excel。对于此tFileOutputExcel演示,我们使用的是SQL数据库表,该表中的数据为

Customer Sales Table with HireDate

Talend导出数据库表到Excel文件示例

从下面的Talend图像中,您可以看到我们已经建立了SQL连接,并使用DBInput选择了Customer表。

Configure Server Connection and write table Select query

接下来,从调色板中拖放tFileOutputExcel输出字段。正如您在工具提示中看到的,Talend tFileOutputExcel逐行将单元格写入Microsoft Excel文件。

Add tFileOutputExcel output field to Export Database Table to Excel in Talend

请将DBInput源连接到tFileOutputExcel。以下屏幕截图显示了Talend tFileOutputExcel组件选项卡中可用的选项列表,用于将数据库表导出到Excel文件。

  • 写入excel2007文件格式(xlsx)–它以2007格式写入输出。
  • 包含标题:您想包含标题名称还是不包含?
  • 附加到现有文件:您想将数据附加到现有文件还是不附加?
  • 更改字体样式。
  • 您希望通过选中旁边的框来自动调整列的宽度吗?
Components tab

默认情况下,tFileOutputExcel字段选择默认位置并将out.xls作为文件名。请单击浏览(...)按钮选择现有文件或创建新的Excel文件。在这里,我们在“Output files”目录中创建Customers_Excel.xls。

接下来,我们从下拉列表中选择了Courier New字体。并选择“Define all columns to auto-size”选项。您可以在下面的屏幕截图中看到我们为此示例选择的所有选项。

Export Database Table to Excel in Talend Configuration

接下来,单击“Edit Schema”按钮以检查Talend tFileOutputExcel的模式。

Edikt Schema

让我们运行Talend tFileOutputExcel作业,看看是否已将数据库表导出到Excel文件。

Run the Job to Export Database Table to Excel in Talend

您可以看到由Talend tFileOutputExcel作业生成的输出文件。

Customer Table