Python Forum
write to excel will be empty in column
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
write to excel will be empty in column
#1
i have a question about reading a text file, but in the text file occur many empty space.
My text file data_out.txt:
no mac mta MAC ETH MAC
=== =========== =========== ===========
2 7719B1822090 7719B1822091 7719B1822092
3 749111111210 491111112101 491111112102

My code:
import openpyxl,string 
f=open(r'D:\test\data_out.txt','r+') #open text 
#########if load excel file ########################
#excel=openpyxl.load_workbook(r'D:\\test\\test.xlsx') #open excel 
#excel=openpyxl.load_workbook(r'D:\\test\\test.xlsx') #open excel 
excel = openpyxl.Workbook() 
sheet=excel.worksheets 
line=f.readline(); #read text 

while line: 
    list=[] 
    list = line.split(sep=' ') #convert, 
    print(list)
    for i in range(0, len(list)): # remove space 
        
        #list[i] = list[i].strip('\n') 
        list[i] = list[i].strip('\n')
        #print(list[i])
    sheet[0].append(list) #wrire into excel 
    
    line=f.readline() #read next line 
    print(line)
excel.save(r'D:\test\test.xlsx')


When it write to my excel file, the column on c3, c4, c5,c6, d3,d4,d5,d6 will be empty.
How can i let G3 move to c3, and G4 move to c4.
is there any way

it will print
['no', '', '', '', '', '', '', '', '', '', '', 'mac', '', '', '', '', '', '', '', '', 'mta', 'MAC', '', '', '', '', '', '', '', '', '', 'ETH', 'MAC', '\n']
['===', '', '', '', '', '===========', '', '', '', '', '', '===========', '', '', '', '', '===========', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '\n']
['2', '\t7719B1822090', '', '', '', '', '7719B1822091', '', '', '', '', '7719B1822092\n']
['3', '\t749111111210', '', '', '', '', '491111112101', '', '', '', '', '491111112102\n']
['\n']


how to remove the ''?
Reply


Messages In This Thread
write to excel will be empty in column - by jacklee26 - Jun-24-2020, 10:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I write all csv records to Excel ? Revox 2 1,003 Mar-29-2023, 03:53 PM
Last Post: deanhystad
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,169 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  [SOLVED] [sqilte3] Check if column not empty? Winfried 5 1,201 Jan-28-2023, 12:53 PM
Last Post: Winfried
  how to read txt file, and write into excel with multiply sheet jacklee26 14 10,531 Jan-21-2023, 06:57 AM
Last Post: jacklee26
  Openpyxl manipulate excel write formula SamLiu 0 1,109 Nov-04-2022, 03:00 PM
Last Post: SamLiu
  How to format Excel column with comma? dee 0 1,413 Jun-13-2022, 10:11 PM
Last Post: dee
  Cursor write 3rd file empty paulo79 3 1,940 Mar-10-2022, 02:51 PM
Last Post: DeaD_EyE
  Appending Excel column value as CSV file name sh1704 0 1,329 Feb-06-2022, 10:32 PM
Last Post: sh1704
  dataframe write to tab delimited differs from Excel koh 0 2,042 Aug-01-2021, 02:46 AM
Last Post: koh
  Want to remove the text from a particular column in excel shantanu97 2 2,194 Jul-05-2021, 05:42 PM
Last Post: eddywinch82

Forum Jump:

User Panel Messages

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