0

this is my code and my excel sheet has 1000 rows and 22 columns of data. i want to convert excel to text file. but when i run this, i only get first and line 5 rows and columns of data? how to solve this issue

import pandas as pd
xlsFile = pd.ExcelFile(r'C:/Users/vivek/OneDrive/Desktop/College Project/modules/spreadSheetManipulation/sample.xlsx')
totalPages= xlsFile.sheet_names
with open(r'C:/Users/vivek/OneDrive/Desktop/College Project/modules/spreadSheetManipulation/output.txt','w') as textFile:
    for page in totalPages:
        dataFrame = xlsFile.parse(page)
        textFile.write("\nSheet name is:"+page+"\n")
        textFile.write(str(dataFrame))
        textFile.write('\n')
Edward
  • 150
  • 1
  • 4

1 Answers1

0

You could try something like this

import pandas as pd

with open(r'C:/Users/vivek/OneDrive/Desktop/College Project/modules/spreadSheetManipulation/sample.xlsx', 'w') as file:
    pd.read_excel(r'C:/Users/vivek/OneDrive/Desktop/College Project/modules/spreadSheetManipulation/output.txt').to_string(file, index=False)

code pulled from: Convert .xlsx to .txt with python? or format .txt file to fix columns indentation?

Edward
  • 150
  • 1
  • 4