# HG changeset patch # User ufz # Date 1734382589 0 # Node ID a21347be425d511823fd9e95f1c7270d430049ac planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/xls2tsv commit 2e75a14496fa80104e76b307289c58b9b7013ae1 diff -r 000000000000 -r a21347be425d test-data/excel_test.xlsx Binary file test-data/excel_test.xlsx has changed diff -r 000000000000 -r a21347be425d test-data/output_sheet_1.tsv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/output_sheet_1.tsv Mon Dec 16 20:56:29 2024 +0000 @@ -0,0 +1,4 @@ +column0 column1 +test1 value1 +test2 value2 +test3 value3 diff -r 000000000000 -r a21347be425d test-data/output_sheet_2.tsv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/output_sheet_2.tsv Mon Dec 16 20:56:29 2024 +0000 @@ -0,0 +1,4 @@ +column2 column3 +test4 value4 +test5 value5 +test6 value6 diff -r 000000000000 -r a21347be425d xlsx2tsv.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xlsx2tsv.py Mon Dec 16 20:56:29 2024 +0000 @@ -0,0 +1,32 @@ +import argparse + +import pandas as pd + + +def convert_xlsx_to_tsv(input_file, sheet_name, output): + try: + # Read the specified sheet and convert them to tsv + df = pd.read_excel(input_file, sheet_name=sheet_name) + df.to_csv(output, sep='\t', index=False) + print(f"Extracted sheet '{sheet_name}' from {input_file}") + + except Exception as e: + print(f"Failed to convert sheet '{sheet_name}' from {input_file}: {e}") + + +def main(): + parser = argparse.ArgumentParser(description="Convert specific sheets from a single .xlsx file to .tsv format in the same directory.") + parser.add_argument("--input-file", type=str, required=True, help="Path to the input .xlsx file.") + parser.add_argument("--sheet-names", type=str, required=True, help="Comma-separated list of sheet names to convert.") + parser.add_argument("--output", type=str, default="extracted_sheet.tsv", required=False, help="Suffix for the tsv file") + args = parser.parse_args() + + # Convert sheet names from str to list + sheet_names = args.sheet_names + + # Call the conversion function with the provided arguments + convert_xlsx_to_tsv(args.input_file, sheet_names, args.output) + + +if __name__ == "__main__": + main() diff -r 000000000000 -r a21347be425d xlsx2tsv.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xlsx2tsv.xml Mon Dec 16 20:56:29 2024 +0000 @@ -0,0 +1,50 @@ + + with pandas + + pandas + openpyxl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Description +----------- +Extract a sheet from XLS/XLSX file to a tabular file + + + 10.5281/zenodo.13819579 + + \ No newline at end of file