vb 读取word文档中的数据和图片
http://bbs.****.net/topics/390528303?page=1 我遇到了和该帖同样的问题:
需要将一个doc文档中 按特定字符分割后提取出内容
内容不只有字符还有图 比如:
/xxxxxxxxxxx[图片1]xxxx/
/xxxxxxxxxxxxxxxx[图片2]xxxxxxxxxxxxxxxx/xxxxxxx[图片3]/
请大家给点建议 尽量详细
建议通过ole连接word,然后你直接用VBA函数来实现,查找指定的分隔符,然后选择分隔符前的内容,剪切到你想要的地方,然后再查找,再剪切.......
字符串的分割操作,用stringlist和StringReplace
StringReplace(str, "JPG", "\r\n", TReplaceFlags() << rfReplaceAll);
TStringList *lst = new TStringList;
lst->Text = str;
lst每个单元都是你需要的图片以及图片说明,再进行分割
呃 我还是个初学者 因为 关于C++操作word 的资料太少 而关于vb操作word的资料似乎更多
所以后来我用了vb
尝试将指定内容复制粘贴到另一个文档. 但是图片没有被复制过来 求助
Private Sub Command1_Click()
Dim wordApp As New Word.Application
Dim wd1 As New Word.Document
Dim wd2 As New Word.Document
Set wordApp = CreateObject("Word.Application")
wordApp.Visible = True
Set wd1 = wordApp.Documents.Open("C:\Users\WIN7\Desktop\工程\打开word\1.doc")
Set wd2 = wordApp.Documents.Open("C:\Users\WIN7\Desktop\工程\打开word\2.doc")
Dim a As Range
Dim b As Range
Dim s1 As Long
Dim e1 As Long
Set a = wd1.Range(1, 1000)
wd1.Select
With Selection.Find
.ClearFormatting
.Text = "1"
.Execute Forward:=True
End With
s1 = Selection.Start
wd1.Select
With Selection.Find
.ClearFormatting
.Text = "2"
.Execute Forward:=True
End With
e1 = Selection.Start
Set b = wd1.Range(s1, e1)
wd2.Activate
wd2.Range(0, 1000) = b
End Sub