1

All I could find was about paragraphs as wholes (as it seems). Tried to use the solution anyway, but there was an error ("AttributeError: .runs").

I looked into python-docx documentation, but I don't know how to apply that information here.

My paragraphs have italicized words and possibly parts of words. What (I think) I need is a loop that checks if characters are italicized.

import win32com.client as win32
word = win32.Dispatch("Word.Application")
word.Visible = 0
word.Documents.Open("C:**path**.docx")
doc = word.ActiveDocument

doc.Tables.Count

table = doc.Tables(1)   

index = list(range(0, 1000))

for i in index: 
    s = table.Cell(Row =i, Column =1).Range.Text  
    # now another loop, using 'run' object?
Community
  • 1
  • 1
Tag
  • 51
  • 1
  • 9

1 Answers1

0

I am not familiar with docx, but maybe you have a version problem.

The documentation you linked in your question is for python-docx 0.8.5.

On pypi there is a docx module, which seems to be outdated as the highest available version is 0.2.4.

There is another module called python-docx, which looks more recent (versions up to 0.8.5).

If you used pip to install docx, you can update to python-docx, which should give you the newest version:

> pip uninstall docx
> pip install python-docx
MB-F
  • 22,770
  • 4
  • 61
  • 116
  • I have python-docx installed, too. 0.8.5. Can an outdated docx module interfere with python-docx? – Tag Jan 04 '16 at 14:21
  • I think so. They use the same module name - I'm not sure which of them is loaded on runtime, or maybe they overwrite each other on installation. Best remove the old one and reinstall python-docx. – MB-F Jan 04 '16 at 14:25
  • Yes. The two will interfere with each other because they share the same module name ("docx"), even though they have different package names ("python-docx" vs "docx"). Which one you get when you `import ... from docx` may depend on the order in which they were installed, but in any case is a crap shoot. In general, python-docx is a new version of the legacy docx package, but is a complete rewrite (object-oriented) and the two APIs are not compatible (not even a little bit :). – scanny Jan 06 '16 at 19:29