kettle获取文件名后怎么使用

有一个文件夹里边时以日期命名的excel,字段名都一样,我需要在每个excel里面加一个列,获取到当前文件名,并加到文件中

在 Kettle 中可以使用 "Get File Names" 步骤获取指定文件夹下的文件名,然后使用 "Excel Input" 步骤读取 Excel 文件中的数据,再使用 "Add Constants" 步骤添加一个常量列,将文件名作为常量添加到 Excel 数据中。
1.使用 "Get File Names" 步骤获取指定文件夹下的文件名
选择 "Get File Names" 步骤,配置 "File / Directory" 为指定的文件夹路径,"File Filters" 为 "*.xlsx"(或者是其他你需要的 Excel 文件格式),"Fields" 中可以勾选 "Filename",这样就会获取到文件名,存储在一个名为 "filename" 的字段中。
2.使用 "Excel Input" 步骤读取 Excel 文件中的数据
选择 "Excel Input" 步骤,配置 "Filename from field" 为上一步获取到的 "filename" 字段,"Sheet name(s)" 为需要读取的工作表名称,"Fields" 中添加需要读取的字段。
🆗
3.使用 "Add Constants" 步骤添加一个常量列选择 "Add Constants" 步骤,添加一个常量列,将 "filename" 字段作为常量值添加到 Excel 数据中。
4.输出数据选择 "Text File Output" 步骤,将处理后的 Excel 数据输出到指定的文件中。

该回答通过自己思路及引用到GPTᴼᴾᴱᴺᴬᴵ搜索,得到内容具体如下。
只在 Kettle 中,您可以使用以下步骤实现你的上述功能:

  1. 使用 "Get File Names" 步骤获取指定文件夹下的所有 Excel 文件名,并将文件名保存到 "ExcelFileName" 变量中。具体步骤如下:

    • 在转换中添加 "Get File Names" 步骤,并配置如下选项:
      • "File / Directory": 指定要读取的文件夹路径。
      • "Wildcard (regex)": 指定要读取的文件名格式,例如 "*.xls"。
      • "Result file name field": 指定一个字段名,用于保存文件名。可以使用 "Add result filename to result" 选项将文件名添加到输出流中。
      • "Add filenames to result": 选中该选项,表示将所有文件名保存到一个结果集中。
    • 在转换中添加 "Set Variables" 步骤,并配置如下选项:
      • "Variable name": 指定一个变量名,用于保存文件名。
      • "Fieldname": 指定一个字段名,该字段保存了文件名。
      • "Value type": 选择 "String"。
      • "Replace variable": 选中该选项,表示将变量值替换为当前字段值。
    • 这样,每次运行转换时,都会从指定文件夹中读取所有 Excel 文件名,并将文件名保存到 "ExcelFileName" 变量中。
  2. 使用 "Excel Input" 步骤读取每个 Excel 文件,并将文件名作为一个字段添加到输出流中。具体步骤如下:

    • 在转换中添加 "Excel Input" 步骤,并配置如下选项:
      • "File name": 指定要读取的 Excel 文件路径。可以使用变量引用方式,例如 "${ExcelFileName}"。
      • "Header row": 选中该选项,表示第一行为标题行。
      • "Sheet name": 指定要读取的工作表名称,或者使用变量引用方式。
      • "Add filename to result": 选中该选项,表示将文件名作为一个字段添加到输出流中。可以指定一个字段名,例如 "FileName"。
    • 这样,每次运行转换时,都会读取指定的 Excel 文件,并将文件名作为一个字段添加到输出流中。
  3. 使用 "Add Constants" 或 "Calculator" 步骤创建一个新的列 "FileName",并将 "ExcelFileName" 变量的值赋值给该列。具体步骤如下:

    • 在转换中添加 "Add Constants" 或 "Calculator" 步骤,并配置如下选项:
      • "Fields": 指定要创建的新列名称和数据类型。
      • "Calculation": 指定该列的计算公式,例如 "${ExcelFileName}"。
    • 这样,每次运行转换时,都会创建一个新的列 "FileName",并将 "ExcelFileName" 变量的值赋值给该列。
  4. 使用 "Microsoft Excel Output" 步骤将带有文件名的 Excel 文件输出到目标文件夹中。具体步骤如下:

    • 在转换中添加 "Microsoft Excel Output" 步骤,并配置如下选项:
      • "File name": 指定要输出的 Excel 文件路径。可以使用变量引用方式,例如 "${ExcelFileName}"。
      • "Create file": 选中该选项,表示如果指定的文件不存在,则会创建一个新的文件。
      • "Sheet name": 指定要输出到的工作表名称,或者使用变量引用方式。
      • "Add filename to result": 选中该选项,表示将文件名作为一个字段添加到输出流中。可以指定一个字段名,例如 "FileName"。
    • 这样,每次运行转换时,都会将带有文件名的 Excel 文件输出到指定的文件夹中。

希望这些步骤能够帮助您解决问题。


如果以上回答对您有所帮助,点击一下采纳该答案~谢谢

kettle常用操作--Excel文件和数据库表之间的数据转换

可以借鉴下
https://blog.csdn.net/qq_44749491/article/details/126786955

以下答案由GPT-3.5大模型与博主波罗歌共同编写:
在Kettle中,获取文件名可以使用“Get file names”步骤,可以配置文件夹路径、文件名过滤规则等参数,获取到需要处理的文件名。

接着可以使用“Excel input”步骤读取excel文件,然后使用“Add constants”步骤添加一个常量列,常量值为当前文件名,添加到读取的excel数据中。

具体操作步骤如下:

  1. 添加“Get file names”步骤,配置好文件夹路径和文件名过滤规则等参数。将获取到的文件名输出到流中。

  2. 添加“Excel input”步骤,配置好需要读取的excel文件的信息,从上一步获取到的文件名流中获取文件名,并设置为excel文件名。

  3. 添加“Add constants”步骤,添加一个常值列,常量值设置为当前文件名,添加到excel数据中。

  4. 最后输出处理好的excel数据。

以下是Kettle代码的示例:

<?xml version="1.0" encoding="UTF-8"?>
<transformation>
  <info>
    <name>add filename to excel</name>
    <description>add current filename as a column to excel</description>
    <extended_description></extended_description>
    <trans_version>9.1.0.0-324</trans_version>
    <trans_type>Normal</trans_type>
    <trans_status>0</trans_status>
    <directory>&lt;project&gt;/&lt;subdir&gt;/</directory>
    <parameters></parameters>
  </info>
  <step>
    <name>Get file names</name>
    <type>GET_FILE_NAMES</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
      <partitioning_per_slave>N</partitioning_per_slave>
      <partitioning_fields/>
    </partitioning>
    <fields>
      <field>
        <name>filename</name>
        <type>String</type>
        <format/>
        <currency/>
        <decimal/>
        <group/>
        <nullif/>
        <ifnull/>
        <trim_type>none</trim_type>
        <length>-1</length>
        <precision>-1</precision>
        <set_empty_string>N</set_empty_string>
      </field>
    </fields>
    <file>
      <name>Get file names</name>
      <exclude_filemask/>
      <file_required>N</file_required>
      <include_subfolders>N</include_subfolders>
      <field_include>N</field_include>
      <type_include>N</type_include>
      <last_modify_date_include>N</last_modify_date_include>
      <uri_replace>N</uri_replace>
      <filename_Field/>
      <wildcard_Field/>
      <exclude_wildcard_Field/>
      <filecount_Field/>
      <include_subfolder_Field/>
      <last_modify_time_Field/>
      <root_uri_Field/>
      <extension_Field/>
      <size_Field/>
      <hidden_Field/>
      <parent_folder_Field/>
      <folder_Field/>
      <short_filename_Field/>
    </file>
    <limit/>
  </step>
  <step>
    <name>Excel input</name>
    <type>EXCEL_INPUT</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
      <partitioning_per_slave>N</partitioning_per_slave>
      <partitioning_fields/>
    </partitioning>
    <fields>
      <field>
        <name>fieldname1</name>
        <type>String</type>
        <format/>
        <currency/>
        <decimal/>
        <group/>
        <nullif/>
        <ifnull/>
        <trim_type>none</trim_type>
        <length>-1</length>
        <precision>-1</precision>
        <set_empty_string>N</set_empty_string>
      </field>
      <field>
        <name>fieldname2</name>
        <type>Number</type>
        <format/>
        <currency/>
        <decimal/>
        <group/>
        <nullif/>
        <ifnull/>
        <trim_type>none</trim_type>
        <length>-1</length>
        <precision>-1</precision>
        <set_empty_string>N</set_empty_string>
      </field>
    </fields>
    <file>
      <name>${filename}</name>
      <sheetname>Sheet1</sheetname>
      <startrow>1</startrow>
      <type_excel>2007</type_excel>
      <header>N</header>
      <stop_on_empty>N</stop_on_empty>
    </file>
    <addl>
      <last_column/>
      <sheet_index_nr>0</sheet_index_nr>
      <stop_on_empty>N</stop_on_empty>
      <add_to_result_filenames>N</add_to_result_filenames>
    </addl>
    <limit/>
  </step>
  <step>
    <name>Add constants</name>
    <type>ADD_CONSTANTS</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
      <partitioning_per_slave>N</partitioning_per_slave>
      <partitioning_fields/>
    </partitioning>
    <fields>
      <field>
        <name>fieldname1</name>
        <type>String</type>
        <format/>
        <currency/>
        <decimal/>
        <group/>
        <nullif/>
        <ifnull/>
        <trim_type>none</trim_type>
        <length>-1</length>
        <precision>-1</precision>
        <set_empty_string>N</set_empty_string>
        <value>${filename}</value>
      </field>
    </fields>
  </step>
  <step>
    <name>Excel output</name>
    <type>EXCEL_OUTPUT</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
      <partitioning_per_slave>N</partitioning_per_slave>
      <partitioning_fields/>
    </partitioning>
    <fields>
      <field>
        <name>fieldname1</name>
        <type>String</type>
        <format/>
        <currency/>
        <decimal/>
        <group/>
        <nullif/>
        <ifnull/>
        <trim_type>none</trim_type>
        <length>-1</length>
        <precision>-1</precision>
        <set_empty_string>N</set_empty_string>
      </field>
      <field>
        <name>fieldname2</name>
        <type>Number</type>
        <format/>
        <currency/>
        <decimal/>
        <group/>
        <nullif/>
        <ifnull/>
        <trim_type>none</trim_type>
        <length>-1</length>
        <precision>-1</precision>
        <set_empty_string>N</set_empty_string>
      </field>
      <field>
        <name>filename</name>
        <type>String</type>
        <format/>
        <currency/>
        <decimal/>
        <group/>
        <nullif/>
        <ifnull/>
        <trim_type>none</trim_type>
        <length>-1</length>
        <precision>-1</precision>
        <set_empty_string>N</set_empty_string>
      </field>
    </fields>
    <file>
      <name>newfile.xls</name>
      <extention>xls</extention>
      <do_not_open_newfile>N</do_not_open_newfile>
      <createparent>N</createparent>
      <append>N</append>
    </file>
    <addl>
      <stepnr>0</stepnr>
      <sheetname>Sheet1</sheetname>
      <make_sheet_active>N</make_sheet_active>
      <if_file_exists>do_nothing</if_file_exists>
      <overwrite_y_n>N</overwrite_y_n>
      <header>N</header>
    </addl>
    <limit/>
  </step>
  <hop>
    <from>Get file names</from>
    <to>Excel input</to>
    <from_out>filename</from_out>
    <to_in>filename</to_in>
    <enabled>Y</enabled>
  </hop>
  <hop>
    <from>Excel input</from>
    <to>Add constants</to>
    <from_out>fieldname1</from_out>
    <to_in>fieldname1</to_in>
    <enabled>Y</enabled>
  </hop>
  <hop>
    <from>Add constants</from>
    <to>Excel output</to>
    <from_out>fieldname1</from_out>
    <to_in>fieldname1</to_in>
    <enabled>Y</enabled>
  </hop>
</transformation>

注意:需要根据实际情况修改文件路径、字段名等参数。
如果我的回答解决了您的问题,请采纳!

  1. 打开一个以日期命名的Excel文件,然后按下 Alt + F11 键,打开 VBA 编辑器。
  2. 在左侧的“项目资源管理器”窗口中,双击该工作簿的名称,打开“Microsoft Excel 对象”文件夹,然后双击“这个工作簿”。
  3. 在右侧的“代码”窗口中输入以下 VBA 代码:
Private Sub Workbook_Open()

    Dim wbName As String
    wbName = Replace(ThisWorkbook.Name, ".xlsx", "")
    ActiveSheet.Cells(1, ActiveSheet.UsedRange.Columns.Count + 1).Value = wbName
    
End Sub
  1. 按下 Ctrl + S 键保存文件并关闭 VBA 编辑器。
  2. 重复以上步骤,将该 VBA 代码添加到每个以日期命名的 Excel 文件中。

这段 VBA 代码会在每次打开 Excel 文件时自动运行,将当前文件名添加到最后一列的第一行。请注意,如果您的 Excel 文件中存在多个工作表,请确保将该 VBA 代码添加到每个工作表中。

在Kettle中获取文件名可以通过使用"Get Filenames"步骤来实现。此步骤可以获取指定文件夹中的所有文件的名称,你需要设置的是文件夹的路径和文件名的通配符(如*.xlsx)。

对于你要的需求,你可以先使用"Get Filenames"步骤来获取到所有需要处理的Excel文件的名称,然后再使用"Excel Input"步骤读取每个Excel文件。

在"Excel Input"步骤中,你可以通过添加自定义字段来获取到文件名。在"Spreadsheet Input"选项卡中,选择"添加"按钮,添加一个新字段,然后在"名称"选项中键入新字段的名称,如"filename"。在"类型"选项卡中,选择"文本"。在"值"选项卡中,选择通配符(*)并将其设置为你的Excel文件的名称字段。

完成上述步骤后,你就可以在每个Excel文件中添加一个名为"filename"的新字段,它将包含当前处理的Excel文件的名称。

如果你需要将这个值写入Excel文件中,你可以使用"Add Constants"步骤将其添加为常量列,或者使用"Calculator"步骤将其添加为新列。在"Calculator"步骤中,你可以使用字符串操作函数(如"concatenate")将"filename"字段中的值与其他字段值组合起来。

希望这些步骤会对你有帮助。

基于new bing的编写参考,有帮助记得采纳!:
你可以使用Kettle中的“Get File Names”步骤来获取一个文件夹中所有的文件名。获取到文件名后,你可以将文件名作为一个变量加入到数据流中。

然后,你可以使用“Excel Input”步骤来读取每个excel文件,并将前面获取到的文件名变量添加为一个新列。

最后,你可以使用“Excel Output”步骤将处理后的文件保存到指定的位置。请确保目标位置有写入权限。

在具体实现中,你可以按照以下步骤进行设置:

  1. 使用“Get File Names”步骤获取目标文件夹中的所有文件名,存储到一个变量中。

  2. 使用“Excel Input”步骤读取每个excel文件,并使用变量作为一个新列添加到数据流中。

  3. 使用“Excel Output”步骤将处理后的文件保存到指定位置。
    将以上三个步骤按顺序连接起来,组成一个完整的Kettle转换。
    在设置“Excel Input”步骤时,请注意使用正确的文件格式及文件路径,并正确配置“Header行数”、“Sheet名称”等参数。在设置“Excel Output”步骤时,请注意设置正确的保存路径、文件名及文件格式。
    以下是Kettle中的转换XML代码示例,可实现你所需的功能:

<?xml version="1.0" encoding="UTF-8"?>
<transformation>
  <info>
    <name>add filename</name>
    <description>增加文件名列</description>
    <extended_description><![CDATA[在一个Excel表格中增加当前文件名列]]></extended_description>
    <job_entry_log_level>Basic</job_entry_log_level>
    <transformation_type>Normal</transformation_type>
    <version>1.0</version>
    <status>0</status>
  </info>

  <step>
    <name>Get file names</name>
    <type>GET_FILE_NAMES</type>
    <description>获取目标文件夹中的所有文件名</description>
    <distribute>Y</distribute>
    <custom_distribution>false</custom_distribution>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name />
    </partitioning>
    <fields>
      <field>
        <name>File path</name>
        <type>File/Directory</type>
        <description>源文件路径</description>
        <format />
        <currency />
        <decimal />
        <group />
        <length>-1</length>
        <precision>-1</precision>
        <trim_type>none</trim_type>
        <repeat />
        <nullif />
        <ifnull />
      </field>
    </fields>
    <include_subfolders>N</include_subfolders>
    <filemask>*.xlsx</filemask>
    <exclude_filemask />
    <file_required>N</file_required>
    <include_hidden>N</include_hidden>
    <use_regex>N</use_regex>
    <dynamic_folder>N</dynamic_folder>
    <wildcard>Y</wildcard>
    <field_files_count />
    <field_hidden />
    <field_last_modified />
    <field_path_filename />
    <field_uri />
    <limit>-1</limit>
    <IsIgnoreEmptyFile>N</IsIgnoreEmptyFile>
    <start_with_subfolder>N</start_with_subfolder>
    <do_not_fail_if_no_files>Y</do_not_fail_if_no_files>
  </step>

  <step>
    <name>Excel Input</name>
    <type>Microsoft Excel Input</type>
    <description>读取Excel表格</description>
    <distribute>Y</distribute>
    <custom_distribution>false</custom_distribution>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name />
    </partitioning>
    <connection>Kettle File Repository</connection>
    <file>PATH_TO_EXCEL_FILE</file>
    <sheet>Sheet1</sheet>
    <header>N</header>
    <startrow>0</startrow>
    <rowcount>0</rowcount>
    <limit>-1</limit>
    <encoding />
    <add_to_result_filenames>N</add_to_result_filenames>
    <is_file_template>N</is_file_template>
    <spreadsheet_type>2007</spreadsheet_type>
    <ignore_missing_worksheets>N</ignore_missing_worksheets>
    <use_legacy_style>N</use_legacy_style>
    <IgnoreEmptySheets>N</IgnoreEmptySheets>
    <stop_on_empty>N</stop_on_empty>
    <accept_filenames_from_previous>N</accept_filenames_from_previous>
    <accept_field>A_FILENAME</accept_field>
    <accept_field_type>Filename</accept_field_type>
    <accept_stepname>Get file names</accept_stepname>
    <expand_folders>N</expand_folders>
  </step>

  <step>
    <name>Add constant</name>
    <type>Constant</type>
    <description>增加常量列</description>
    <distribute>Y</distribute>
    <custom_distribution>false</custom_distribution>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name />
    </partitioning>
    <fields>
      <field>
        <name>FILENAME</name>
        <type>String</type>
        <description>当前文件名</description>
        <format />
        <currency />
        <decimal />
        <group />
        <length>-1</length>
        <precision>-1</precision>
        <trim_type>none</trim_type>
        <repeat />
        <nullif />
        <ifnull />
        <value>PATH_TO_EXCEL_FILE</value>
        <field_length>-1</field_length>
        <field_precision>-1</field_precision>
        <set_type_desc>N</set_type_desc>
      </field>
    </fields>
  </step>

  <step>
    <name>Select values</name>
    <type>SelectValues</type>
    <description>选择需要的列</description>
    <distribute>Y</distribute>
    <custom_distribution>false</custom_distribution>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name />
    </partitioning>
    <fields>
      <field>
        <name>A_FILENAME</name>
        <type>Filename</type>
        <description>文件名</description>
        <format />
        <currency />
        <decimal />
        <group />
        <length>100</length>
        <precision>-1</precision>
        <trim_type>none</trim_type>
        <repeat />
        <nullif />
        <ifnull />
        <aggregation_type>none</aggregation_type>
        <case_sensitive>N</case_sensitive>
        <custom_name />
      </field>
      <field>
        <name>NEW_COL</name>
        <type>String</type>
        <description>新增列</description>
        <format />
        <currency />
        <decimal />
        <group />
        <length>-1</length>
        <precision>-1</precision>
        <trim_type>none</trim_type>
        <repeat />
        <nullif />
        <ifnull />
        <aggregation_type>none</aggregation_type>
        <case_sensitive>N</case_sensitive>
        <custom_name />
      </field>
    </fields>
    <select_fields>N</select_fields>
    <reset_row_number>N</reset_row_number>
    <is_aggregate>N</is_aggregate>
    <always_allocate_rowset>Y</always_allocate_rowset>
    <database_meta />
    <limit>-1</limit>
    <lazy_conversion_active>N</lazy_conversion_active>
    <cluster_schema />
  </step>

  <step>
    <name>Excel Output</name>
    <type>Microsoft Excel Output</type>
    <description>保存为Excel表格</description>
    <distribute>Y</distribute>
    <custom_distribution>false</custom_distribution>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name />
    </partitioning>
    <connection>Kettle File Repository</connection>
    <append>N</append>
    <create_parent_folder>Y</create_parent_folder>
    <filename>PATH_TO_EXCEL_FILE</filename>
    <xlsx_compress>N</xlsx_compress>
    <create_sheets>N</create_sheets>
    <field_type_list />
    <split_every>0</split_every>
    <add_to_result>Y</add_to_result>
    <template_enabled>N</template_enabled>
    <template_append>Y</template_append>
    <sheetname>Sheet1</sheetname>
    <leave_query_data>N</leave_query_data>
    <password_encoding />
    <encoding />
    <header_enabled>N</header_enabled>
    <footer_enabled>N</footer_enabled>
    <header_font_name>Arial</header_font_name>
    <header_font_size>10</header_font_size>
    <header_font_color>000000</header_font_color>
    <header_background_color>CCCCCC</header_background_color>
    <header_row_height>-1</header_row_height>
    <footer_font_name>Arial</footer_font_name>
    <footer_font_size>10</footer_font_size>
    <footer_font_color>000000</footer_font_color>
    <footer_background_color>CCCCCC</footer_background_color>
    <footer_row_height>-1</footer_row_height>
    <row_font_name>Arial</row_font_name>
    <row_font_size>10</row_font_size>
    <row_font_color>FFFFFF</row_font_color>
    <row_background_color>000000</row_background_color>
    <row_alternative>N</row_alternative>
    <row_alternative_font_name>Arial</row_alternative_font_name>
    <row_alternative_font_size>10</row_alternative_font_size>
    <row_alternative_font_color>FFFFFF</row_alternative_font_color>
    <row_alternative_background_color>666666</row_alternative_background_color>
    <row_height>-1</row_height>
    <header_image_encoding>base64</header_image_encoding>
    <header_image />
    <comment_field />
    <formula />
    <shift_field />
    <NoEmptyLines>N</NoEmptyLines>
    <IgnorHeader>N</IgnorHeader>
    <ProtectSheet>N</ProtectSheet>
    <ProtectSheetPassword />
    <AppendToExistingFile>N</AppendToExistingFile>
    <AppendSeparator />
    <AddToResultFilenames>Y</AddToResultFilenames>
    <AppendFieldFilenames>N</AppendFieldFilenames>
    <date_time_format />
  </step>

  <hop>
    <from>Get file names</from>
    <to>Excel Input</to>
    <enabled>Y</enabled>
  </hop>
  <hop>
    <from>Excel Input</from>
    <to>Add constant</to>
    <enabled>Y</enabled>
  </hop>
  <hop>
    <from>Add constant</from>
    <to>Select values</to>
    <enabled>Y</enabled>
  </hop>
  <hop>
    <from>Select values</from>
    <to>Excel Output</to>
    <enabled>Y</enabled>
  </hop>
</transformation>


注意替换代码中的一些自定义参数,例如:PATH_TO_EXCEL_FILE,这些参数根据具体情况设置。

  • 你可以看下这个问题的回答https://ask.csdn.net/questions/7491243
  • 我还给你找了一篇非常好的博客,你可以看看是否有帮助,链接:kettle遍历抽取某目录下Excel文件数据
  • 除此之外, 这篇博客: Kettle学习笔记中的 4.1 Excel输出 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • Excel输出:
    Excel输出 ---- 输出.xls 文件
    Microsoft Excel输出 ---- 输出.xlsx文件

    任务:
    从MySQL数据库的mysql库的user表读取数据插入到excel的.xls和.xlsx文件中

    1.配置:

    文件选择界面:

    image-20210930165826263

    获取字段界面:

    image-20210930165934258

    2.运行结果:

    image-20210930170111669

    image-20210930170200006

解决方式参考了https://blog.csdn.net/weixin_43329319/article/details/108348145
我的解决方式是

img

img

1.获取目录下的文件名

img

2.遍历上个转换的结果集并写入到新的excel

img

2.1

img


2.2

img