Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9057743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:32:18+00:00 2026-06-16T14:32:18+00:00

I wrote a small script to read from multiple excel files and write the

  • 0

I wrote a small script to read from multiple excel files and write the data into a xml-file. I stripped the script a bit to explain what goes wrong. It looks like this:

import glob, xlrd

xmlFile = 'example.xml'
xmlData = open(xmlFile, 'a')

for xlsfile in glob.glob('*.xls'):

    wb = xlrd.open_workbook(xlsfile)
    sh1 = wb.sheet_by_index(0)
    sh1c1 = sh1.col_values(1)   


    for cell in sh1c1: xmlData.write(cell + "\n")

Everything goes fine as long there is only text in the cells in my excel-files. When there is a number in one of the cells; I get an error:

 Traceback (most recent call last):
    File "test.py", line 14, in <module>
   for cell in sh1c1: xmlData.write(cell + "\n")
TypeError: unsupported operand type(s) for +: 'float' and 'str'

It is only in some cells and in some files that it will contain a number. I already read a lot about floats, integers and strings but I haven’t found a way to apply this on above code. I am absolutely new to python and I can’t get my head around everything yet. Does someone want to point me in the right direction?

Many thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T14:32:19+00:00Added an answer on June 16, 2026 at 2:32 pm

    As commenter suggests, you need to cast your float to string to use a + operator:

    for cell in sh1c1: xmlData.write(str(cell) + "\n")
    

    Or, you can rewrite it as:

    for cell in sh1c1: xmlData.write("{0}\n".format(cell)) 
    

    Or, as:

    for cell in sh1c1: xmlData.write("%s\n" % cell)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am write a small python script to gather some data from a database,
I wrote a small PHP script to edit the site news XML file. I
So I've wrote a small script to download pictures from a website. It goes
I have a small script we're using to read in a CSV file containing
I wanted to write a small script that searched for an exact file name,
I wrote small script in python to translate words from English to Russian language.
I would like to read a file into a script, line by line. Each
I just started playing with Clojure, and I wrote a small script to help
I wrote a small program, that creates files at an interval of 1 minute.
I am writing small process monitor script in Perl by reading values from Proc

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.