Member Avatar for dumicom

Hi, is there a simple way to convert the xls file to txt file to fit my program's code.

import matplotlib.pyplot as plt

x = []
y = []
t = []

fig = plt.figure()
rect = fig.patch

**readFile = open('data.xls', 'r')
sepFile ='\n')

for idx, plotPair in enumerate(sepFile):
    if plotPair in '. ':
       # skip. or space
    if idx > 1:  # to skip the first line
        xAndY = plotPair.split(',')
        time_string = xAndY[0]

ax1 = fig.add_subplot(1, 1, 1, axisbg='blue')
ax1.plot(t, y, 'c', linewidth=3.3)


There are python modules to read xls files (such as xlrd). However in your case, it may be easier to convert the file to csv on the command line: if you have Libreoffice installed on your computer, you can use

soffice --headless --convert-to csv data.xls

in a terminal to convert data.xls into data.csv. (In windows, the options with -- may take a single dash -). Make sure there is no data.csv before running the command!

The conversion command line above can also be called from python if you want.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.