是否有任何方法使用C#或VBA將jpeg圖像插入到Visio中? 插入後有一種方法來格式化它的屬性,如寬度,高度,放置在圖紙上的位置?在C#或VBA中以編程方式將Jpeg圖像插入到Visio中
0
A
回答
2
將圖像導入到Visio中時,它們會被包裝成標準形狀(具有visTypeForeignObject的Type屬性)。
從那裏你只是在與ShapeSheet中的單元格交談。 (有關ShapeSheet http://visualsignals.typepad.co.uk/vislog/2007/10/just-for-starte.html的更多詳細信息,請參閱此帖子)
因此,您可以從Visio上的宏記錄器開始使用這類事物。圖片拖動到頁面上,會產生輸出是這樣的:
Sub Macro1()
'Enable diagram services
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150
Dim UndoScopeID2 As Long
UndoScopeID2 = Application.BeginUndoScope("Auto Size Page")
Application.ActiveWindow.Page.AutoSize = False
Application.EndUndoScope UndoScopeID2, True
Dim UndoScopeID3 As Long
UndoScopeID3 = Application.BeginUndoScope("Insert")
Application.ActiveWindow.Page.Import "C:\SomeImage.jpg"
Application.EndUndoScope UndoScopeID3, True
ActiveWindow.DeselectAll
ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(1), visSelect
Application.ActiveWindow.Selection.Move 2.129396, -0.904364
Dim UndoScopeID4 As Long
UndoScopeID4 = Application.BeginUndoScope("Size Object")
Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionObject, visRowXFormOut, visXFormPinX).FormulaU = "46.261665987369 mm"
Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionObject, visRowXFormOut, visXFormPinY).FormulaU = "212.02916285428 mm"
Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionObject, visRowXFormOut, visXFormWidth).FormulaU = "103.47666530807 mm"
Application.EndUndoScope UndoScopeID4, True
Dim UndoScopeID5 As Long
UndoScopeID5 = Application.BeginUndoScope("Size Object")
Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionObject, visRowXFormOut, visXFormPinX).FormulaU = "46.261665987369 mm"
Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionObject, visRowXFormOut, visXFormPinY).FormulaU = "185.77916321819 mm"
Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionObject, visRowXFormOut, visXFormHeight).FormulaU = "73.441667394486 mm"
Application.EndUndoScope UndoScopeID5, True
'Restore diagram services
ActiveDocument.DiagramServicesEnabled = DiagramServices
End Sub
宏錄製在當前選擇上操作,但你並不需要。此外,它使用SRC(節,行,列)語法,而不是更簡單的單元名稱語法。所以的翻譯上面可能是這樣的:
Sub TestAddImage()
Call DropImage(ActivePage, "C:\SomeImage.jpg")
End Sub
Private Sub DropImage(ByRef vPag As Visio.Page, imageFile As String)
If Not vPag Is Nothing Then
Dim newShp As Visio.Shape
Set shpNew = vPag.Import(imageFile)
'Set position
shpNew.CellsU("PinX").FormulaU = "75mm"
shpNew.CellsU("PinY").FormulaU = "175mm"
'Set size
shpNew.CellsU("Width").FormulaU = "100mm"
shpNew.CellsU("Height").FormulaU = "80mm"
End If
End Sub
C#的這個版本是這樣的:
void Main()
{
var vApp = MyExtensions.GetRunningVisio();
DropImage(vApp.ActivePage, @"C:\SomeImage.jpg");
}
private void DropImage(Visio.Page vPag, string imageFile)
{
if (vPag != null)
{
var shpNew = vPag.Import(imageFile);
//Set position
shpNew.CellsU["PinX"].FormulaU = "75mm";
shpNew.CellsU["PinY"].FormulaU = "175mm";
//Set size
shpNew.CellsU["Width"].FormulaU = "100mm";
shpNew.CellsU["Height"].FormulaU = "80mm";
}
}
注意GetRunningVisio
是我與LinqPad使用擴展方法:
http://visualsignals.typepad.co.uk/vislog/2015/12/getting-started-with-c-in-linqpad-with-visio.html
......但這取決於你如何得到應用程序對象。
相關問題
- 1. 以編程方式將多個jpeg圖像嵌入到EXCEL中?
- 2. 以編程方式將幾個圖像插入到UITableviewcell中?
- 3. 通過VBA將圖像導入到Visio
- 4. 將圖像作爲Visio中的形狀插入 - VBA
- 5. 如何以編程方式將圖像插入到Gmail郵件中
- 6. 如何以編程方式將圖像插入Word文檔?
- 7. 在vba中插入圖像
- 8. 如何以編程方式將行插入到DataGridView中?
- 9. 以編程方式將行插入表
- 10. 如何以編程方式在圖像視圖中插入進度條
- 11. 以編程方式將autocad文件轉換爲Visio圖
- 12. 以編程方式將插入圖像添加到TFS工作項目
- 13. C#以編程方式形成圖像
- 14. 在C++中以塊分割jpeg圖像
- 15. 在VBA中使用Base64將圖像插入到工作表中?
- 16. 我可以以編程方式將matplotlib圖形插入Excel嗎?
- 17. 以編程方式將輸入插入到drupal表單
- 18. 如何以編程方式將.xlam插件(作爲對象)添加到vba中?
- 19. 以編程方式在Linux服務器上創建Visio繪圖
- 20. 以編程方式在Telerik RadGrid圖像列中隱藏圖像
- 21. 如何以編程方式在Word 2007文檔中使用vs 2010,c#插入或編輯餅圖?
- 22. 在C++中將數組編碼爲jpeg圖像
- 23. 在C#中以編程方式將formview綁定到數據表#
- 24. 如何使用java PDFBox以編程方式將圖像插入AcroForm字段?
- 25. VBA - Power Point - 以編程方式將文本包裹在Shape中
- 26. 如何以編程方式將文本插入到SWF文件
- 27. 如何以編程方式將數據從iphone插入到mysql
- 28. 您將如何以編程方式將PDF嵌入到SWF中?
- 29. 如何以編程方式更改Visio中的遊標?
- 30. 在Drupal 7中以編程方式將圖像文件附加到節點上
約翰,那太棒了,它工作完美。但有什麼內置的將形狀放置在頁面的末尾,如shpNew.cellsu.end?或者是否需要運行一個宏來查找您在「sub Macro1」中顯示的座標? – Puneeth
爲此,您需要向PinX/Y單元添加公式而不是常量值。對於PinX:'「ThePage!PageWidth-(Width-LocPinX)」'和PinY'「ThePage!PageHeight-(Height-LocPinY)」'。這將設置頁面左上角的形狀。 – JohnGoldsmith
對不起,我的問題是放在頁面的底部,我相信用+修改公式會在頁面底部設置形狀,不是嗎? – Puneeth