当前位置: 首页 > news >正文

农业网站建设模板昆明seo

农业网站建设模板,昆明seo,wordpress插件破解下载,南京软件外包公司win32com库基于wps对Word文档的基础操作 文章目录 win32com库基于wps对Word文档的基础操作新建/打开文档段落操作(Paragraph)字体设置(Font)图表操作(Shape) 参考链接: WAS API手册 新建/打开文档 import win32com import win32com.client as win32 # 启动WPS进程 word_obj …

win32com库基于wps对Word文档的基础操作

文章目录

    • win32com库基于wps对Word文档的基础操作
      • 新建/打开文档
      • 段落操作(Paragraph)
      • 字体设置(Font)
      • 图表操作(Shape)

参考链接: WAS API手册

新建/打开文档

import win32com
import win32com.client as win32
# 启动WPS进程
word_obj = win32.gencache.EnsureDispatch('KWPS.Application')
word_obj .Visible = 1
# 打开文件
dst_file = "你的文档路径"
dst_doc = word_obj.Documents.Open(dst_file)
# 新建文档 返回一个空白文档对象
dst_doc = word_obj.Documents.Add(dst_file)

段落操作(Paragraph)

# Paragraphs 返回所选内容、范围或文档中所有的段落的集合
# 获取全部段落
dst_Paragraphs = dst_doc.Paragraphs
# 获取第1段
dst_Paragraph = dst_doc.Paragraphs(1)# 段落方法
dst_Paragraph.Delete() # 删除段落dst_Paragraph.Select() # 选中段落# 设置段落水平对齐方式为居中对齐 其余对齐方式参考官方文档中的枚举变量 WdParagraphAlignment
dst_Paragraph.Alignment = 1# 设置段落垂直对齐方式为中心对齐 其余对齐方式参考官方文档中的枚举变量 WdBaselineAlignment
dst_Paragraph.BaseLineAlignment = 1# 设置段落段前、段后间距
dst_Paragraph.LineUnitBefore= 1 # 段前 单位 行
dst_Paragraph.LineUnitAfter = 1 # 段后 单位 行
dst_Paragraph.SpaceBefore = 12 # 段前 单位 磅
dst_Paragraph.SpaceAfter = 12 # 段后 单位 磅# 设置段落大纲级别 # 若段落样式为标题样式,则无法修改
dst_Paragraph.OutlineLevel = 1# 段落左缩进和右缩进
dst_Paragraph.CharacterUnitLeftIndent = 0 # 左缩进 单位 字符
dst_Paragraph.CharacterUnitRightIndent = 0 # 右缩进 单位 字符
dst_Paragraph.LeftIndent = 0 # 左缩进 单位 磅
dst_Paragraph.RightIndent = 0 # 右缩进 单位 磅# 段落首行缩进、悬挂缩进 为正值时表示首行缩进,负值时表示悬挂缩进
dst_Paragraph.CharacterUnitFirstLineIndent = 2 #单位 字符
dst_Paragraph.FirstLineIndent = 12 #单位 磅# 设置段落行距为单倍行距 其余行距类型参考官方文档中的枚举变量 WdLineSpacing
dst_Paragraph.LineSpacingRule = 0# 若设置段落行距类型为固定值或多倍行距时 需要单独设置 LineSpacing属性
dst_Paragraph.LineSpacing = 12 # 其中一行等于12磅 或者使用 word_obj.LinesToPoints(1)进行计算
'''
WPS中各单位转换为磅值关系及方法如下:
1行 = 12磅 LinesToPoints()
1cm = 28.35磅 CentimetersToPoints()
1毫米 = 2.85磅 MillimetersToPoints()
1英寸 = 72磅 InchesToPoints()
像素 --> 磅 PixelsToPoints()
'''

字体设置(Font)

Paragraph = dst_doc.Paragraphs(1) # 获取第一段
'''
Range 表示对象在word文档中的连续区域
'''
# 设置段落字体中文样式
Paragraph.Range.Font.NameFarEast = "楷体_GB2312" # 设置中文字体
# 设置段落字体英文样式 其余样式详见开发文档
Paragraph.Range.Font.Name = "Times New Roman"
# 复杂文本
Paragraph.Range.Font.NameAscii = "Times New Roman"
# 设置字体大小
Paragraph.Range.Font.Size = 18 # 单位 磅 小二为18磅
# 设置字号
Paragraph.Range.Font.SizeFarEast = 3 #设置字体为3号# 字体加粗
Paragraph.Range.Font.Bold = True
# 字体倾斜
Paragraph.Range.Font.Italic = True
# 设置字符间距
Paragraph.Range.Font.Spacing = 1

图表操作(Shape)

# 获取第一个图表对象
dst_shape= dst_doc.Shapes(1)
# 设置大小
dst_shape.Height = 128 # 高
dst_shape.Width = 128 # 宽# 设置文字环绕
dst_shape.WrapFormat.Type = win32com.client.constants.wdWrapSquare  # 四周型 (wdWrapSquare)
dst_shape.WrapFormat.Side = win32com.client.constants.wdWrapBoth  # 环绕文字两边
# 设置四周边距
dst_shape.WrapFormat.DistanceTop = 0  # 上:0厘米
dst_shape.WrapFormat.DistanceBottom = 0  # 下:0厘米
dst_shape.WrapFormat.DistanceLeft = self.word.CentimetersToPoints(0.32)  # 左:0.32厘米
dst_shape.WrapFormat.DistanceRight = self.word.CentimetersToPoints(0.32)  # 右:0.32厘米
# 设置位置为页边距
dst_shape.RelativeHorizontalPosition = 0  # 1代表页边距
dst_shape.RelativeVerticalPosition = 0  # 1代表页边距
dst_shape.Top = 0
dst_shape.Left = 0
dst_shape.WrapFormat.AllowOverlap = False # 不允许重叠
嵌入式图表操作(InlineShape)
表格处理(Table、Row、Column、Cell)
dst_table = dst_doc.Tables(1)
# 获取行|列数
row_count = dst_table.Rows.Count
col_count = dst_table.Columns.Count
# 设置行高 单位 磅
dst_table.Rows(1).Height = 20
# 设置列宽
dst_table.Columns(1).Width = 20
# 设置表格的所有行的行高
dst_table.Rows.Height = 20# 设置单个单元格的宽高 PS设置时会自动修改其所在行和列的行高和列宽
dst_table.Cell(1,1).Height = 20
dst_table.Cell(1,1).Width = 20# 设置表格文本样式
dst_table.Cell(1,1).Range.Text = "设置文本"
# 设置字体样式(其余属性请参考Font设置)
dst_table.Cell(1,1).Font.Name = ""
# 调整单元格边距
dst_table.Rows(1).TopPadding = 20 # 上边距
dst_table.Rows(1).BottomPadding = 20 # 下边距
dst_table.Rows(1).LeftPadding = 20 # 左边距
dst_table.Rows(1).RightPadding = 20 # 右边距
http://www.hrbkazy.com/news/52963.html

相关文章:

  • wordpress 电影网站苏州seo培训
  • 动态网站建设的一般步骤志鸿优化设计答案网
  • 求国外做任务赚钱的网站有哪些谷歌seo公司
  • 手机网站制作服务大泽山seo快速排名
  • 洛阳响应式建站seo优化与sem推广有什么关系
  • 漯河做网站哪家好网络推广应该怎么做啊
  • 公司做网站需要哪些手续南宁市优化网站公司
  • 做网站挣钱么百度站长平台有哪些功能
  • wap网站e4a做app谷歌外贸网站
  • 网站seo诊断湖南岚鸿诊断seo技术优化技巧
  • 自己可以做公司网站吗百度扫一扫入口
  • 建设网站需求百度一下你就知道移动首页
  • 做海报免费素材网站有哪些比百度强大的搜索引擎
  • 网站建设 小影seo宁波seo高级方法
  • 一个互联网公司可以做几个网站娄底地seo
  • 建站工具有哪些cms杭州网站提升排名
  • 韶关网站建设搜索引擎优化工具
  • 婚恋网站 模板怎么申请自己的域名
  • 兰州网站制作速推网
  • 美国母鸡服务器租用企业网站优化方案
  • 网站开发是怎么样的关键词排名优化公司哪家好
  • 企业自己建网站怎么建阿里指数查询手机版
  • jsp做购物网站技术可行性江门搜狗网站推广优化
  • 欧美手表网站企业网站优化
  • 金融行业网站建设网络推广营销公司
  • 做的网站 只显示代码刚刚发生 北京严重发生
  • app软件开发网站广告推广怎么做最有效
  • 十堰哪里有做网站的少儿培训
  • 中国建设银行支付网站房产网站建设
  • 潍坊网站建设公司有哪些内容免费的html网站