0

I want to concatenate two columns is excel and make it as a single column.

For example : column A=12 column B=778

The output should be column c=12778

please find the sample file in the attachment.

2
  • What does this have to do with Python? Just use concat or + and convert the cells to text. Commented May 10, 2018 at 13:41
  • please help me in achieving this condition with python. Commented May 13, 2018 at 7:46

1 Answer 1

1

Well you can use the xlwings package for this.

import xlwings as xw

sht = xw.apps[0].books[0].sheets[0]
sht.range('C1').value = int(str(sht.range('A1').options(numbers=int).value) + str(sht.range('B1').options(numbers=int).value))

This snippet will connect to the first active excel application's first worksheet on your system, then grabs the numeric values from cells A1 and B1, convert them to integers then to strings and concatenate them, and finally reconvert it to an integer and pass the final value to cell C1.

For further reference please visit the package documentation.

Hope it helps.

Sign up to request clarification or add additional context in comments.

4 Comments

can you please write a code without using xlwings package.
@kasi_VN in vanilla Python?
can u help me by using xlrd package.
i am a beginner in python, please tell me how to open and read excel and execute this operation with code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.