Python Forum
Text to Column to Excel in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Text to Column to Excel in Python
#1
Hello everyone,

I have updated my script as follows:
import mutagen, xlrd, glob, re, openpyxl, os
# from mutagen.easyid3 import EasyID3
from os import walk
from pprint import pprint
from tinytag import TinyTag, TinyTagException
from openpyxl import Workbook
from openpyxl.utils import get_column_letter
from mp3_tagger import MP3File
from string import ascii_uppercase

filenames = os.listdir('E:\\All of D Drive\\Mixes\\')  # directory path of files
number_files = len(filenames)


def ExtractMP3TagtoExcel():
    print('Starting Program')

    tracks = []
    gettags = []
    
    for root, dirs, files, in os.walk('E:\\All of D Drive\\Mixes\\'): #('C:\\Users\\mrdrj\\Desktop\\sdf\\'):
        for name in files:
            if name.endswith(('.mp3', '.m4a', '.flac', '.alac')):

                tracks.append(name)  # Add Media Files

                try:

                    temp_track = TinyTag.get(root + '\\' + name)
                    mp3 = MP3File(root + '\\' + name)
                    # tags = mp3.get_tags()
                    print(root, '-', temp_track.artist, '-', temp_track.title)

                    gettags2 = [temp_track.album, temp_track.albumartist, temp_track.artist, temp_track.audio_offset,
                                temp_track.bitrate, temp_track.comment, temp_track.composer, temp_track.disc,
                                temp_track.disc_total, temp_track.duration, temp_track.filesize, temp_track.genre,
                                temp_track.samplerate, temp_track.title, temp_track.track, temp_track.track_total,
                                temp_track.year]  # Add Tags to list

                    gettags.append(gettags2)

                except TinyTagException:
                    print('Error')

    wb = Workbook()

    dest_filename = '-11empty_book11-.xlsx'
    #newFile = dest_filename

    #worksheet = wb.active

    ws1 = wb.active
    #ws = wb.active
    ws1.title = "MP3 Tags"  # Main Tab
    #sheet = "MP3 Tags"
    sheet = wb['MP3 Tags']

    ws1['A1'] = 'Album'
    ws1['B1'] = 'Contributing Artists'
    ws1['C1'] = 'Title'
    ws1['D1'] = 'Total Number of Disk'
    ws1['E1'] = 'Genre'
    ws1['F1'] = 'Disc Number'
    ws1['G1'] = 'Track Duration'

    for i in range(0,len(gettags)):
        e=sheet.cell(row=2+i,column=1)
        e.value =  "{0}".format(gettags[i]) #gettags[i] #gettags[i]
        print(gettags[i])

    wb.save(filename=dest_filename)

ExtractMP3TagtoExcel()
The problem that I am having difficulty working out from the print
gettags[i]
is how can I text to columns like in excel the following ['', ' A.R.P & U. T Dread', ' A.R.P & U. T Dread', 484185, 320] into the separate columns of Album, Title, Genre, etc? Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,130 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Two text files, want to add a column value zxcv101 8 1,942 Jun-20-2022, 03:06 PM
Last Post: deanhystad
  Reshaping a single column in to multiple column using Python sahar 7 2,071 Jun-20-2022, 12:35 PM
Last Post: deanhystad
  How to format Excel column with comma? dee 0 1,374 Jun-13-2022, 10:11 PM
Last Post: dee
  Appending Excel column value as CSV file name sh1704 0 1,303 Feb-06-2022, 10:32 PM
Last Post: sh1704
  Want to remove the text from a particular column in excel shantanu97 2 2,147 Jul-05-2021, 05:42 PM
Last Post: eddywinch82
  beginner text formatting single line to column jafrost 4 3,227 Apr-28-2021, 07:03 PM
Last Post: jafrost
  Copy column from one existing excel file to another file mkujawsk 0 5,648 Apr-14-2021, 06:33 PM
Last Post: mkujawsk
  Importing text file into excel spreadsheet with formatting david_dsmn 1 3,632 Apr-05-2021, 10:21 PM
Last Post: david_dsmn
  Add a new column when I extract each sheet in an Excel workbook as a new csv file shantanu97 0 2,239 Mar-24-2021, 04:56 AM
Last Post: shantanu97

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020