vb操作word的一个问题!VB2005
答案:1 悬赏:70 手机版
解决时间 2021-03-27 19:10
- 提问者网友:
- 2021-03-27 14:01
vb操作word的一个问题!VB2005
最佳答案
- 五星知识达人网友:洎扰庸人
- 2021-03-27 15:14
花了点时间帮你写了下,你自己测试一下.
Using f As New OpenFileDialog
f.Filter = "*.jpg|*.jpg"
If f.ShowDialog <> Windows.Forms.DialogResult.OK Then Return
Using fs As New IO.FileStream(f.FileName, IO.FileMode.Open, IO.FileAccess.Read)
Dim img = Image.FromStream(fs)
If img.Size.Height <> 768 OrElse img.Size.Width = 1024 Then
Using bmp As New Bitmap(1024 * 768)
Using g = Graphics.FromImage(bmp)
g.DrawImage(img, New Rectangle(0, 0, 1024, 768))
img = bmp
End Using
Clipboard.Clear()
Clipboard.SetImage(img)
End Using
End If
End Using
End Using
Dim path As String = "c:\abcd.doc"
Dim wd As New Microsoft.Office.Interop.Word.Application
Dim doc As Microsoft.Office.Interop.Word.Document = wd.Documents.Open(FileName:=path)
doc.Activate()
wd.Selection.EndKey(Unit:=Microsoft.Office.Interop.Word.WdUnits.wdStory)
wd.Selection.TypeParagraph()
wd.Selection.Paste()
doc.Save()
doc.Close()
wd.Quit()
Using f As New OpenFileDialog
f.Filter = "*.jpg|*.jpg"
If f.ShowDialog <> Windows.Forms.DialogResult.OK Then Return
Using fs As New IO.FileStream(f.FileName, IO.FileMode.Open, IO.FileAccess.Read)
Dim img = Image.FromStream(fs)
If img.Size.Height <> 768 OrElse img.Size.Width = 1024 Then
Using bmp As New Bitmap(1024 * 768)
Using g = Graphics.FromImage(bmp)
g.DrawImage(img, New Rectangle(0, 0, 1024, 768))
img = bmp
End Using
Clipboard.Clear()
Clipboard.SetImage(img)
End Using
End If
End Using
End Using
Dim path As String = "c:\abcd.doc"
Dim wd As New Microsoft.Office.Interop.Word.Application
Dim doc As Microsoft.Office.Interop.Word.Document = wd.Documents.Open(FileName:=path)
doc.Activate()
wd.Selection.EndKey(Unit:=Microsoft.Office.Interop.Word.WdUnits.wdStory)
wd.Selection.TypeParagraph()
wd.Selection.Paste()
doc.Save()
doc.Close()
wd.Quit()
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯