我正在使用Python docx库来生成一个文档,我希望能够打开并找到拼写错误.但是当我打开文档时,没有任何拼写错误标记(小红色下划线)或者如果我确定进行拼写检查.如果我编辑一行或副本,将内容剪切并粘贴到单词中,拼写功能将按预期工作.
有没有办法让输出文档自动显示/识别输出文档中的拼写错误?我玩过"no_proof"标志,但似乎没有帮助.(在Windows框中使用64位Python 3.4,docx 8.6,在Word 2013中打开输出)
谢谢你的任何想法!
代码重现:
from docx import Document
document = Document()
paragraph = document.add_paragraph('This has a spellling errror')
document.save(r'SpellingTester.docx')
Run Code Online (Sandbox Code Playgroud)
我的问题是,当使用时tkFileDialog.askdirectory,为initialdir设置的目录总是突出显示,因为它应该是这样,但窗口仅在第一次向下滚动到它,任何后续打开的对话框都卡在顶部。这是一个可以尝试的最小示例:
import Tkinter, tkFileDialog, ttk
def get_dir():
global dir
dir = tkFileDialog.askdirectory(parent=root, initialdir=dir, title="Select directory")
dir = "c:/work/test" # Just enter any directory here that has to be reached by scrolling
root = Tkinter.Tk()
btn = ttk.Button(root, text="Open", command=get_dir)
btn.pack(side="left")
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
我使用的是 python 2.7 和 Windows 10,我不确定这个问题是普遍的还是特定于平台的,但如果有人见过类似的东西,我将不胜感激。
到目前为止我尝试过但不起作用的事情:设置固定的初始目录而不是最后打开的目录,用正斜杠替换反斜杠,反之亦然
根据要求,以下是所发生情况的屏幕截图:
这是第一次打开对话框时的样子,选择了初始目录,然后向下滚动到:
这是关闭对话框并再次打开它后发生的情况,initialdir 仍然被选中,但它滚动到顶部:
我遇到一个问题,在特定情况下,当我setVisibility(GONE)在自定义视图中onVisibilityChanged调用时,虽然此后getVisibility()返回8(或GONE),但它的方法没有被调用,并且实际上也没有隐藏视图。
这是我知道可见性更改但不调用onVisibilityChanged的方式。
@Override
protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
Log.i(LOG_TAG, "onVisibilityChanged: " + visibility);
super.onVisibilityChanged(changedView, visibility);
}
@Override
public void setVisibility(int visibility) {
super.setVisibility(visibility);
Log.i(LOG_TAG, "setVisibility: " + visibility);
}
public void hide(){
Log.i(LOG_TAG, "before hide visibility: " + getVisibility());
setVisibility(GONE);
Log.i(LOG_TAG, "after hide visibility: " + getVisibility());
}
Run Code Online (Sandbox Code Playgroud)
通常,当我打电话时,我会hide()在日志中看到以下几行:
隐藏前可见度:0
onVisibilityChanged:8
setVisibility:8
隐藏后可见度:8
但是在一个特殊的情况下,当我打电话时,我hide()在日志中得到了这些行,尽管getVisibility()返回了8:
隐藏前可见度:0
setVisibility:8
隐藏后可见度:8
那么,通常何时会发生这种情况?什么时候setVisibility …
我\xe2\x80\x99m 试图完成的任务:
\n\n问题:
\n\n我可以使用非 CTL 语言(例如英语)来执行此操作:
\n\nfrom docx import Document\nfrom docx.enum.style import WD_STYLE_TYPE\nfrom docx.shared import Pt\n\nuser_font_name = 'FreeMono'\nuser_font_size = 14\n\ndoc = Document()\nmy_style = doc.styles.add_style('style_name',WD_STYLE_TYPE.PARAGRAPH)\nmy_font = my_style.font\nmy_font.name = user_font_name\nmy_font.size = Pt(user_font_size)\np = doc.add_paragraph('some text',my_style)\n\n# persian_p = doc.add_paragraph('\xd9\x86\xd9\x88\xd8\xb4\xd8\xaa\xd9\x87',my_style)\n# FreeMono supports Persian language so the problem is not the font\n\ndoc.save('file.docx')\nRun Code Online (Sandbox Code Playgroud)但是,如果我将文本更改为波斯语文本,其字体将\xe2\x80\x99t 更改为指定字体。
为什么会发生这种情况:
\n\n我怎么知道这一点:
\n\n当我复制一些文本并粘贴(crtl + v)它在一个tkinter条目中,如果有选定的文本,它将不会从条目中删除它.我在Linux(Mint)64位.
第一:我想知道这是一个特定于Linux的错误还是它应该是怎么回事?
第二:我正在考虑解决此问题,validatecommand但我遇到了另一个问题:
如果我要删除命令中的选定文本,我必须知道条目中的选择索引.否则,如果在光标之前和之前有所选文本的多个实例,我将不知道要删除哪一个并用新文本替换.因为光标可能位于选择的任一侧(取决于人是否在文本上从右向左或从左向右拖动鼠标).
现在有没有办法获得条目中的选择索引?或解决此问题的其他方法?
以下是一些代码示例:
import tkinter as tk
root = tk.Tk()
def validation(after_text, before_text, validation_text, cursor_index):
cursor_index = int(cursor_index)
print('cursor index:', cursor_index)
print('text after change:', after_text)
print('text before change:', before_text)
print('text in need of validation:', validation_text)
try:
selection = root.selection_get()
except:
selection = ''
print('selection:', selection)
# EXAMPLE:
# validation_text = 'd'
# before text = "bb"
# now if someone dragged …Run Code Online (Sandbox Code Playgroud) python ×3
python-docx ×2
tkinter ×2
android ×1
docx ×1
linux ×1
python-2.7 ×1
python-3.x ×1
windows ×1