15.04.2013 Views

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

20 sleep(1)<br />

21 for i in RANGE:<br />

22 rng.InsertAfter('Line %d\r\n' % i)<br />

23 sleep(1)<br />

24 rng.InsertAfter("\r\nTh-th-th-that's all folks!\r\n")<br />

25<br />

26 warn(app)<br />

27 doc.Close(False)<br />

28 word.Application.Quit()<br />

29<br />

30 if __name__=='__main__':<br />

31 Tk().withdraw()<br />

32 word()<br />

The Word example follows pretty much the same script as the Excel example. The only difference is that<br />

instead of writing in cells, we have to insert the strings into the text "range" of our document and move<br />

the cursor forward after each write. We also have to manually provide the line termination characters of<br />

carriage RETURN following by NEWLINE (\r\n).<br />

If we run this script, a resulting screen might look like Figure 23-2.<br />

Figure 23-2. <strong>Python</strong>-to-Word demonstration script (word.pyw)<br />

23.2.4. Microsoft PowerPoint

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!