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 7569285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:07:38+00:00 2026-05-30T15:07:38+00:00

I’m using XLWT to write excel files from .csv and I have the first

  • 0

I’m using XLWT to write excel files from .csv and I have the first column in the csv as the style for the row. How can I start writing the values beginning with the second column of each row (as to not print out the value, for example, “headerStyle”)? I’ve tried a few different ways, such as creating a col_count but haven’t had any luck.

row_count = 0
style = rowStyle

#Read each row and write to sheet
for row in csv_input:
        #Iterate through each column
        for col in range(len(row)):
            if col == 0:
                style = row[col]
            else:
                if(is_number(row[col]) == True):
                    sheet.write(row_count,col,float(row[col]),style)
                else:
                    sheet.write(row_count,col,row[col],style)

        #Increment row_count
        row_count += 1

Any help is appreciated! Thanks!

I ended up figuring it out. For anyone interested, one problem was that style was coming back as a string so I created a function to fix that:

def assign_style(string):
    if string=='headerStyle':
        style = headerStyle
        return style

Then the following would loop through while skipping the first column:

    row_count = 0

#Read each row and write to sheet
for row in csv_input:
        #Iterate through each column
        for col in range(len(row)):
            if col == 0:
                style = assign_style(row[col])
            elif(is_number(row[col]) == True):
                sheet.write(row_count,col-1,float(row[col]),style)
            else:
                sheet.write(row_count,col-1,row[col],style)      
        #Increment row_count
        row_count += 1
  • 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-05-30T15:07:39+00:00Added an answer on May 30, 2026 at 3:07 pm

    Use iter(). Also, don’t iterate over the range(). Instead use enumerate(). And use the ternary operator, it helps to maintain DRY:

    for row_count, row in enumerate(csv_input):
        columns = iter(row)
        style = next(columns)
        for col_count, col in enumerate(columns, start=1):
            sheet.write(
                row_count,
                col_count,
                float(col) if is_number(col) else col,
                style
            )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.