docx

Open a Word Document Using Python [duplicate]

夙愿已清 提交于 2021-02-04 22:16:10
问题 This question already has answers here : Open document with default OS application in Python, both in Windows and Mac OS (13 answers) Closed 2 years ago . I am trying to automatically open a Word Document in Python. I am very new to programming and I heard this site helped people who had trouble with it. I have looked at various questions and have found this: DummyFile = path_to_docx with open(DummyFile) as f: source_stream = io(f.read()) document = doc(source_stream) source_stream.close()

【C#】异步的用法

拈花ヽ惹草 提交于 2021-02-04 02:39:23
1. C#5.0 加入了async, await关键字. async 是在声明异步方法时使用的修饰符, 声明放在返回值之前即可, await 表达式则负责消费异步操作, 不能出现在catch或finally块, 非异步匿名函数(没有用async声明的匿名方法或者lambda表达式), lock语句或不安全的代码中使用。 ps:这些约束条件是为了保证安全,特别是关于锁的约束。如果你希望在异步操作完成时持有锁,那么应该重新设计你的代码。不要通过在 try/finally 块中手动调用 Monitor.TryEnter 和 Monitor.Exit 的方式绕过编译器的限制,而应该实现代码的更改,这样在操作过程中就不再需要锁了。如果此时的情况不允许代码的改变,则可考虑使用 SemaphoreSlim 和它的 WaitAsync 方法来代替。 2. 所有用async修饰的异步方法, 参数都不可以使用out 或者 ref 修饰符. 返回值必须是void, task, task<T>. 一般为task. 因为可以让调用者监控异步操作的状态. 3. await的主要目的是在等待耗时操作完成时避免阻塞。代码总是在执行到await的时候就开始返回了, 并且到达await之后会校验结果是否存在 如果结果不存在, 会安排给一个后续操作, 这个后续操作会记录位置,状态, 然后代码回到UI主线程继续运行,

Change font style in a specific word from docx file using Java Apache POI

安稳与你 提交于 2021-01-29 07:11:16
问题 I'm using Apache POI XWPF to manipulate a docx file, I need to update some words of paragraph and change the font style of it. For updating a single word, it's ok, let's assume that my docx content has the paragraphs bellow: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer pretium sodales nisl, ut ornare ligula vehicula vitae. Fusce non magna feugiat, sagittis massa at, fermentum nibh. Curabitur auctor leo vitae sem tempus, facilisis feugiat orci vestibulum. Mauris molestie

Frame around inline images

て烟熏妆下的殇ゞ 提交于 2021-01-28 23:44:44
问题 Is there a way to put frames around inline images with python docx ? I have something like: from docx import Document from docx.shared import Mm document = Document() table = document.add_table(rows=1, cols=3) pic_cells = table.rows[0].cells paragraph = pic_cells[0].paragraphs[0] run = paragraph.add_run() run.add_picture('testQR.png', width=Mm(15), height=Mm(15)) document.save('demo.docx') I need to put a frame around the image to mark the border of this image (that should be identical with

Edit CustomXML with OpenXML C#

蓝咒 提交于 2021-01-28 22:50:26
问题 This is my first OpenXML project. I am trying to edit the CustomXML file of a docx file. I am trying to change this: <?xml version="1.0" encoding="UTF-8"?> <PERSON> <NAMETAG>NAME</NAMETAG> <DOBTAG>DOB</DOBTAG> <SCORE1TAG>SCORE1</SCORE1TAG> <SCORE2TAG>SCORE2</SCORE2TAG> </PERSON> To this: <?xml version="1.0" encoding="UTF-8"?> <PERSON> <NAMETAG>John Doe</NAMETAG> <DOBTAG>01/01/2020</DOBTAG> <SCORE1TAG>90.5</SCORE1TAG> <SCORE2TAG>100.0</SCORE2TAG> </PERSON> I would prefer to not use search and

Apache docx CreateWatermark Set font in text oR CTTextPath setstyle remove double/single quotes

夙愿已清 提交于 2021-01-28 19:05:00
问题 I am using the code from here by extending this calss https://svn.apache.org/viewvc/poi/tags/REL_3_17_FINAL/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java?view=markup#l416 COde from this : CTTextPath shapeTextPath = shape.addNewTextpath(); shapeTextPath.setStyle("font-family:"Cambria";font-size:1pt"); Tried various combination and permutation but in the end in xml it removes it and prints like : <v:textpath style="font-family:Cambria;font-size:1pt" string="test"/> Any

Python auto-numbering in headings to text [docx files]

a 夏天 提交于 2021-01-28 02:28:18
问题 I'm trying to find a way to convert headings' auto-numbering to text In MS Word's VBA it is just: Sub Test() ActiveDocument.Range.ListFormat.ConvertNumbersToText End Sub but how about Python 3.x? 回答1: Python-docx has the styles attribute. Documentation and examples of use here: http://python-docx.readthedocs.io/en/latest/user/styles-using.html 来源: https://stackoverflow.com/questions/49194396/python-auto-numbering-in-headings-to-text-docx-files

How to write a CSV table to docx using python

倖福魔咒の 提交于 2021-01-28 01:01:52
问题 I have a CSV file like the following one: user,password,company Administrator, 123456, test_company test_user1, abcdf, test_company1 test_user2, 789, test_company2 This should be a table with user , password and company as headers. How can I write this structure as a table in a docx file using python? 回答1: import docx import csv doc = docx.Document() with open('csv.csv', newline='') as f: csv_reader = csv.reader(f) csv_headers = next(csv_reader) csv_cols = len(csv_headers) table = doc.add

微软发布了免费的文件恢复工具!

寵の児 提交于 2021-01-27 11:22:34
误删文件这事相信大家都碰到过,比如不小心误删了一个重要的文件,一不留神就把自己的硬盘清空了,或者是面对已经被误删的文件手足无措......以前碰到这种情况,有实力的程序员们就靠实力恢复误删的文件,像猿妹这样没实力的,网上购买个小工具也可以帮我恢复,就是费钱。 现在好了,最近微软在 Windows 10 应用商店中上架了一款免费的数据删除恢复工具 Windows File Recovery,猿妹再也不用担心误删文件了。 Windows File Recovery基于命令行程序设计,大小仅有8.26MB,所有Windows 10用户均可免费下载使用。 无论是照片、文档、视频还是其他,Windows File Recovery都可以帮你恢复,而且它还支持机械硬盘、固态硬盘、U盘、SD卡等多种硬件类型,遗憾的是,不支持网络驱动器文件恢复。 下面还是一起来看看用法吧: 嵌入式专栏 1 下载安装 首先,通过下载链接打开“Windows File Recovery”的下载界面,点击“获取”按钮安装。(下载地址:https://www.microsoft.com/zh-cn/p/windows-file-recovery/9n26s50ln705?activetab=pivot:overviewtab) 这里需要提醒大家的是,安装Windows File Recovery操作系统要求Windows

根据word模板(书签)创建导出word

假装没事ソ 提交于 2021-01-25 07:46:51
/// <summary> /// 根据word模板(书签)创建word-导出 /// </summary> /// <param name="context"></param> public void export_Word(HttpContext context) { string templatePath = context.Server.MapPath( " ../../../模板.docx " ); // word模板位置 Document doc = new Document(templatePath); // 循环书签 foreach (Bookmark mark in doc.Range.Bookmarks) { if (mark != null ) { switch (mark.Name) { case " UserName " : mark.Text = " 饶哈哈 " ; break ; case " Sex " : mark.Text = " 男 " ; break ; case " Photo " : DocumentBuilder builder = new DocumentBuilder(doc); string imgPath = context.Server.MapPath( " /Admin/666.jpg " ); // 图片地址 if