问题标签 [xlsxwriter]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
652 浏览

python - Walking sub directories in Python and saving to same sub directory

First of all thanks for reading this. I am a little stuck with sub directory walking (then saving) in Python. My code below is able to walk through each sub directory in turn and process a file to search for certain strings, I then generate an xlsx file (using xlsxwriter) and post my search data to an Excel.

I have two problems...

The first problem I have is that I want to process a text file in each directory, but the text file name varies per sub directory, so rather than specifying 'Textfile.txt' I'd like to do something like *.txt (would I use glob here?)

The second problem is that when I open/create an Excel I would like to save the file to the same sub directory where the .txt file has been found and processed. Currently my Excel is saving to the python script directory, and consequently gets overwritten each time a new sub directory is opened and processed. Would it be wiser to save the Excel at the end to the sub directory or can it be created with the current sub directory path from the start?

Here's my partially working code...

Thanks again for looking at this problem.

MikG

0 投票
1 回答
3781 浏览

python - Python xlsxwriter 按列过滤并发布到另一个工作表

我认为我正在超越我业余 Python 知识的领域。我正在使用 xlsxwriter 过滤 txt 文件并获取围绕特定字符串匹配的数据。我将捕获的数据放入与 TIMESTAMP、STRING_MATCH_VALUE、VALUE1、VALUE2 的 4 列相关的 Excel 表中(如下表),我可以到这里。

输出表

我的下一个任务是尝试按 VALUE1 列过滤 Excel 工作表。这就是我的 Python 知识被延伸的地方。我希望过滤 -88.00 和 -88.99 以及 -89.00 和 -89.99 之间的范围,然后将过滤后的数据发布到 Excel 中的特定工作表。在阅读 xlsxwriter 文档后,我查看了 xlsxwriter 过滤并在下面生成了一些代码,但我认为我正在努力使用正确的措辞。任何提示将不胜感激。

0 投票
2 回答
679 浏览

python - 在 xlsxwriter 中设置 set_table() 的字体大小

我一直在寻找一种方法来设置由Python 包xlsxwriter中的set_table()生成的表中值的字体大小,但找不到这样做的方法。我创建了一个柱形图,并一直在尝试使用下面的代码设置字体大小,但我没有尝试过任何工作。

有没有人幸运地为柱形图下的表格中的值设置字体大小?任何帮助将不胜感激。谢谢你。

0 投票
1 回答
3235 浏览

python - 使用 xlsxwriter 从临时文件打开 excel 输出失败

我正在xlsxwriter使用模块创建一个 xlsx 输出到一个临时文件中tempfile,我将此临时文件的路径存储在一个变量中,稍后我会在另一个脚本中使用它来打开它。

问题是有时打开文件失败并出现错误:

抱歉,我对这个问题发生的频率没有确切的了解,但它似乎不时发生,所以我不明白为什么......

这就是我保存到临时文件中的方式:

然后创建 xlsx 输出:

然后在 Python CGI 脚本中,我使用变量 xlsxfilename 来打开它:

我在这里做错了什么以及关于如何通过使用另一种方法存储到临时文件中来解决这个问题的任何想法?

0 投票
1 回答
719 浏览

python - 用于创建新 Excel 工作簿并填充单元格的 Python 函数

我想编写一个 Python 函数,它将遍历 Excel 目录(os.walk),将该函数应用于每个文件,并使用_edit.xlsx' 扩展名('filename* _edit** .xlsx')。我正在使用 xlsxWriter。

这是我必须处理的。此代码一次只对一个文件执行我想要的操作,但我希望它适用于我的文件夹目录中的所有文件:

非常感谢。

0 投票
5 回答
2829 浏览

python - 将 Excel 文件文件夹转换为 CSV 文件/合并 Excel 工作簿

我有一个包含大量 Excel 工作簿的文件夹。有没有办法使用 Python 的 xlrd、xlutiles 和 xlsxWriter 将此文件夹中的每个文件转换为 CSV 文件?

我希望新转换的 CSV 文件具有扩展名“_convert.csv”。

否则...

有没有办法合并文件夹中的所有 Excel 工作簿来创建一个大文件?

我一直在寻找两种方法都可以做到,但没有任何效果......

0 投票
1 回答
1039 浏览

python - 如何在 xlswriter 中设置列​​宽并同时使用 autofulter 功能?

当我在 python 中使用 xlsxwriter 的自动筛选功能时,我的列宽设置不起作用。有办法吗?

0 投票
1 回答
20235 浏览

python - 使用 XlsxWriter 将熊猫图表插入 Excel 文件

我使用 python 3.4、pandas 0.14.1 和 XlsxWriter 0.5.6。我使用带有以下代码的熊猫创建了一个名为“图形”的图形

,这会产生一个漂亮的直方图。

现在,如何使用 XlsxWriter 将该图形插入 Excel 文件?

我尝试了 XlsxWriter 方法

但这会在 Excel 中创建一个图表,而不是我想要的。

谢谢

0 投票
1 回答
3254 浏览

python - 使用 Python 从 xlsx 文件中删除行

我有一个包含许多列的 xlsx 文件,但对于示例,我将只用两列来描述它:

我需要在period < 1403 or period > 1403.

所以这就是我想做的事情:

  1. 打开上面的xlsx文件
  2. 循环遍历所有列和行
  3. 将行复制 period < 1403 or period > 1403到新的 xlsxfile
  4. 关闭两个 xlsx 文件

我正在使用 xlsxwriter,这就是我设法从字典创建第一个 xlsx 文件的方式。

请问有什么想法吗?

0 投票
1 回答
157 浏览

python - Python 3.4 脚本挑战

我是一个只有 VBA 经验的非程序员。我接受了自动化公司中一些日常任务的挑战,并选择了 Python 3.4 来完成它(不确定是否是最佳选择)。

我需要做的脚本相当简单。他们只需要从 .txt 文件中读取值、执行计算并在 .xls 模板中写入值。

我在 stackoverflow 中阅读了一些主题并开始关注这两个主题:

  1. 有没有可行的方法在 excel 中写入数据(COM 自动化,Python 3 包)?

  2. 我可以将 Python 3.4 编译成 .exe 文件吗?用户不能在他们的桌面上安装东西。

我可以在 VBA 中编写这样的脚本,但我需要一个所有人都可以使用的可执行文件。