找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 1887|回复: 3

写入word文档表格并存储

[复制链接]
发表于 2020-7-9 16:45:54 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
本帖最后由 china_shy_wzb 于 2020-7-9 16:48 编辑

Option Explicit

Private Function OutWord(ByVal filePath As String) As Boolean
Dim newDoc As Word.Document
Set newDoc = New Word.Document

With newDoc
.Paragraphs(.Paragraphs.Count).Range.Font.Name = "宋体"
.Paragraphs(.Paragraphs.Count).Range.Font.Size = 10.5
.Paragraphs(.Paragraphs.Count).Alignment = wdAlignParagraphRight
.Content.InsertAfter "编号:" & vbCrLf

.Paragraphs(.Paragraphs.Count).Range.Font.Name = "宋体"
.Paragraphs(.Paragraphs.Count).Range.Font.Size = 26
.Paragraphs(.Paragraphs.Count).Range.Font.Bold = True
.Paragraphs(.Paragraphs.Count).Alignment = wdAlignParagraphCenter
.Content.InsertAfter vbCrLf & "XXXXXXXXX报告" & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf

.Paragraphs(.Paragraphs.Count).Range.Font.Name = "宋体"
.Paragraphs(.Paragraphs.Count).Range.Font.Size = 15
.Paragraphs(.Paragraphs.Count).Range.Font.Bold = False
.Paragraphs(.Paragraphs.Count).Alignment = wdAlignParagraphLeft
.Content.InsertAfter "项目名称:" & vbCrLf
.Content.InsertAfter "应急类型:" & vbCrLf
.Content.InsertAfter "预警状态:正常/警界/危机" & vbCrLf

.Paragraphs(.Paragraphs.Count).Alignment = wdAlignParagraphCenter
.Tables.Add Range:=.Range(Start:=.Range.End - 1, End:=.Range.End), NumRows:=1, NumColumns:=3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
'With .Tables(0)
'If .Style <> "表 (格子)" Then
'.Style = "表 (格子)"
'End If
'.ApplyStyleHeadingRows = True
'.ApplyStyleLastRow = True
'.ApplyStyleFirstColumn = True
'.ApplyStyleLastColumn = True
'.Columns.Width = 50
'.Rows.Height = 20
'End With

.Paragraphs(.Paragraphs.Count).Range.Font.Name = "宋体"
.Paragraphs(.Paragraphs.Count).Range.Font.Size = 15
.Paragraphs(.Paragraphs.Count).Range.Font.Bold = False
.Paragraphs(.Paragraphs.Count).Alignment = wdAlignParagraphLeft
.Content.InsertAfter "委 托 人:" & vbCrLf
.Content.InsertAfter "预 警 机 构:" & vbCrLf
.Content.InsertAfter "报告负责人:" & vbCrLf
.Content.InsertAfter "时 间:" & vbCrLf

游客,如果您要查看本帖隐藏内容请回复

End With

newDoc.SaveAs filePath
newDoc.Close
End Function
回复

使用道具 举报

发表于 2020-7-12 15:02:45 | 显示全部楼层
看看
回复

使用道具 举报

发表于 2020-9-1 15:43:38 | 显示全部楼层
学习一下
回复

使用道具 举报

发表于 2022-11-23 23:39:59 | 显示全部楼层
学习一下vba
回复 赞! 靠!

使用道具 举报

本版积分规则

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-11-23 16:21 , Processed in 0.036666 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表