dropdown menu

Back To Home

Monday, May 25, 2020

Solved: UnicodeEncodeError: 'charmap' codec can't encode characters

Below are code to solve this error.

Code:


import xlsxwriter 
  
workbook = xlsxwriter.Workbook('skill.csv') 
  
# By default worksheet names in the spreadsheet will be  
# Sheet1, Sheet2 etc., but we can also specify a name. 
worksheet = workbook.add_worksheet("skill") 
  
# Some data we want to write to the worksheet. 
details = ( 
    ['SN', 'Name','Contribution'], 
    [1, "Linus Torvalds", "Linux Kernel"], 
    [2, "Tim Berners-Lee", "World Wide Web"], 
    [3, "Guido van Rossum", "Python Programming"],
    [4, "吴刚", "中文"],
 ) 

# Start from the first cell. Rows and 
# columns are zero indexed. 
row = 0
col = 0
  
# Iterate over the data and write it out row by row. 
for SN, Name , Contribution in (details): 
    worksheet.write(row, col, SN) 
    worksheet.write(row, col + 1, Name)
    worksheet.write(row, col + 2, Contribution)
    row += 1
  
workbook.close() 




No comments:

Post a Comment