搜集的一些关于win32com.client操作office的相关用法

#创建

#word
w = win32com.client.Dispatch("Word.Application")
w = win32com.client.DispatchEx("Word.Application")#使用启动独立的进程 #excel
xlApp = win32com.client.Dispatch("Excel.Application") #后台运行, 不显示, 不警告
w.Visible = 0;
w.DisplayAlerts = 0; #打开新的文件 #word
doc = w.Documents.Open(FileName)
#new_doc = w.Documents.Add() #创建新的文档 #excel
xlBook = xlApp.Workbooks.Open(FileName)
#new_xlBook = xlApp.Workbooks.Add() #创建新的工作簿 #插入文字 #word
myRange = doc.Range(0, 0)
myRange.InsertBefore("hello from Python") #excel #使用样式
wordStyle = myRange.Select()
wordStyle.Style = constants.wdStyleHeading1 #正文文字替换
w.Selection.Find.ClearFormatting()
w.Selection.Find.Replacement.ClearFormatting()
w.Selection.Find.Execute(OldStr, False, False, False, False, False, True, 1, True, NewStr, 2) #表格操作 #word
doc.Tables[0].Rows[0].Cells[0].Range.Text = "hello world Python"
worddoc.Tables[0].Rows.Add() #增加一行 #excel #获取
_sheet = xlBook.Worksheets(sheet)
_sheet.Cell(row, col).Value #设置
_sheet = xlBook.Worksheets(sheet)
_sheet.Cells(row, col).Value = values #范围操作
_sheet = xlBook.Worksheets(sheet)
_sheet.Range(_sheet.Cell(row1, col1), _sheet.Cell(row2, col2)).Value #添加图片 #excel
_sheet = xlBook.Worksheets(sheet)
_sheet.Shapes.AddPicture(picturename, 1, 1, Left, Top, Width, Height) #copy 工作簿 sheets = xlBook.Worksheets
sheets(1).Copy(None, sheets(1)) #转换为html #word
wc = win32com.client.constants
w.ActiveDocument.WebOptions.RelyOnCSS = 1
w.ActiveDocument.WebOptions.OptimizeForBrowser = 1
w.ActiveDocument.WebOptions.BrowserLevel = 0 # constants.wdBrowserLevelV4
w.ActiveDocument.WebOptions.OrganizeInFolder = 0
w.ActiveDocument.WebOptions.UseLongFileNames = 1
w.ActiveDocument.WebOptions.RelyOnVML = 0
w.ActiveDocument.WebOptions.AllowPNG = 1
w.ActiveDocument.SaveAs(FileName, FileFormat = wc.wdFormatHTML) #打印
doc.PrintOut() #保存 #excel
xlBook.SaveAs(FileName)#另存为
xlBook.Save() #关闭 #word
#doc.Close()
w.Documents.Close(wc.wdDoNotSaveChanges)
w.Quit() #excel
xlBook.Close(SaveChange = 0)
xlBook.Quit()

python win32com.client的更多相关文章

  1. [转]Python中出错:ImportError: No module named win32com.client

    Python中出错:ImportError: No module named win32com.client [问题] [已解决]Python中处理操作Excel中的图表(Chart,Graph) 的 ...

  2. Python: 读写Excel(openpyxl / win32com.client)

    项目周报汇报的时候要做数据汇总,总是要从不同的excel文件中去获取数据最后汇总到一个excel表里面,所以决定用python直接写个自动化脚本来自动执行. 用python来读写excel,目前找了2 ...

  3. Python 3中,import win32com.client 出错

    在 import win32com.client 时,出现了界面: Traceback (most recent call last): File "<pyshell#1>&qu ...

  4. python调用win32com.client的GetObject查找进程信息及服务信息

    为何不用wmi呢?因为执行很慢,为啥不用winreg?因为winreg在批量获取及遍历服务方面很不方便,于是采用这方法 该方法同命令行下的wmic执行 获取服务信息 #coding=utf8 from ...

  5. 线程中调用python win32com

    在python的线程中,调用win32com.client.Dispatch 调用windows下基于COM组件的应用接口, 需要在调用win32com.client.Dispatch前,调用pyth ...

  6. Python win32com模块 合并文件夹内多个docx文件为一个docx

    Python win32com模块 合并文件夹内多个docx文件为一个docx #!/usr/bin/env python # -*- coding: utf-8 -*- from win32com. ...

  7. python win32com

    要使用Python控制MS Word,您需要先安裝win32com套件,這個套件可以到 http://sourceforge.net/projects/pywin32/ 找到.本文假設您已經正確安裝w ...

  8. Python~win32com~Excel

    import win32com.client #w=win32com.client.Dispatch("Word.Application") #w.Visible=1 o=win3 ...

  9. mac虚拟机搭建自动化环境-wda和python wda client

    尽量升级Xcode到最新版,保持iPhone的版本大于9.3 1.安装webDriverAgent到ios真机 从github上下载代码:git clone https://github.com/fa ...

随机推荐

  1. R语言最优化(多维)

    线性搜索的最速上升法 #### max.search <- function(f, x, y, tol=1e-9, a.max = 2^5){ if(sum(abs(y)) == 0) retu ...

  2. 固定div的位置——不随窗口大小改变为改变位置

    百度首页示例: 我给二维码,和下面文本固定位置 这时html代码 <div id="bar_code"> <div class="img_put&quo ...

  3. Java String 常量池理解

    String:字符串常量池 作为最基础的引用数据类型,Java 设计者为 String 提供了字符串常量池以提高其性能,那么字符串常量池的具体原理是什么,我们带着以下三个问题,去理解字符串常量池: 字 ...

  4. spring cloud 随笔记录(1)-

    最近随着微服务的火热,我也开始对我服务进行了解了  毕竟程序员这一行需要及时更新自己的技能,才能更好的生存. 我理解的微服务  项目由多个独立运行的程序组成,每个服务运行在自己的进程中,服务间采用轻量 ...

  5. 介绍一下Spring Cloud简介

    Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智能路由,微代理,控制总线).分布式系统的协调导致了样板模式, 使用Spring Clo ...

  6. SoapUI--the use of Script Library

    SoapUI--the use of Script Library 有两种方法在soapUI中引用自己的groovy脚本库. 方法一:把自己的script folder放到soapUI install ...

  7. L1-037 A除以B (10 分)

    题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805094485180416   真的是简单题哈 —— 给定两个 ...

  8. Problem A: 字符的变化

    Description 定义一个Character类,具有: 1. char类型的数据成员. 2.构造函数Character(char). 3. Character toUpper():如果当前字符是 ...

  9. python+appium 自动化2--元素定位uiautomatorviewer

    出处:https://www.cnblogs.com/yoyoketang/p/6128741.html 前言: 可以打开手机上的app了,下一步元素定位uiautomatorviewer,通过定位到 ...

  10. javascript 飞机大战完整代码

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...