Tag: xlwt

在python(xlwt)中设置excel列样式

我正在尝试将数据写入Excel文档,其中一些列完全由我想格式化的date/数字数据组成。 我可以分别在每个单元格上设置一个格式,但似乎过多。 对象列上有一个set_style方法,但由于某种原因,它似乎没有做任何事情。 import xlwt from datetime import date book = xlwt.Workbook('ascii') sheet = book.add_sheet('Sheet1') # cells in first column, they end up with no formatting sheet.write(0, 0, date(2012, 1, 1)) sheet.write(1, 0, date(2012, 1, 1)) sheet.write(2, 0, date(2012, 2, 1)) style = xlwt.easyxf(num_format_str='YYYY-MM-DD') sheet.col(0).set_style(style) # cells in second column are formatted correctly sheet.write(0, 1, […]

复制的Excel单元格值在另一个打印时不占用百分比值

我面临的问题,而从Excel复制单元格的价值和打印到另一个Excel不占百分比值。 就像我擅长的单元格值是这样的: | 22.13% | 22.10% | 23.34% | 现在,当复制单元格值并在另一个excel中打印时,它显示: | .221 | .221 | .233 | m=1 for rownum in range(1,sheetIO.nrows): data = [str(sheetIO.cell_value(rownum, col)) for col in range(sheetIO.ncols)] ## here is the prob it is calculating and taking the value if data[1]== '': newDataArr = data[0].replace (" ", "_") else: k=1 if data[0] […]

使用xlutils xlwt复制工作簿

是否有可能复制macros启用excel工作簿? 例如,我有: from xlutils.copy import copy from xlrd import open_workbook from tempfile import TemporaryFile book = open_workbook("book.xlsm") book_copy = copy(book) book_copy.save("bookcopy.xlsm") book_copy.save(TemporaryFile()) 但是,当我点击bookcopy.xlsm打开它,我得到以下错误:“Excel无法打开文件'bookcopy.xlsm',因为文件格式或文件extesion无效。确认文件没有损坏,文件扩展名匹配文件的格式“。 我保存的时候没有得到这个错误是“bookcopy.xls”,但是我需要它是.xlsm。 有没有人有一个想法是什么问题?

使用xlwt写入XLS文件时,权限被拒绝错误

我在Python中使用xlwt包来创build一个工作簿,在excel工作表的单元格中写入表格数据。 最后,我将工作簿保存为一个现有的文件名(比如说List_Of_Animals.xls)。 如果该文件已经在某人的计算机上打开(这是一种可能性,因为我们的客户可能经常忘记closures他们正在查看的Excel表格),python脚本失败,说缺less写入权限。 没有办法覆盖文件,即使它通过删除锁打开某处? 我们可以用xlwt来做这个吗? 注意:代码在Windows计算机上运行,​​客户主要使用Windows计算机。 (如果需要的话,提供这些信息)

通过python脚本在excel中调整单元格宽度和高度,单位为mm / cm

我试图find它,但找不到一个。 是否有可能使用openpyxl或xlwt模块来调整excel中单元格的宽度和高度,单位是mm或cm? 如果是的话可以有人指向我的脚本命令? 非常感谢。

Python – 从嵌套循环只打印一次

我有一个excel文件,看起来像这样: col1 col2 col3 col4 —————————– row1 | 2,3,1 _ 1 w row2 | 3,2,7 _ 2 x row3 | _ _ 3 y row4 | 4,9 _ 4 z 我在第2列写了一些值(使用XLWT),如下所示: col1 col2 col3 col4 —————————– row1 | 2,3,1 x,y,w 1 w row2 | 3,2,7 y,x 2 x row3 | _ _ 3 y row4 […]

Python XLWT外键值

我正在导出数据库字段为Excel文件,一切正常,但我的外键字段被打印为外键ID而不是实际值。 我该如何解决? 这里是我的代码: book = xlwt.Workbook(encoding='utf8') sheet = book.add_sheet('Expense summary', cell_overwrite_ok=True) header_style = xlwt.easyxf('font:height 280, color blue, bold 1; border: bottom thick;') sum_style = xlwt.easyxf('font:height 200, color green, bold 1; border: top thick;') date_style = xlwt.XFStyle() date_style.num_format_str = 'DD-MM-YYYY' currency_style = xlwt.XFStyle() currency_style.num_format_str = '#,##0.00' xls_values = expense.filter( user=request.user.id).values_list('date', 'amount', 'towho', 'forwhat', 'category', 'payment_method') headers […]

尝试使用Python xlwt保存Excel文件时的UnicodeDecodeError

我正在运行一个Python脚本,将使用BeautifulSoup发现的HTML代码写入Excel电子表格列的多行。 […] Col_HTML = 19 w_sheet.write(row_index, Col_HTML, str(HTML_Code)) wb.save(output) 当试图保存文件时,我得到以下错误信息: Traceback (most recent call last): File "C:\Users\[..]\src\MYCODE.py", line 201, in <module> wb.save(output) File "C:\Python27\lib\site-packages\xlwt-0.7.5-py2.7.egg\xlwt\Workbook.py", line 662, in save doc.save(filename, self.get_biff_data()) File "C:\Python27\lib\site-packages\xlwt-0.7.5-py2.7.egg\xlwt\Workbook.py", line 637, in get_biff_data shared_str_table = self.__sst_rec() File "C:\Python27\lib\site-packages\xlwt-0.7.5-py2.7.egg\xlwt\Workbook.py", line 599, in __sst_rec return self.__sst.get_biff_record() File "C:\Python27\lib\site-packages\xlwt-0.7.5-py2.7.egg\xlwt\BIFFRecords.py", line 76, in get_biff_record self._add_to_sst(s) File […]

Python循环不工作(xlwt)

我在Python中有这段代码,应该工作。 python import xlwt #== change variables according to requirements ==# numoftopcol = 5 numoftestcases = 4 coltext = ['Test Case', 'Test Name', 'Duration', 'Factual Result', 'Result (Pass/Fail)'] testN = ['void','Get Counter Result', 'Read Stats', 'Client Initialization', 'Start Server'] #== change variables according to requirements ==# styleH = xlwt.easyxf('font: name Arial, bold on, color-index blue;') […]

Python:如何读取多个文件夹中的所有文本文件内容,并将其保存到一个Excel文件中

我目前正在做这个任务,并陷入困境。 请给我你的build议。 我在下面写的代码,它只返回多个文件夹中的.txt文件名,而我想打印出每个.txt文件的内容并保存在不同的行中。 每个.txt文件的内容都是数字。 import os, glob,xlwt #create workbook and worksheet wbk = xlwt.Workbook() sheet = wbk.add_sheet('data') path= 'E:\Cag\Data' row = 0 for dir,subdir,files in os.walk(path): for file in files: if glob.fnmatch.fnmatch(file, '*.txt'): L = file.strip() sheet.write(row,5,L) row += 1 wbk.save('read_all_txt_in_folders.xls') print 'success'