开发者

excel printing in to different column

开发者 https://www.devze.com 2023-03-29 18:31 出处:网络
import xlrd import os path = \"data\" dirList=os.listdir(path) f = open(\'\', \'w\') f.write(\'\') f.write(\"\\n\")
import xlrd
import os

path = "data"
dirList=os.listdir(path)
f = open('', 'w')
f.write('')
f.write("\n")

for file in dirList:
    fullpath = os.path.join(path,file)
    if os.path.isfile(fullpath) == 1:
        wb = xlrd.open_workbook(fullpath)
        wb.sheet_names()
        sh = wb.sheet_by_name(u'')

        for j in range(0,sh.nrows):
            f.write(str(sh.cell(j,0).value))
            f.write(", ")
            f.write("\n")
            f.write(str(sh.cell(j,1).value))
            f.write(", ")
        f.write("\n")

This is the Script I have so far. I'm sorry about the last two questions. So I have excel files that have data values(numbers) under fist column labeled x and second column labeled y. 10 of these excel files are saved in a folder called RawTrack. I'm trying to take the x and y values from all of the files and print it to a single excel file(x_y_z_value.xls). So I'm having trouble printing all of the x files in the first column and all of the y values in the second column. Thanks开发者_开发问答


I think only a slight modification is required. You are putting a newline in between the x, y values that does not need to be there. This should produce rows with x, y.

    for j in range(21,sh.nrows):
        f.write(str(sh.cell(j,0).value))
        f.write(", ")
        f.write(str(sh.cell(j,1).value))
        f.write("\n")
0

精彩评论

暂无评论...
验证码 换一张
取 消